Skip to content

Commit

Permalink
Merge 709c227 into e2c2269
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Mar 24, 2023
2 parents e2c2269 + 709c227 commit b1522e5
Show file tree
Hide file tree
Showing 80 changed files with 509 additions and 789 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ gemspec

if ENV['BEAKER_PE_PR_REPO_URL']
lib = ENV['BEAKER_PE_PR_REPO_URL'].match(/\/([^\/]+)\.git$/)[1]
author = ENV['BEAKER_PE_PR_AUTHOR']
ref = ENV['BEAKER_PE_PR_COMMIT']
author = ENV.fetch('BEAKER_PE_PR_AUTHOR', nil)
ref = ENV.fetch('BEAKER_PE_PR_COMMIT', nil)
gem lib, :git => "git@github.com:#{author}/#{lib}.git", :branch => ref
end

Expand Down
40 changes: 12 additions & 28 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,16 @@ module HarnessOptions
end

def hosts_file_env
ENV['BEAKER_HOSTS']
ENV.fetch('BEAKER_HOSTS', nil)
end

def hosts_opt(use_preserved_hosts = false)
if use_preserved_hosts
"--hosts=#{HOSTS_PRESERVED}"
elsif hosts_file_env
"--hosts=#{hosts_file_env}"
else
if hosts_file_env
"--hosts=#{hosts_file_env}"
else
"--hosts=tmp/#{HOSTS_FILE}"
end
"--hosts=tmp/#{HOSTS_FILE}"
end
end

Expand Down Expand Up @@ -110,7 +108,7 @@ def beaker_test(mode = :base, options = {})
end
end

tests = ENV['TESTS'] || ENV['TEST']
tests = ENV['TESTS'] || ENV.fetch('TEST', nil)
tests_opt = ""
tests_opt = "--tests=#{tests}" if tests

Expand Down Expand Up @@ -142,17 +140,13 @@ namespace :test do
puts line
end
output = stdout.to_s
if not wait_thr.value.success?
fail "Failed to 'bundle exec rspec' (exit status: #{wait_thr.value})"
end
fail "Failed to 'bundle exec rspec' (exit status: #{wait_thr.value})" if not wait_thr.value.success?

exit_status = wait_thr.value
end
if exit_status != /0/
# check for deprecation warnings
if output.include?('Deprecation Warnings')
fail "DEPRECATION WARNINGS in spec generation, please fix!"
end
fail "DEPRECATION WARNINGS in spec generation, please fix!" if output.include?('Deprecation Warnings')
end
end
end
Expand Down Expand Up @@ -183,9 +177,7 @@ namespace :test do

desc 'Generate Beaker Host Config File'
task :gen_hosts do
if hosts_file_env
next
end
next if hosts_file_env

arguments = [test_targets]
arguments += ['--hypervisor', ENV['BEAKER_HYPERVISOR']] if ENV['BEAKER_HYPERVISOR']
Expand All @@ -208,9 +200,7 @@ namespace :history do
Dir.chdir(__dir__) do
output = `bundle exec ruby history.rb .`
puts output
if !output.include?('success')
raise "History generation failed"
end
raise "History generation failed" if !output.include?('success')
end
end
end
Expand All @@ -227,9 +217,7 @@ FOREGROUND_SERVER = "bundle exec yard server --reload --verbose lib/beaker --doc
def running?(cmdline)
ps = `ps -ef`
found = ps.lines.grep(/#{Regexp.quote(cmdline)}/)
if found.length > 1
raise StandardError, "Found multiple YARD Servers. Don't know what to do."
end
raise StandardError, "Found multiple YARD Servers. Don't know what to do." if found.length > 1

yes = found.empty? ? false : true
return yes, found.first
Expand Down Expand Up @@ -259,9 +247,7 @@ namespace :docs do
Dir.chdir(__dir__) do
output = `bundle exec yard doc -o #{DOCS_DIR}`
puts output
if /\[warn\]|\[error\]/.match?(output)
fail "Errors/Warnings during yard documentation generation"
end
fail "Errors/Warnings during yard documentation generation" if /\[warn\]|\[error\]/.match?(output)
end
end

Expand Down Expand Up @@ -342,8 +328,6 @@ else
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']

# Use Rubocop's Github Actions formatter if possible
if ENV['GITHUB_ACTIONS'] == 'true'
task.formatters << 'github'
end
task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
end
end
2 changes: 1 addition & 1 deletion acceptance/config/acceptance-options.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
:load_path => File.join('acceptance', 'lib'),
:ssh => {
:keys => ["id_rsa_acceptance", "#{ENV['HOME']}/.ssh/id_rsa-acceptance"],
:keys => ["id_rsa_acceptance", "#{ENV.fetch('HOME', nil)}/.ssh/id_rsa-acceptance"],
},
}
4 changes: 1 addition & 3 deletions acceptance/fixtures/module/spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
end

hosts.each do |host|
unless host.is_pe?
on host, "/bin/echo '' > #{host.puppet('hiera_config')}"
end
on host, "/bin/echo '' > #{host.puppet('hiera_config')}" unless host.is_pe?
on host, "mkdir -p #{host['distmoduledir']}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion acceptance/pre_suite/subcommands/05_install_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ruby_version, ruby_source = ENV['RUBY_VER'], "job parameter"
ruby_version, ruby_source = ENV.fetch('RUBY_VER', nil), "job parameter"
unless ruby_version
ruby_version = "2.4.1"
ruby_source = "default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
test_name "dsl::helpers::host_helpers #backup_the_file" do
step "#backup_the_file CURRENTLY will return nil if the file does not exist in the source directory" do
# NOTE: would expect this to fail with Beaker::Host::CommandFailure
remote_source = default.tmpdir()
remote_destination = default.tmpdir()
remote_source = default.tmpdir
remote_destination = default.tmpdir
result = backup_the_file default, remote_source, remote_destination
assert_nil result
end

step "#backup_the_file will fail if the destination directory does not exist" do
remote_source = default.tmpdir()
remote_source = default.tmpdir
create_remote_file_from_fixture("simple_text_file", default, remote_source, "puppet.conf")

assert_raises Beaker::Host::CommandFailure do
Expand All @@ -19,10 +19,10 @@
end

step "#backup_the_file copies `puppet.conf` from the source to the destination directory" do
remote_source = default.tmpdir()
remote_source = default.tmpdir
_remote_filename, contents = create_remote_file_from_fixture("simple_text_file", default, remote_source, "puppet.conf")

remote_destination = default.tmpdir()
remote_destination = default.tmpdir
remote_destination_filename = File.join(remote_destination, "puppet.conf.bak")

result = backup_the_file default, remote_source, remote_destination
Expand All @@ -33,10 +33,10 @@
end

step "#backup_the_file copies a named file from the source to the destination directory" do
remote_source = default.tmpdir()
remote_source = default.tmpdir
_remote_filename, contents = create_remote_file_from_fixture("simple_text_file", default, remote_source, "testfile.txt")

remote_destination = default.tmpdir()
remote_destination = default.tmpdir
remote_destination_filename = File.join(remote_destination, "testfile.txt.bak")

result = backup_the_file default, remote_source, remote_destination, "testfile.txt"
Expand All @@ -47,9 +47,9 @@
end

step "#backup_the_file CURRENTLY will fail if given a hosts array" do
remote_source = default.tmpdir()
remote_source = default.tmpdir
create_remote_file_from_fixture("simple_text_file", default, remote_source, "testfile.txt")
remote_destination = default.tmpdir()
remote_destination = default.tmpdir

assert_raises NoMethodError do
backup_the_file hosts, remote_source, remote_destination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def create_remote_file_with_backups host, remote_filename, contents, opts = {}
result = create_remote_file(
host, remote_filename, contents, opts
) # return of block is whether or not we're done repeating
if result.is_a?(Rsync::Result) || result.is_a?(Beaker::Result)
return result.success?
end
return result.success? if result.is_a?(Rsync::Result) || result.is_a?(Beaker::Result)

result.all? { |individual_result| individual_result.success? }
rescue Beaker::Host::CommandFailure => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def host_local_url(host, path)
end

step "#curl_on can retrieve the contents of a URL, using standard curl options" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_filename, contents = create_remote_file_from_fixture("simple_text_file", default, remote_tmpdir, "testfile.txt")
remote_targetfilename = File.join remote_tmpdir, "outfile.txt"

Expand All @@ -29,7 +29,7 @@ def host_local_url(host, path)
end

step "#curl_on can retrieve the contents of a URL, when given a hosts array" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
on hosts, "mkdir -p #{remote_tmpdir}"

remote_filename = contents = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
step "#retry_on CURRENTLY fails with a RuntimeError if command does not pass after all retries" do
# NOTE: would have expected this to fail with Beaker::Hosts::CommandFailure

remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_script_file = File.join(remote_tmpdir, "test.sh")
create_remote_file_from_fixture("retry_script", default, remote_tmpdir, "test.sh")

Expand All @@ -14,7 +14,7 @@
end

step "#retry_on succeeds if command passes before retries are exhausted" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_script_file = File.join(remote_tmpdir, "test.sh")
create_remote_file_from_fixture("retry_script", default, remote_tmpdir, "test.sh")

Expand All @@ -27,7 +27,7 @@
# NOTE: would expect this to work across hosts, or be better documented and
# to raise Beaker::Host::CommandFailure

remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_script_file = File.join(remote_tmpdir, "test.sh")

hosts.each do |host|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def rsync_to_with_backups hosts, local_filename, remote_dir
step "#rsync_to CURRENTLY fails on windows systems" do
Dir.mktmpdir do |local_dir|
local_filename, _contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir

assert_raises Beaker::Host::CommandFailure do
rsync_to default, local_filename, remote_tmpdir
Expand All @@ -54,7 +54,7 @@ def rsync_to_with_backups hosts, local_filename, remote_dir
confine :except, :hypervisor => 'docker'

step "#rsync_to fails if the local file cannot be found" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
assert_raises IOError do
rsync_to default, "/non/existent/file.txt", remote_tmpdir
end
Expand Down Expand Up @@ -116,7 +116,7 @@ def rsync_to_with_backups hosts, local_filename, remote_dir
step "#rsync_to creates the file on the remote system" do
Dir.mktmpdir do |local_dir|
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_filename = File.join(remote_tmpdir, "testfile.txt")

result = rsync_to_with_backups default, local_filename, remote_tmpdir
Expand All @@ -138,7 +138,7 @@ def rsync_to_with_backups hosts, local_filename, remote_dir
step "#rsync_to creates the file on all remote systems when a host array is provided" do
Dir.mktmpdir do |local_dir|
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
on hosts, "mkdir -p #{remote_tmpdir}"
remote_filename = File.join(remote_tmpdir, "testfile.txt")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
test_name "dsl::helpers::host_helpers #scp_from" do
if test_scp_error_on_close?
step "#scp_from fails if the local path cannot be found" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_filename, _contents = create_remote_file_from_fixture("simple_text_file", default, remote_tmpdir, "testfile.txt")

assert_raises Beaker::Host::CommandFailure do
Expand All @@ -22,7 +22,7 @@

step "#scp_from creates the file on the local system" do
Dir.mktmpdir do |local_dir|
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_filename, contents = create_remote_file_from_fixture("simple_text_file", default, remote_tmpdir, "testfile.txt")

scp_from default, remote_filename, local_dir
Expand All @@ -37,7 +37,7 @@
# file repeatedly to generate an error

Dir.mktmpdir do |local_dir|
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
remote_filename = File.join(remote_tmpdir, "testfile.txt")
on hosts, "mkdir -p #{remote_tmpdir}"
on hosts, %{echo "${RANDOM}:${RANDOM}:${RANDOM}" > #{remote_filename}}
Expand Down
6 changes: 3 additions & 3 deletions acceptance/tests/base/dsl/helpers/host_helpers/scp_to_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

test_name "dsl::helpers::host_helpers #scp_to" do
step "#scp_to fails if the local file cannot be found" do
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
assert_raises IOError do
scp_to default, "/non/existent/file.txt", remote_tmpdir
end
Expand All @@ -24,7 +24,7 @@
step "#scp_to creates the file on the remote system" do
Dir.mktmpdir do |local_dir|
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")
remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir

scp_to default, local_filename, remote_tmpdir

Expand All @@ -38,7 +38,7 @@
Dir.mktmpdir do |local_dir|
local_filename, contents = create_local_file_from_fixture("simple_text_file", local_dir, "testfile.txt")

remote_tmpdir = default.tmpdir()
remote_tmpdir = default.tmpdir
on hosts, "mkdir -p #{remote_tmpdir}"
remote_filename = File.join(remote_tmpdir, "testfile.txt")

Expand Down
23 changes: 10 additions & 13 deletions acceptance/tests/base/dsl/platform_tag_confiner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

step "#{pstc_method_name} can remove hosts from a test, or be skipped if empty" do
assert hosts.length() > 0, "#{pstc_method_name} did not have enough hosts to test"
assert hosts.length > 0, "#{pstc_method_name} did not have enough hosts to test"
previous_hosts = hosts.dup

options[:platform_tag_confines] = [
Expand All @@ -26,19 +26,16 @@
begin
tag('tag1')
rescue Beaker::DSL::Outcomes::SkipTest => e
if /^No\ suitable\ hosts\ found/.match?(e.message)
# SkipTest is raised in the case when there are no hosts leftover for a test
# after confining. It's a very common acceptance test case where all of the
# hosts involved are of the same platform, and are thus all confined
# away by the code being run here. In this case, the hosts object will not
# be altered, but should be considered a pass, since the fact that SkipTest
# is being raised confirms that a lower number of hosts are coming out of
# the confine (0) than came in (>0, according to our pre-condition assertion)
else
fail "#{pstc_method_name} raised unexpected SkipTest exception: #{e}"
end
fail "#{pstc_method_name} raised unexpected SkipTest exception: #{e}" unless /^No\ suitable\ hosts\ found/.match?(e.message)
# SkipTest is raised in the case when there are no hosts leftover for a test
# after confining. It's a very common acceptance test case where all of the
# hosts involved are of the same platform, and are thus all confined
# away by the code being run here. In this case, the hosts object will not
# be altered, but should be considered a pass, since the fact that SkipTest
# is being raised confirms that a lower number of hosts are coming out of
# the confine (0) than came in (>0, according to our pre-condition assertion)
else
assert hosts.length() < previous_hosts.length(), "#{pstc_method_name} did not change hosts array"
assert hosts.length < previous_hosts.length, "#{pstc_method_name} did not change hosts array"
end

# cleanup
Expand Down
4 changes: 1 addition & 3 deletions acceptance/tests/install/from_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

step 'install arbitrary dmg via url' do
hosts.each do |host|
if host['platform'].include?('osx')
host.generic_install_dmg('https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.dmg', 'Vagrant', 'Vagrant.pkg')
end
host.generic_install_dmg('https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.dmg', 'Vagrant', 'Vagrant.pkg') if host['platform'].include?('osx')
end
end
2 changes: 0 additions & 2 deletions beaker.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- encoding: utf-8 -*-

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'beaker/version'
Expand Down
Loading

0 comments on commit b1522e5

Please sign in to comment.