From 90091d2c3215c53c83142249eb11b6506f8b8c99 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 24 Jul 2024 17:29:56 +0200 Subject: [PATCH] Use explicit hosts in host_prebuilt_steps_spec.rb This removes the common hosts in favor of explicit host definitions. --- spec/beaker/host_prebuilt_steps_spec.rb | 109 ++++++++++-------------- 1 file changed, 45 insertions(+), 64 deletions(-) diff --git a/spec/beaker/host_prebuilt_steps_spec.rb b/spec/beaker/host_prebuilt_steps_spec.rb index 8bc0dba0d..b1f093f2c 100644 --- a/spec/beaker/host_prebuilt_steps_spec.rb +++ b/spec/beaker/host_prebuilt_steps_spec.rb @@ -11,14 +11,6 @@ let(:rhel8_packages) { Beaker::HostPrebuiltSteps::RHEL8_PACKAGES } let(:fedora_packages) { Beaker::HostPrebuiltSteps::FEDORA_PACKAGES } let(:amazon2023_packages) { Beaker::HostPrebuiltSteps::AMAZON2023_PACKAGES } - let(:platform) { @platform || 'el-9-64' } - let(:hosts) do - hosts = make_hosts({ :platform => platform }) - hosts[0][:roles] = ['agent'] - hosts[1][:roles] = %w[master dashboard agent database] - hosts[2][:roles] = ['agent'] - hosts - end let(:dummy_class) { Class.new { include Beaker::HostPrebuiltSteps } } shared_examples 'enables_root_login' do |platform, commands, non_cygwin| @@ -267,17 +259,19 @@ subject { dummy_class.new } it "can sync keys on a solaris host" do - @platform = 'solaris-11-64' + host = make_host('host', { 'platform' => 'solaris-11-64' }) - expect(Beaker::Command).to receive(:new).with(sync_cmd % "bash").exactly(3).times + expect(Beaker::Command).to receive(:new).with(sync_cmd % "bash").once - subject.sync_root_keys(hosts, options) + subject.sync_root_keys(host, options) end it "can sync keys on a non-solaris host" do - expect(Beaker::Command).to receive(:new).with(sync_cmd % "env PATH=\"/usr/gnu/bin:$PATH\" bash").exactly(3).times + host = make_host('host', { 'platform' => 'el-9-64' }) + + expect(Beaker::Command).to receive(:new).with(sync_cmd % "env PATH=\"/usr/gnu/bin:$PATH\" bash").once - subject.sync_root_keys(hosts, options) + subject.sync_root_keys(host, options) end end @@ -285,94 +279,81 @@ subject { dummy_class.new } it "can validate el-9 hosts" do - hosts.each do |host| - rhel8_packages.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + host = make_host('host', { :platform => 'el-9-64' }) + + rhel8_packages.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate windows hosts" do - @platform = 'windows-11-64' - - hosts.each do |host| - windows_pkgs.each do |pkg| - allow(host).to receive(:cygwin_installed?).and_return(true) - allow(host).to receive(:is_cygwin?).and_return(true) - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + host = make_host('host', { :platform => 'windows-11-64', :is_cygwin => true }) + allow(host).to receive(:cygwin_installed?).and_return(true) + + windows_pkgs.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate SLES hosts" do - @platform = 'sles-13.1-x64' + host = make_host('host', { :platform => 'sles-13.1-x86_64' }) - hosts.each do |host| - sles_only_pkgs.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + sles_only_pkgs.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate opensuse hosts" do - @platform = 'opensuse-15-x86_x64' + host = make_host('host', { :platform => 'opensuse-15-x86_x64' }) - hosts.each do |host| - sles_only_pkgs.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + sles_only_pkgs.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate RHEL8 hosts" do - @platform = 'el-8-x86_x64' + host = make_host('host', { :platform => 'el-8-64' }) - hosts.each do |host| - rhel8_packages.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + rhel8_packages.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate Fedora hosts" do - @platform = 'fedora-32-x86_64' + host = make_host('host', { :platform => 'fedora-32-x86_64' }) - hosts.each do |host| - fedora_packages.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + fedora_packages.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end it "can validate Amazon hosts" do - @platform = 'amazon-2023-x86_64' + host = make_host('host', { :platform => 'amazon-2023-x86_64' }) - hosts.each do |host| - amazon2023_packages.each do |pkg| - expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) - expect(host).to receive(:install_package).with(pkg).once - end + amazon2023_packages.each do |pkg| + expect(host).to receive(:check_for_package).with(pkg).once.and_return(false) + expect(host).to receive(:install_package).with(pkg).once end - subject.validate_host(hosts, options) + subject.validate_host(host, options) end end