Skip to content

Commit

Permalink
Merge pull request #9247 from puppetlabs/backport-9236-to-7.x
Browse files Browse the repository at this point in the history
[Backport 7.x] Update deprecated Beaker methods
  • Loading branch information
mhashizume authored Feb 8, 2024
2 parents 3950b39 + becb5bd commit fb5cc8c
Show file tree
Hide file tree
Showing 91 changed files with 386 additions and 401 deletions.
2 changes: 1 addition & 1 deletion acceptance/tests/agent/last_run_summary_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

step "Check that '#{statedir}' exists and has no 'last_run_summary.yaml' file" do
on(agent, "ls #{statedir}",:acceptable_exit_codes => [0]) do |result|
assert_no_match(/last_run_summary.yaml/, result.stdout)
refute_match(/last_run_summary.yaml/, result.stdout)
end
end

Expand Down
4 changes: 2 additions & 2 deletions acceptance/tests/aix/aix_package_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on hosts, "lslpp -qLc #{package} | cut -f3 -d:" do
actual_version = stdout.chomp
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
Expand Down
10 changes: 5 additions & 5 deletions acceptance/tests/aix/nim_package_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def assert_package_version(package, expected_version)
# The output of lslpp is a colon-delimited list like:
# sudo:sudo.rte:1.8.6.4: : :C: :Configurable super-user privileges runtime: : : : : : :0:0:/:
# We want the version, so grab the third field
on hosts, "lslpp -qLc #{package} | cut -f3 -d:" do
actual_version = stdout.chomp
on(hosts, "lslpp -qLc #{package} | cut -f3 -d:") do |result|
actual_version = result.stdout.chomp
assert_equal(expected_version, actual_version, "Installed package version #{actual_version} does not match expected version #{expected_version}")
end
end
Expand Down Expand Up @@ -109,11 +109,11 @@ def test_apply(package_name, ensure_value, expected_version)
version = details[:old_version]

manifest = get_manifest(package_name, version)
on hosts, puppet_apply("--verbose", "--detailed-exitcodes"),
on(hosts, puppet_apply("--verbose", "--detailed-exitcodes"),
{ :stdin => manifest,
:acceptable_exit_codes => [4,6] } do
:acceptable_exit_codes => [4,6] }) do |result|

assert_match(/NIM package provider is unable to downgrade packages/, stderr, "Didn't get an error about downgrading packages")
assert_match(/NIM package provider is unable to downgrade packages/, result.stderr, "Didn't get an error about downgrading packages")
end
end

Expand Down
8 changes: 4 additions & 4 deletions acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
testdir = master.tmpdir("nodenamefact")
node_names = []

on agents, facter('kernel') do
node_names << stdout.chomp
on agents, facter('kernel') do |result|
node_names << result.stdout.chomp
end

node_names.uniq!
Expand Down Expand Up @@ -147,8 +147,8 @@
}

with_puppet_running_on(master, master_opts, testdir) do
on(agents, puppet('agent', "--no-daemonize --verbose --onetime --node_name_fact kernel")) do
assert_match(/defined 'message'.*#{success_message}/, stdout)
on(agents, puppet('agent', "--no-daemonize --verbose --onetime --node_name_fact kernel")) do |result|
assert_match(/defined 'message'.*#{success_message}/, result.stdout)
end
end
end
4 changes: 2 additions & 2 deletions acceptance/tests/allow_arbitrary_node_name_for_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
},
}
with_puppet_running_on(master, master_opts, testdir) do
on(agents, puppet('agent', "-t --node_name_value specified_node_name"), :acceptable_exit_codes => [0,2]) do
assert_match(/defined 'message'.*#{success_message}/, stdout)
on(agents, puppet('agent', "-t --node_name_value specified_node_name"), :acceptable_exit_codes => [0,2]) do |result|
assert_match(/defined 'message'.*#{success_message}/, result.stdout)
end
end
end
16 changes: 8 additions & 8 deletions acceptance/tests/apply/classes/parameterized_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class x($y, $z) {
class {x: y => '1', z => '2'}
}

apply_manifest_on(agents, manifest) do
fail_test "inclusion after parameterization failed" unless stdout.include? "1-2"
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end

########################################################################
Expand All @@ -28,8 +28,8 @@ class {x: y => '1', z => '2'}
include x
}

apply_manifest_on(agents, manifest) do
fail_test "inclusion after parameterization failed" unless stdout.include? "1-2"
apply_manifest_on(agents, manifest) do |result|
fail_test "inclusion after parameterization failed" unless result.stdout.include? "1-2"
end

########################################################################
Expand All @@ -41,8 +41,8 @@ class x($y, $z='2') {
class {x: y => '1'}
}

apply_manifest_on(agents, manifest) do
fail_test "the default didn't apply as expected" unless stdout.include? "1-2"
apply_manifest_on(agents, manifest) do |result|
fail_test "the default didn't apply as expected" unless result.stdout.include? "1-2"
end

########################################################################
Expand All @@ -54,6 +54,6 @@ class x($y, $z='2') {
class {x: y => '1', z => '3'}
}

apply_manifest_on(agents, manifest) do
fail_test "the override didn't happen as we expected" unless stdout.include? "1-3"
apply_manifest_on(agents, manifest) do |result|
fail_test "the override didn't happen as we expected" unless result.stdout.include? "1-3"
end
4 changes: 2 additions & 2 deletions acceptance/tests/apply/classes/should_allow_param_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class child inherits parent {
include child
}

apply_manifest_on(agents, manifest) do
apply_manifest_on(agents, manifest) do |result|
fail_test "parameter override didn't work" unless
stdout.include? "defined 'message' as 'child'"
result.stdout.include? "defined 'message' as 'child'"
end

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class child inherits parent {
step "apply the manifest"
apply_manifest_on(agent, manifest)
step "verify the file content"
on(agent, "cat #{out}") do
fail_test "the file was not touched" if stdout.include? "hello world!"
fail_test "the file was not updated" unless stdout.include? "hello new world"
on(agent, "cat #{out}") do |result|
fail_test "the file was not touched" if result.stdout.include? "hello world!"
fail_test "the file was not updated" unless result.stdout.include? "hello new world"
end

on(agent, "rm -rf #{dir}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class x {
}
include x
}
apply_manifest_on(agents, manifest) do
fail_test "the resource did not apply" unless
stdout.include? "defined 'message' as 'a'"
apply_manifest_on(agents, manifest) do |result|
fail_test "the resource did not apply" unless result.stdout.include?("defined 'message' as 'a'")
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'audit:unit' # This should be covered at the unit layer.

manifest = %q{ class x { notify { 'test': message => 'never invoked' } } }
apply_manifest_on(agents, manifest) do
apply_manifest_on(agents, manifest) do |result|
fail_test "found the notify despite not including it" if
stdout.include? "never invoked"
result.stdout.include? "never invoked"
end
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@

step "Run agent again using --use_cached_catalog and ensure content from the first code_id is used"
on(agent, puppet("agent", "-t", "--use_cached_catalog"), :acceptable_exit_codes => [0,2])
on(agent, "cat #{agent_test_file_path}") do
assert_equal('code_version_1', stdout)
on(agent, "cat #{agent_test_file_path}") do |result|
assert_equal('code_version_1', result.stdout)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def remove_reports_on_master(master_reportdir, agent_node_name)

def get_catalog_uuid_from_cached_catalog(host, agent_vardir, agent_node_name)
cache_catalog_uuid = nil
on(host, "cat #{agent_vardir}/client_data/catalog/#{agent_node_name}.json") do
cache_catalog_uuid = stdout.match(/"catalog_uuid":"([a-z0-9\-]*)",/)[1]
on(host, "cat #{agent_vardir}/client_data/catalog/#{agent_node_name}.json") do |result|
cache_catalog_uuid = result.stdout.match(/"catalog_uuid":"([a-z0-9\-]*)",/)[1]
end
cache_catalog_uuid
end

def get_catalog_uuid_from_report(master_reportdir, agent_node_name)
report_catalog_uuid = nil
on(master, "cat #{master_reportdir}/#{agent_node_name}/*") do
report_catalog_uuid = stdout.match(/catalog_uuid: '?([a-z0-9\-]*)'?/)[1]
on(master, "cat #{master_reportdir}/#{agent_node_name}/*") do |result|
report_catalog_uuid = result.stdout.match(/catalog_uuid: '?([a-z0-9\-]*)'?/)[1]
end
report_catalog_uuid
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@
agents.each do |agent|
on(agent, puppet('agent',
"--test --environment #{environment}"),
:acceptable_exit_codes => (0..255)) do
assert_match(/you win/, stdout,
'agent did not pickup newly classified environment.')
:acceptable_exit_codes => (0..255)) do |result|
assert_match(/you win/, result.stdout, 'agent did not pickup newly classified environment.')
end
end
end
4 changes: 2 additions & 2 deletions acceptance/tests/environment/can_enumerate_environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def curl_master_from(agent, path, headers = '', &block)

with_puppet_running_on(master, master_opts) do
step "Ensure that an unauthenticated client cannot access the environments list" do
on master, "curl --tlsv1 -ksv https://#{master}:#{server_port(master)}/puppet/v3/environments", :acceptable_exit_codes => [0,7] do
assert_match(/< HTTP\/1\.\d 403/, stderr)
on(master, "curl --tlsv1 -ksv https://#{master}:#{server_port(master)}/puppet/v3/environments", :acceptable_exit_codes => [0,7]) do |result|
assert_match(/< HTTP\/1\.\d 403/, result.stderr)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

step 'make environmentpath'
master_user = puppet_config(master, 'user', section: 'master')
cert_path = puppet_config(master, 'hostcert', section: 'master')
key_path = puppet_config(master, 'hostprivkey', section: 'master')
cacert_path = puppet_config(master, 'localcacert', section: 'master')
apply_manifest_on(master, <<-MANIFEST, :catch_failures => true)
File {
ensure => directory,
Expand All @@ -33,9 +30,6 @@

step 'run master; ensure production environment created'
with_puppet_running_on(master, master_opts, testdir) do
if master.is_using_passenger?
on(master, "curl -k --cert #{cert_path} --key #{key_path} --cacert #{cacert_path} https://localhost:8140/puppet/v3/environments")
end
on(master, "test -d '#{testdir}/environments/production'")

step 'ensure catalog returned from production env with no changes'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

step 'Expect no production environment folder changes' do
on(agent, "ls #{custom_environment_path}") do |result|
assert_no_match(/production/, result.stdout)
refute_match(/production/, result.stdout)
end

on(agent, "ls #{default_environment_path}") do |result|
Expand All @@ -110,7 +110,7 @@
step 'Expect production environment folder to be recreated in the custom path' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
step 'Expect the module to be gone on the server node' do
assert_no_match(/Error:.*i18ndemo/, result.stderr)
refute_match(/Error:.*i18ndemo/, result.stderr)
end if agent == master

step 'Expect the production environment, along with the module, to be synced back on the agent node' do
Expand All @@ -123,7 +123,7 @@
end

on(agent, "ls #{default_environment_path}") do |result|
assert_no_match(/production/, result.stdout)
refute_match(/production/, result.stdout)
end
end

Expand All @@ -134,7 +134,7 @@
step 'Expect production environment folder to be found in both paths but use the default one' do
on(agent, puppet("agent -t"), :acceptable_exit_codes => [0, 2]) do |result|
step 'Expect the module to be gone' do
assert_no_match(/Error:.*i18ndemo/, result.stderr)
refute_match(/Error:.*i18ndemo/, result.stderr)
end if agent == master
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def run_with_environment(agent, environment, options = {})
end

run_with_environment(agent, "production", :expected_exit_code => 2) do |tmpdir, catalog_result|
assert_no_match(/module-atmp/, catalog_result.stdout, "module-atmp was included despite the default environment being loaded")
refute_match(/module-atmp/, catalog_result.stdout, "module-atmp was included despite the default environment being loaded")

assert_match(/environment fact from module-globalmod/, catalog_result.stdout)

Expand Down
6 changes: 3 additions & 3 deletions acceptance/tests/face/4654_facts_face.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
MANIFEST

step "Agent #{agent}: custom_fact and external_fact should be present in the output of `puppet facts`"
on agent, puppet('facts') do
assert_match(/"custom_fact": "foo"/, stdout, "custom_fact did not match expected output")
assert_match(/"external_fact": "bar"/, stdout, "external_fact did not match expected output")
on agent, puppet('facts') do |result|
assert_match(/"custom_fact": "foo"/, result.stdout, "custom_fact did not match expected output")
assert_match(/"external_fact": "bar"/, result.stdout, "external_fact did not match expected output")
end
end
20 changes: 10 additions & 10 deletions acceptance/tests/face/loadable_from_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ def print
end
EOM

on(agent, puppet('help', '--config', puppetconf)) do
assert_match(/helloworld\s*Hello world face/, stdout, "Face missing from list of available subcommands")
on(agent, puppet('help', '--config', puppetconf)) do |result|
assert_match(/helloworld\s*Hello world face/, result.stdout, "Face missing from list of available subcommands")
end

on(agent, puppet('help', 'helloworld', '--config', puppetconf)) do
assert_match(/This is the hello world face/, stdout, "Descripion help missing")
assert_match(/moduleprint\s*Prints hello world from a required module/, stdout, "help for moduleprint action missing")
assert_match(/actionprint\s*Prints hello world from an action/, stdout, "help for actionprint action missing")
on(agent, puppet('help', 'helloworld', '--config', puppetconf)) do |result|
assert_match(/This is the hello world face/, result.stdout, "Descripion help missing")
assert_match(/moduleprint\s*Prints hello world from a required module/, result.stdout, "help for moduleprint action missing")
assert_match(/actionprint\s*Prints hello world from an action/, result.stdout, "help for actionprint action missing")
end

on(agent, puppet('helloworld', 'actionprint', '--config', puppetconf)) do
assert_match(/^Hello world from an action$/, stdout, "face did not print hello world")
on(agent, puppet('helloworld', 'actionprint', '--config', puppetconf)) do |result|
assert_match(/^Hello world from an action$/, result.stdout, "face did not print hello world")
end

on(agent, puppet('helloworld', 'moduleprint', '--config', puppetconf)) do
assert_match(/^Hello world from a required module$/, stdout, "face did not load module to print hello world")
on(agent, puppet('helloworld', 'moduleprint', '--config', puppetconf)) do |result|
assert_match(/^Hello world from a required module$/, result.stdout, "face did not load module to print hello world")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def refresh

step 'compile catalog and make sure that ruby code is NOT executed' do
on master, puppet('catalog', 'find', master.hostname) do |result|
assert_no_match(/running ruby code/, result.stderr)
refute_match(/running ruby code/, result.stderr)
catalog_results[master.hostname]['pcore_cat'] = JSON.parse(result.stdout.sub(/^[^{]+/,''))
end
end
Expand Down
4 changes: 2 additions & 2 deletions acceptance/tests/language/resource_refs_with_nested_arrays.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
MANIFEST

apply_manifest_on agent, test_manifest do
assert_match(/Exec\[third\].*the final command/, stdout)
apply_manifest_on(agent, test_manifest) do |result|
assert_match(/Exec\[third\].*the final command/, result.stdout)
end
end
6 changes: 3 additions & 3 deletions acceptance/tests/loader/func4x_loadable_from_modules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class helloworld {
SOURCE

# Run apply to generate the file with the output
on agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf)
on(agent, puppet('apply', '-e', "'include helloworld'", '--config', puppetconf))

# Assert that the file was written with the generated content
on(agent, "cat #{File.join(target_path, 'result.txt')}") do
assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, stdout, "Generated the wrong content")
on(agent, "cat #{File.join(target_path, 'result.txt')}") do |result|
assert_match(/^Generated, 1 => 10, 2 => 20, 3 => 30$/, result.stdout, "Generated the wrong content")
end

end
Loading

0 comments on commit fb5cc8c

Please sign in to comment.