Skip to content

Commit

Permalink
Update Beaker result proxies on host object
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 updates any methods that were initially missed in the first
pass of this work in commit 9f5f8e5.
  • Loading branch information
mhashizume committed Feb 9, 2024
1 parent a3e77e7 commit c4d6e53
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions acceptance/lib/puppet/acceptance/environment_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,20 @@ def use_an_environment(environment, description, master_opts, envdir, confdir, o
# Test agents configured to use directory environments (affects environment
# loading on the agent, especially with regards to requests/node environment)
args << "--environmentpath='$confdir/environments'" if directory_environments && agent != master
on(agent, puppet("agent", *args), :acceptable_exit_codes => (0..255)) do
on(agent, puppet("agent", *args), :acceptable_exit_codes => (0..255)) do |result|
agent_results[:puppet_agent] = result
end

args = ["--trace"]
args << ["--environment", environment] if environment

step "print puppet config for #{description} environment"
on(master, puppet(*(["config", "print", "basemodulepath", "modulepath", "manifest", "config_version", config_print] + args)), :acceptable_exit_codes => (0..255)) do
on(master, puppet(*(["config", "print", "basemodulepath", "modulepath", "manifest", "config_version", config_print] + args)), :acceptable_exit_codes => (0..255)) do |result|
agent_results[:puppet_config] = result
end

step "puppet apply using #{description} environment"
on(master, puppet(*(["apply", '-e', '"include testing_mod"'] + args)), :acceptable_exit_codes => (0..255)) do
on(master, puppet(*(["apply", '-e', '"include testing_mod"'] + args)), :acceptable_exit_codes => (0..255)) do |result|
agent_results[:puppet_apply] = result
end
end
Expand Down
11 changes: 6 additions & 5 deletions acceptance/lib/puppet/acceptance/module_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def get_default_modulepath_for_host(host)
# @param host [String] hostname
# @return [Array] paths for found modules
def get_installed_modules_for_host(host)
on host, puppet("module list --render-as json")
str = stdout.lines.to_a.last
pat = /\(([^()]+)\)/
mods = str.scan(pat).flatten
return mods
on(host, puppet('module list --render-as json')) do |result|
str = result.stdout.lines.to_a.last
pat = /\(([^()]+)\)/
mods = str.scan(pat).flatten
return mods
end
end

# Return a hash of array of paths to installed modules for a hosts.
Expand Down
16 changes: 8 additions & 8 deletions acceptance/lib/puppet/acceptance/service_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def ensure_service_change_on_host(host, service, status)
# that the exit code is either
# 2 => something changed, or
# 0 => no change needed
apply_manifest_on host, service_manifest(service, status), :acceptable_exit_codes => [0, 2] do
assert_match(/Service\[#{service}\]\/ensure: ensure changed '\w+' to '#{status[:ensure]}'/, stdout, 'Service status change failed') if status[:ensure]
assert_match(/Service\[#{service}\]\/enable: enable changed '\w+' to '#{status[:enable]}'/, stdout, 'Service enable change failed') if status[:enable]
apply_manifest_on(host, service_manifest(service, status), :acceptable_exit_codes => [0, 2]) do |result|
assert_match(/Service\[#{service}\]\/ensure: ensure changed '\w+' to '#{status[:ensure]}'/, result.stdout, 'Service status change failed') if status[:ensure]
assert_match(/Service\[#{service}\]\/enable: enable changed '\w+' to '#{status[:enable]}'/, result.stdout, 'Service enable change failed') if status[:enable]
end
end

Expand All @@ -56,9 +56,9 @@ def ensure_service_change_on_host(host, service, status)
# @return None
def ensure_service_idempotent_on_host(host, service, status)
# ensure idempotency
apply_manifest_on host, service_manifest(service, status) do
assert_no_match(/Service\[#{service}\]\/ensure/, stdout, 'Service status not idempotent') if status[:ensure]
assert_no_match(/Service\[#{service}\]\/enable/, stdout, 'Service enable not idempotent') if status[:enable]
apply_manifest_on(host, service_manifest(service, status)) do |result|
assert_no_match(/Service\[#{service}\]\/ensure/, result.stdout, 'Service status not idempotent') if status[:ensure]
assert_no_match(/Service\[#{service}\]\/enable/, result.stdout, 'Service enable not idempotent') if status[:enable]
end
end

Expand Down Expand Up @@ -86,8 +86,8 @@ def assert_service_status_on_host(host, service, status, &block)
ensure_status = "ensure.+=> '#{status[:ensure]}'" if status[:ensure]
enable_status = "enable.+=> '#{status[:enable]}'" if status[:enable]

on host, puppet_resource('service', service) do
assert_match(/'#{service}'.+#{ensure_status}.+#{enable_status}/m, stdout, "Service status does not match expectation #{status}")
on(host, puppet_resource('service', service)) do |result|
assert_match(/'#{service}'.+#{ensure_status}.+#{enable_status}/m, result.stdout, "Service status does not match expectation #{status}")
end

# Verify service state on the system using a custom block
Expand Down
3 changes: 1 addition & 2 deletions acceptance/tests/agent/agent_disable_lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@

step "attempt to run the agent (message: '#{expected_message}')" do
agents.each do |agent|
on(agent, puppet('agent', "--test"),
:acceptable_exit_codes => [1]) do
on(agent, puppet('agent', "--test"), :acceptable_exit_codes => [1]) do |result|
disabled_regex = /administratively disabled.*'#{expected_message}'/
unless result.stdout =~ disabled_regex
fail_test("Unexpected output from attempt to run agent disabled; expecting to match '#{disabled_regex}', got '#{result.stdout}' on agent '#{agent}'") unless agent['locale'] == 'ja'
Expand Down
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 @@ -65,8 +65,8 @@ def curl_master_from(agent, path, headers = '', &block)
end

step "Ensure that an authenticated client can retrieve the list of environments" do
curl_master_from(master, '/puppet/v3/environments') do
data = JSON.parse(stdout)
curl_master_from(master, '/puppet/v3/environments') do |result|
data = JSON.parse(result.stdout)
assert_equal(["env1", "env2", "production"], data["environments"].keys.sort)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

step 'ensure catalog returned from production env with no changes'
agents.each do |agent|
on(agent, puppet("agent -t --environment production --detailed-exitcodes")) do
on(agent, puppet("agent -t --environment production --detailed-exitcodes")) do |result|
# detailed-exitcodes produces a 0 when no changes are made.
assert_equal(0, exit_code)
assert_equal(0, result.exit_code)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ class Puppet::Application::#{app_name.capitalize} < Puppet::Application::FaceBas

step "verify that the application shows up in help" do
agents.each do |agent|
on(agent, PuppetCommand.new(:help, "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do
on(agent, PuppetCommand.new(:help, "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do |result|
assert_match(/^\s+#{app_name}\s+#{app_desc % "face"}/, result.stdout)
end
end
end

step "verify that we can run the application" do
agents.each do |agent|
on(agent, PuppetCommand.new(:"#{app_name}", "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do
on(agent, PuppetCommand.new(:"#{app_name}", "--libdir=\"#{get_test_file_path(agent, agent_lib_dir)}\"")) do |result|
assert_match(/^#{app_output % "face"}/, result.stdout)
end
end
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/resource/service/should_query_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
agents.each do |agent|
step "query with puppet"
on(agent, puppet_resource('service'), :accept_all_exit_codes => true) do |result|
assert_equal(exit_code, 0, "'puppet resource service' should have an exit code of 0")
assert_equal(result.exit_code, 0, "'puppet resource service' should have an exit code of 0")
assert(/^service/ =~ result.stdout, "'puppet resource service' should present service details")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ class Puppet::Application::#{app_name.capitalize} < Puppet::Application::FaceBas

step "verify that the application shows up in help" do
agents.each do |agent|
on(agent, PuppetCommand.new(:help, "--vardir=\"#{get_test_file_path(agent, agent_var_dir)}\"")) do
on(agent, PuppetCommand.new(:help, "--vardir=\"#{get_test_file_path(agent, agent_var_dir)}\"")) do |result|
assert_match(/^\s+#{app_name}\s+#{app_desc % "face"}/, result.stdout)
end
end
end

step "verify that we can run the application" do
agents.each do |agent|
on(agent, PuppetCommand.new(:"#{app_name}", "--vardir=\"#{get_test_file_path(agent, agent_var_dir)}\"")) do
on(agent, PuppetCommand.new(:"#{app_name}", "--vardir=\"#{get_test_file_path(agent, agent_var_dir)}\"")) do |result|
assert_match(/^#{app_output % "face"}/, result.stdout)
end
end
Expand Down

0 comments on commit c4d6e53

Please sign in to comment.