From e3652a0f58679056b8309f4eabe62ae16399165a Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Mon, 5 Feb 2024 21:40:09 -0800 Subject: [PATCH] Use agents beaker DSL method Beaker's singular `agent` DSL method can either return a single host or an array of hosts, depending on how many hosts have the agent role in your beaker config. For example, when running with `redhat7-64m-ubuntu2004-64a`, then it will return a single host. If running with `redhat7-64ma-ubuntu2004-64a`, then it will return an array of hosts[1]. The beaker `agent` method should never be used as it can cause tests to pass in agent CI, but fail in puppetserver CI, since they test the agent running on the server host. Instead reference the `agents` method, which is guaranteed to exist and return an array, possible empty. Also use the `fact_on` helper which parses the facter output as JSON and avoids having to chomp newlines in the output. [1] https://github.com/voxpupuli/beaker/blob/abd5b30e93061b44e45f2211bc6a73cb6e20b353/lib/beaker/dsl/roles.rb#L181-L187 --- .../package/common_package_name_in_different_providers.rb | 4 +++- acceptance/tests/resource/package/yum.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/acceptance/tests/resource/package/common_package_name_in_different_providers.rb b/acceptance/tests/resource/package/common_package_name_in_different_providers.rb index 96b278befbe..536f5c6d00a 100644 --- a/acceptance/tests/resource/package/common_package_name_in_different_providers.rb +++ b/acceptance/tests/resource/package/common_package_name_in_different_providers.rb @@ -7,7 +7,9 @@ end # Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096) - on(agent, 'dnf -y upgrade almalinux-release') if on(agent, facter('os.name')).stdout.strip == 'AlmaLinux' + agents.each do |agent| + on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux' + end tag 'audit:high', 'audit:acceptance' # Uses a provider that depends on AIO packaging diff --git a/acceptance/tests/resource/package/yum.rb b/acceptance/tests/resource/package/yum.rb index ce1e4d07bcb..da23c785724 100644 --- a/acceptance/tests/resource/package/yum.rb +++ b/acceptance/tests/resource/package/yum.rb @@ -7,7 +7,9 @@ end # Upgrade the AlmaLinux release package for newer keys until our image is updated (RE-16096) - on(agent, 'dnf -y upgrade almalinux-release') if on(agent, facter('os.name')).stdout.strip == 'AlmaLinux' + agents.each do |agent| + on(agent, 'dnf -y upgrade almalinux-release') if fact_on(agent, 'os.name') == 'AlmaLinux' + end tag 'audit:high', 'audit:acceptance' # Could be done at the integration (or unit) layer though