diff --git a/package-testing/Gemfile b/package-testing/Gemfile index 4109fe77e..18e7ddc17 100644 --- a/package-testing/Gemfile +++ b/package-testing/Gemfile @@ -2,7 +2,8 @@ source ENV.fetch('GEM_SOURCE', nil) || 'https://rubygems.org' gem 'beaker', '~> 4.39' gem 'beaker-abs', '~> 0.11.0' -gem 'beaker-hostgenerator', '~> 2.2.0' +gem 'beaker-docker', '~> 2' +gem 'beaker-hostgenerator', '~> 2.11.0' gem 'beaker-puppet', '= 1.29.0' gem 'beaker-rspec', '= 7.1.0' gem 'beaker-vmpooler', '= 1.4.0' diff --git a/package-testing/Rakefile b/package-testing/Rakefile index 530f2a4fb..93f6b9f11 100644 --- a/package-testing/Rakefile +++ b/package-testing/Rakefile @@ -63,7 +63,7 @@ namespace :acceptance do puts "Generating beaker hosts using TEST_TARGET value #{test_target}" - cli = BeakerHostGenerator::CLI.new(["#{test_target}{type=foss}", '--disable-default-role', '--hypervisor', 'abs']) + cli = BeakerHostGenerator::CLI.new(["#{test_target}{type=foss}", '--disable-default-role', '--hypervisor', ENV.fetch('BEAKER_HYPERVISOR', 'abs')]) File.open('acceptance_hosts.yml', 'w') do |hosts_file| hosts_file.print(cli.execute) diff --git a/package-testing/spec/package/support/serverspec_monkeypatch.rb b/package-testing/spec/package/support/serverspec_monkeypatch.rb index 39b594916..405d83f8e 100644 --- a/package-testing/spec/package/support/serverspec_monkeypatch.rb +++ b/package-testing/spec/package/support/serverspec_monkeypatch.rb @@ -49,6 +49,11 @@ class BeakerExec old_build_command = instance_method(:build_command) define_method(:build_command) do |cmd| + if get_config(:cwd) + cmd = cmd.shelljoin if cmd.is_a? Array + cmd = "cd #{get_config(:cwd)} && #{cmd}" + end + prepend_env(old_build_command.bind_call(self, cmd)) end @@ -57,36 +62,27 @@ def unescape(string) end def prepend_env(cmd) - _, env, shell, command = cmd.match(/\Aenv (.+?)? (\S+) -c (.+)\Z/).to_a - - output = if get_config(:run_as) - ["sudo -u #{get_config(:run_as)}"] - else - ['env'] - end + _, orig_env, orig_cmd = cmd.match(/\A(?:env (.+) )?(\S+(?: -i)?(?: -l)? -c .+)\Z/).to_a + env = [orig_env].compact (get_config(:env) || {}).each do |k, v| - output << %(#{k}="#{v}") + env << %(#{k}="#{v}") end - output << env - new_cmd = if get_config(:cwd) - "'cd #{get_config(:cwd).shellescape} && #{unescape(command)}'" - else - "'#{unescape(command)}'" - end - output << '-i --' if get_config(:run_as) - # sudo on osx 10.11 behaves strangely when processing arguments and does - # not preserve quoted arguments, so we have to quote twice for this corner - # case. - output << if Specinfra.get_working_node.platform.start_with?('osx-10.11-') && get_config(:run_as) - "#{shell} -c \"#{new_cmd}\"" + command = if env.empty? + orig_cmd else - "#{shell} -c #{new_cmd}" + "env #{env.join(' ')} #{orig_cmd}" end - $stderr.puts(output.join(' ')) if ENV.key?('BEAKER_debug') - output.join(' ') + output = if get_config(:run_as) + "su -l #{get_config(:run_as)} -c #{command.shellescape}" + else + command + end + + $stderr.puts(output) if ENV.key?('BEAKER_debug') + output end end end diff --git a/package-testing/spec/package/unprivileged_user_spec.rb b/package-testing/spec/package/unprivileged_user_spec.rb index fbc5ed0b8..d036d2ef4 100644 --- a/package-testing/spec/package/unprivileged_user_spec.rb +++ b/package-testing/spec/package/unprivileged_user_spec.rb @@ -18,8 +18,6 @@ on(host, "mkdir #{homedir} && chown #{uid}:#{gid} #{homedir}") unless directory_exists_on(host, homedir) end end - - on(host, 'sed -i -e \'s/\srequiretty/!requiretty/g\' /etc/sudoers') if file_exists_on(host, '/etc/sudoers') end end diff --git a/spec/acceptance/remove_config_spec.rb b/spec/acceptance/remove_config_spec.rb index b98a7a5af..98ecd4457 100644 --- a/spec/acceptance/remove_config_spec.rb +++ b/spec/acceptance/remove_config_spec.rb @@ -31,24 +31,6 @@ end end - RSpec.shared_context 'with a fake answer file' do |initial_content = nil| - before(:all) do - fake_answer_file = Tempfile.new('mock_answers.json') - unless initial_content.nil? - require 'json' - fake_answer_file.binmode - fake_answer_file.write(JSON.pretty_generate(initial_content)) - end - fake_answer_file.close - ENV['PDK_ANSWER_FILE'] = fake_answer_file.path - end - - after(:all) do - FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here - ENV.delete('PDK_ANSWER_FILE') - end - end - context 'when run outside of a module' do describe command('pdk remove config') do its(:exit_status) { is_expected.not_to eq 0 } diff --git a/spec/acceptance/set_config_spec.rb b/spec/acceptance/set_config_spec.rb index 5b452c142..614387fdb 100644 --- a/spec/acceptance/set_config_spec.rb +++ b/spec/acceptance/set_config_spec.rb @@ -27,24 +27,6 @@ end end - RSpec.shared_context 'with a fake answer file' do |initial_content = nil| - before(:all) do - fake_answer_file = Tempfile.new('mock_answers.json') - unless initial_content.nil? - require 'json' - fake_answer_file.binmode - fake_answer_file.write(JSON.pretty_generate(initial_content)) - end - fake_answer_file.close - ENV['PDK_ANSWER_FILE'] = fake_answer_file.path - end - - after(:all) do - FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here - ENV.delete('PDK_ANSWER_FILE') - end - end - context 'when run outside of a module' do describe command('pdk set config') do its(:exit_status) { is_expected.not_to eq 0 } diff --git a/spec/acceptance/support/with_a_fake_answer_file.rb b/spec/acceptance/support/with_a_fake_answer_file.rb new file mode 100644 index 000000000..478c96a8b --- /dev/null +++ b/spec/acceptance/support/with_a_fake_answer_file.rb @@ -0,0 +1,17 @@ +RSpec.shared_context 'with a fake answer file' do |initial_content = nil| + before(:all) do + fake_answer_file = Tempfile.new('mock_answers.json') + unless initial_content.nil? + require 'json' + fake_answer_file.binmode + fake_answer_file.write(JSON.pretty_generate(initial_content)) + end + fake_answer_file.close + ENV['PDK_ANSWER_FILE'] = fake_answer_file.path + end + + after(:all) do + FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here + ENV.delete('PDK_ANSWER_FILE') + end +end diff --git a/spec/acceptance/test_unit_spec.rb b/spec/acceptance/test_unit_spec.rb index 24735a6a7..5312ec922 100644 --- a/spec/acceptance/test_unit_spec.rb +++ b/spec/acceptance/test_unit_spec.rb @@ -5,7 +5,7 @@ include_context 'with a fake TTY' shared_context 'with spec file' do |filename, content| - around(:all) do |example| + around do |example| path = File.join('spec', 'unit', filename) FileUtils.mkdir_p(File.dirname(path)) File.open(path, 'w') { |f| f.puts content }