Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manageiq env plugins should update everything on bin/update #15508

Merged
merged 2 commits into from
Jul 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 12 additions & 10 deletions lib/manageiq/environment.rb
Original file line number Diff line number Diff line change
@@ -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

@@ -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,11 +55,11 @@ 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
system!('bundle update')
def self.bundle_update(root = APP_ROOT)
system!('bundle update', :chdir => root)
end

def self.create_database
@@ -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
9 changes: 6 additions & 3 deletions lib/tasks/test_vmdb.rake
Original file line number Diff line number Diff line change
@@ -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