Skip to content

Commit

Permalink
Update stdout and stderr methods
Browse files Browse the repository at this point in the history
Previously in Beaker, you could use standalone stdout and stderr methods
to access output from remote machines.

These methods were deprecated in 2013 with voxpupuli/beaker@28b2510 and
dropped entirely in voxpupuli/beaker@73a31c7.

This commit removes these methods from puppet tests in favor of calling
stdout and stderr methods on Result objects.
  • Loading branch information
mhashizume committed Feb 1, 2024
1 parent 0162588 commit c2d49a1
Show file tree
Hide file tree
Showing 69 changed files with 327 additions and 338 deletions.
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: 3 additions & 5 deletions acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
testdir = master.tmpdir("nodenamefact")
node_names = []

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

node_names.uniq!

Expand Down Expand Up @@ -147,8 +145,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
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
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
27 changes: 14 additions & 13 deletions acceptance/tests/lookup/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,27 @@ class #{module_name}($#{env_data_implied_key},
with_puppet_running_on master, master_opts, testdir do
step "Lookup string data, binding specified in metadata.json" do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [0, 2])
assert_match("#{env_data_implied_key} #{env_data_implied_value}", stdout)
assert_match("#{env_data_key} #{env_data_value}", stdout)
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [0, 2]) do |result|
assert_match("#{env_data_implied_key} #{env_data_implied_value}", result.stdout)
assert_match("#{env_data_key} #{env_data_value}", result.stdout)

assert_match("#{module_data_implied_key} #{module_data_implied_value}", stdout)
assert_match("#{module_data_key} #{module_data_value}", stdout)
assert_match("#{module_data_implied_key} #{module_data_implied_value}", result.stdout)
assert_match("#{module_data_key} #{module_data_value}", result.stdout)

assert_match("#{module_data_key} #{module_data_value_other}", stdout)
assert_match("#{module_data_key} #{module_data_value_other}", result.stdout)

assert_match("#{env_data_override_implied_key} #{env_data_override_implied_value}", stdout)
assert_match("#{env_data_override_key} #{env_data_override_value}", stdout)
assert_match("#{env_data_override_implied_key} #{env_data_override_implied_value}", result.stdout)
assert_match("#{env_data_override_key} #{env_data_override_value}", result.stdout)

assert_match("#{hiera_data_implied_key} #{hiera_data_implied_value}", stdout)
assert_match("#{hiera_data_key} #{hiera_data_value}", stdout)
assert_match("#{hiera_data_implied_key} #{hiera_data_implied_value}", result.stdout)
assert_match("#{hiera_data_key} #{hiera_data_value}", result.stdout)

assert_match("#{hash_name} {#{module_hash_key} => #{module_hash_value}, #{env_hash_key} => #{env_hash_value}, #{hiera_hash_key} => #{hiera_hash_value}}", stdout)
assert_match("#{hash_name} {#{module_hash_key} => #{module_hash_value}, #{env_hash_key} => #{env_hash_value}, #{hiera_hash_key} => #{hiera_hash_value}}", result.stdout)

assert_match("#{array_key} [#{hiera_array_value0}, #{hiera_array_value1}, #{env_array_value0}, #{env_array_value1}, #{module_array_value0}, #{module_array_value1}]", stdout)
assert_match("#{array_key} [#{hiera_array_value0}, #{hiera_array_value1}, #{env_array_value0}, #{env_array_value1}, #{module_array_value0}, #{module_array_value1}]", result.stdout)

assert_match("#{automatic_data_key} #{automatic_data_value}", stdout)
assert_match("#{automatic_data_key} #{automatic_data_value}", result.stdout)
end
end
end
end
Expand Down
7 changes: 4 additions & 3 deletions acceptance/tests/ordering/master_agent_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@

with_puppet_running_on(master, master_opts) do
agents.each do |agent|
on(agent, puppet('agent', "--no-daemonize --onetime --verbose"))
if stdout !~ /Notice: first.*Notice: second.*Notice: third.*Notice: fourth.*Notice: fifth.*Notice: sixth.*Notice: seventh.*Notice: eighth/m
fail_test "Output did not include the notify resources in the correct order"
on(agent, puppet('agent', "--no-daemonize --onetime --verbose")) do |result|
if result.stdout !~ /Notice: first.*Notice: second.*Notice: third.*Notice: fourth.*Notice: fifth.*Notice: sixth.*Notice: seventh.*Notice: eighth/m
fail_test "Output did not include the notify resources in the correct order"
end
end
end
end
6 changes: 3 additions & 3 deletions acceptance/tests/parser_functions/hiera/lookup_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class apache {

with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2])

assert_match("apache server port: 8080", stdout)
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match('apache server port: 8080', result.stdout)
end
end
end
8 changes: 4 additions & 4 deletions acceptance/tests/parser_functions/hiera_array/lookup_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class ntp {

with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2])

assert_match("ntpserver global.ntp.puppetlabs.com", stdout)
assert_match("ntpserver production.ntp.puppetlabs.com", stdout)
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match('ntpserver global.ntp.puppetlabs.com', result.stdout)
assert_match('ntpserver production.ntp.puppetlabs.com', result.stdout)
end
end
end
6 changes: 3 additions & 3 deletions acceptance/tests/parser_functions/hiera_hash/lookup_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@

with_puppet_running_on master, master_opts, testdir do
agents.each do |agent|
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2])

assert_match("name: postgres shell: /bin/bash", stdout)
on(agent, puppet('agent', "-t"), :acceptable_exit_codes => [2]) do |result|
assert_match("name: postgres shell: /bin/bash", result.stdout)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

with_puppet_running_on master, master_opts, basedir do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/pluginfacts/, stderr)
refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/plugins/, stderr)
on(agent, puppet('agent', "-t")) do |result|
refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/pluginfacts/, result.stderr)
refute_match(/Could not retrieve information from environment production source\(s\) puppet:\/\/\/plugins/, result.stderr)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
with_puppet_running_on master, master_opts, basedir do
agents.each do |agent|
on(agent, puppet('agent', "-t"))
on agent, "cat \"#{agent.puppet['vardir']}/lib/foo.rb\"" do
assert_match(/from the first module/, stdout, "The synced plugin was not found or the wrong version was synced")
on(agent, "cat \"#{agent.puppet['vardir']}/lib/foo.rb\"") do |result|
assert_match(/from the first module/, result.stdout, "The synced plugin was not found or the wrong version was synced")
end
end
end
Loading

0 comments on commit c2d49a1

Please sign in to comment.