From 93bcfaaa0708ad40b8d1357cecc9c708674b3642 Mon Sep 17 00:00:00 2001 From: Marcel Hild Date: Wed, 5 Jul 2017 15:51:24 +0200 Subject: [PATCH 1/2] rake task test:vmdb:setup checks wether it is run namespaced if so, the dependencies are also run namespaced this is used from a plugins 'spec:setup' task and thus moves the dependencies properly to the core --- .../templates/lib/tasks_private/spec.rake | 2 +- lib/manageiq/environment.rb | 16 +++++++++------- lib/tasks/test_vmdb.rake | 9 ++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/generators/provider/templates/lib/tasks_private/spec.rake b/lib/generators/provider/templates/lib/tasks_private/spec.rake index a300b6bf8fd..da5c5d38277 100644 --- a/lib/generators/provider/templates/lib/tasks_private/spec.rake +++ b/lib/generators/provider/templates/lib/tasks_private/spec.rake @@ -1,6 +1,6 @@ namespace :spec do desc "Setup environment specs" - task :setup => ["app:test:initialize", "app:test:verify_no_db_access_loading_rails_environment", "app:test:setup_db"] + task :setup => ["app:test:vmdb:setup"] end desc "Run all specs" diff --git a/lib/manageiq/environment.rb b/lib/manageiq/environment.rb index cc80f42ce7d..bcf08010ce8 100644 --- a/lib/manageiq/environment.rb +++ b/lib/manageiq/environment.rb @@ -19,7 +19,7 @@ def self.manageiq_plugin_setup create_database_user end - setup_test_environment + setup_test_environment(:task_prefix => 'app:', :root => plugin_root) end def self.ensure_config_files @@ -55,7 +55,7 @@ def self.install_bundler end def self.bundle_install(root = APP_ROOT) - system('bundle check', :chdir => root) || system('bundle install', :chdir => root) + system('bundle check', :chdir => root) || system!('bundle install', :chdir => root) end def self.bundle_update @@ -77,9 +77,9 @@ def self.seed_database run_rake_task("db:seed") end - def self.setup_test_environment + def self.setup_test_environment(task_prefix: '', root: APP_ROOT) puts "\n== Resetting tests ==" - run_rake_task("test:vmdb:setup") + run_rake_task("#{task_prefix}test:vmdb:setup", :root => root) end def self.reset_automate_domain @@ -122,12 +122,14 @@ def self.bundler_version File.read(gemfile).match(/gem\s+['"]bundler['"],\s+['"](.+?)['"]/)[1] end - def self.run_rake_task(task) - system!("#{APP_ROOT.join("bin/rails")} #{task}") + def self.run_rake_task(task, root: APP_ROOT) + system!("bin/rails #{task}", :chdir => root) end def self.system!(*args) - system(*args, :chdir => APP_ROOT) || abort("\n== Command #{args} failed ==") + options = args.last.kind_of?(Hash) ? args.pop : {} + options[:chdir] ||= APP_ROOT + system(*args, options) || abort("\n== Command #{args} failed in #{options[:chdir]} ==") end end end diff --git a/lib/tasks/test_vmdb.rake b/lib/tasks/test_vmdb.rake index cc33da8a7e7..bc3bec0caa0 100644 --- a/lib/tasks/test_vmdb.rake +++ b/lib/tasks/test_vmdb.rake @@ -4,19 +4,22 @@ if defined?(RSpec) && defined?(RSpec::Core::RakeTask) namespace :test do namespace :vmdb do desc "Setup environment for vmdb specs" - task :setup => [:initialize, :verify_no_db_access_loading_rails_environment] do + task :setup => [:initialize, :verify_no_db_access_loading_rails_environment] do |rake_task| + # in case we are called from an engine or plugin, the task might be namespaced under 'app:' + # i.e. it's 'app:test:vmdb:setup'. Then we have to call the tasks in here under the 'app:' namespace too + app_prefix = rake_task.name.chomp('test:vmdb:setup') if ENV['PARALLEL'] database_config = Pathname.new(__dir__).expand_path + "../../config/database.yml" if File.readlines(database_config).grep(/TEST_ENV_NUMBER/).size > 0 require 'parallel_tests' - ParallelTests::CLI.new.run(["--type", "rspec"] + ["-e", "bin/rake evm:db:reset"]) + ParallelTests::CLI.new.run(["--type", "rspec"] + ["-e", "bin/rails #{app_prefix}evm:db:reset"]) else puts "Oops! Your database.yml doesn't appear to support parallel tests!" puts "Update your config/database.yml with TEST_ENV_NUMBER as seen in the example (database.pg.yml), then try again." exit(1) end else - Rake::Task['test:setup_db'].invoke + Rake::Task["#{app_prefix}test:setup_db"].invoke end end end From cf2bab38d71504306c8b923c5bb19ca3d85b05ce Mon Sep 17 00:00:00 2001 From: Marcel Hild Date: Thu, 6 Jul 2017 12:06:51 +0200 Subject: [PATCH 2/2] run bundle update on manageiq_plugin_setup --- lib/manageiq/environment.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/manageiq/environment.rb b/lib/manageiq/environment.rb index bcf08010ce8..b22b32ab632 100644 --- a/lib/manageiq/environment.rb +++ b/lib/manageiq/environment.rb @@ -10,7 +10,7 @@ def self.manageiq_plugin_setup plugin_root = Pathname.new(caller_locations.last.absolute_path).dirname.parent install_bundler - bundle_install(plugin_root) + bundle_update(plugin_root) ensure_config_files @@ -58,8 +58,8 @@ def self.bundle_install(root = APP_ROOT) system('bundle check', :chdir => root) || system!('bundle install', :chdir => root) end - def self.bundle_update - system!('bundle update') + def self.bundle_update(root = APP_ROOT) + system!('bundle update', :chdir => root) end def self.create_database