From c4d6e53808bd4ef5d49c963d6b56843d584eb9e7 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Thu, 8 Feb 2024 12:17:27 -0800 Subject: [PATCH] Update Beaker result proxies on host object 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. --- .../lib/puppet/acceptance/environment_utils.rb | 6 +++--- acceptance/lib/puppet/acceptance/module_utils.rb | 11 ++++++----- .../lib/puppet/acceptance/service_utils.rb | 16 ++++++++-------- acceptance/tests/agent/agent_disable_lockfile.rb | 3 +-- .../environment/can_enumerate_environments.rb | 4 ++-- ...tory_environment_production_created_master.rb | 4 ++-- ...p_stubs_should_be_available_via_pluginsync.rb | 4 ++-- .../tests/resource/service/should_query_all.rb | 2 +- ...ir_hook_should_be_called_on_initialization.rb | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/acceptance/lib/puppet/acceptance/environment_utils.rb b/acceptance/lib/puppet/acceptance/environment_utils.rb index afb744aec70..21282c611eb 100644 --- a/acceptance/lib/puppet/acceptance/environment_utils.rb +++ b/acceptance/lib/puppet/acceptance/environment_utils.rb @@ -241,7 +241,7 @@ 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 @@ -249,12 +249,12 @@ def use_an_environment(environment, description, master_opts, envdir, confdir, o 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 diff --git a/acceptance/lib/puppet/acceptance/module_utils.rb b/acceptance/lib/puppet/acceptance/module_utils.rb index 5827737238e..3c840b39fea 100644 --- a/acceptance/lib/puppet/acceptance/module_utils.rb +++ b/acceptance/lib/puppet/acceptance/module_utils.rb @@ -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. diff --git a/acceptance/lib/puppet/acceptance/service_utils.rb b/acceptance/lib/puppet/acceptance/service_utils.rb index de9ba3ffafd..cc7048005d2 100644 --- a/acceptance/lib/puppet/acceptance/service_utils.rb +++ b/acceptance/lib/puppet/acceptance/service_utils.rb @@ -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 @@ -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 @@ -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 diff --git a/acceptance/tests/agent/agent_disable_lockfile.rb b/acceptance/tests/agent/agent_disable_lockfile.rb index 2b011605d66..68d4419668f 100644 --- a/acceptance/tests/agent/agent_disable_lockfile.rb +++ b/acceptance/tests/agent/agent_disable_lockfile.rb @@ -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' diff --git a/acceptance/tests/environment/can_enumerate_environments.rb b/acceptance/tests/environment/can_enumerate_environments.rb index eeb08c61dcb..3fb8a0dad98 100644 --- a/acceptance/tests/environment/can_enumerate_environments.rb +++ b/acceptance/tests/environment/can_enumerate_environments.rb @@ -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 diff --git a/acceptance/tests/environment/directory_environment_production_created_master.rb b/acceptance/tests/environment/directory_environment_production_created_master.rb index b0fd60e3c1b..3f4c3ec0b77 100644 --- a/acceptance/tests/environment/directory_environment_production_created_master.rb +++ b/acceptance/tests/environment/directory_environment_production_created_master.rb @@ -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 diff --git a/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb b/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb index 169f734f2c8..ee632dc69e5 100644 --- a/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb +++ b/acceptance/tests/pluginsync/7316_faces_with_app_stubs_should_be_available_via_pluginsync.rb @@ -133,7 +133,7 @@ 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 @@ -141,7 +141,7 @@ class Puppet::Application::#{app_name.capitalize} < Puppet::Application::FaceBas 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 diff --git a/acceptance/tests/resource/service/should_query_all.rb b/acceptance/tests/resource/service/should_query_all.rb index f0ab8e2ad94..4647701b3cf 100644 --- a/acceptance/tests/resource/service/should_query_all.rb +++ b/acceptance/tests/resource/service/should_query_all.rb @@ -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 diff --git a/acceptance/tests/ticket_13948_lib_dir_hook_should_be_called_on_initialization.rb b/acceptance/tests/ticket_13948_lib_dir_hook_should_be_called_on_initialization.rb index 29482fcc568..60402ac7246 100644 --- a/acceptance/tests/ticket_13948_lib_dir_hook_should_be_called_on_initialization.rb +++ b/acceptance/tests/ticket_13948_lib_dir_hook_should_be_called_on_initialization.rb @@ -137,7 +137,7 @@ 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 @@ -145,7 +145,7 @@ class Puppet::Application::#{app_name.capitalize} < Puppet::Application::FaceBas 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