From 5380a129998fee6fec87d1ef3cd3dc4f1fa9e384 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Thu, 29 Feb 2024 14:11:57 -0800 Subject: [PATCH] Re-add removed methods Two methods were mistakenly removed from both Beaker and beaker-puppet, breaking tests for modules. puppet_agent_dev_package_info was removed in Beaker in voxpupuli/beaker@cdaedad under the mistaken assumption that it had already been moved over to beaker-puppet. install_puppet_agent_dev_repo_on was removed in beaker-puppet in 22a38c8 because it relied on puppet_agent_dev_package_info, which was no longer available. This commit restores those two methods (with some minor modifications for platforms that are no longer supported) and their associated tests. --- lib/beaker-puppet/install_utils/foss_utils.rb | 150 +++++++ .../install_utils/foss_utils_spec.rb | 380 ++++++++++++++++++ 2 files changed, 530 insertions(+) diff --git a/lib/beaker-puppet/install_utils/foss_utils.rb b/lib/beaker-puppet/install_utils/foss_utils.rb index 49ef8b9..97a3ae7 100644 --- a/lib/beaker-puppet/install_utils/foss_utils.rb +++ b/lib/beaker-puppet/install_utils/foss_utils.rb @@ -1195,6 +1195,117 @@ def install_packages_from_local_dev_repo(host, package_name) configure_type_defaults_on(host) end + # Install development repo of the puppet-agent on the given host(s). Downloaded from + # location of the form DEV_BUILDS_URL/puppet-agent/AGENT_VERSION/repos + # + # @param [Host, Array, String, Symbol] hosts One or more hosts to act upon, + # or a role (String or Symbol) that identifies one or more hosts. + # @param [Hash{Symbol=>String}] opts An options hash + # @option opts [String] :puppet_agent_version The version of puppet-agent to install. This + # parameter is used by puppet with the +SUITE_VERSION+ environment + # variable to provide a `git describe` value to beaker to create a + # build server URL. Note that +puppet_agent_sha+ will still be used + # instead of this if a value is provided for that option + # @option opts [String] :puppet_agent_sha The sha of puppet-agent to install, defaults to provided + # puppet_agent_version + # @option opts [String] :copy_base_local Directory where puppet-agent artifact + # will be stored locally + # (default: 'tmp/repo_configs') + # @option opts [String] :copy_dir_external Directory where puppet-agent + # artifact will be pushed to on the external machine + # (default: '/root') + # @option opts [String] :puppet_collection Defaults to 'PC1' + # @option opts [String] :dev_builds_url Base URL to pull artifacts from + # @option opts [String] :copy_base_local Directory where puppet-agent artifact + # will be stored locally + # (default: 'tmp/repo_configs') + # @option opts [String] :copy_dir_external Directory where puppet-agent + # artifact will be pushed to on the external machine + # (default: '/root') + # + # @note on windows, the +:ruby_arch+ host parameter can determine in addition + # to other settings whether the 32 or 64bit install is used + # + # @example + # install_puppet_agent_dev_repo_on(host, { :puppet_agent_sha => 'd3377feaeac173aada3a2c2cedd141eb610960a7', :puppet_agent_version => '1.1.1.225.gd3377fe' }) + # + # @return nil + def install_puppet_agent_dev_repo_on(hosts, global_opts) + global_opts[:puppet_agent_version] ||= global_opts[:version] # backward compatability + unless global_opts[:puppet_agent_version] + raise 'must provide :puppet_agent_version (puppet-agent version) for install_puppet_agent_dev_repo_on' + end + + block_on hosts do |host| + opts = global_opts.dup + + # TODO: consolidate these values as they serve no purpose from beaker's side + # you could provide any values you could to one to the other + puppet_agent_version = opts[:puppet_agent_sha] || opts[:puppet_agent_version] + + opts = sanitize_opts(opts) + opts[:download_url] = "#{opts[:dev_builds_url]}/puppet-agent/#{puppet_agent_version}/repos/" + opts[:copy_base_local] ||= File.join('tmp', 'repo_configs') + opts[:puppet_collection] ||= 'PC1' + + release_path = opts[:download_url] + + variant, version, arch, codename = host['platform'].to_array + add_role(host, 'aio') # we are installing agent, so we want aio role + copy_dir_local = File.join(opts[:copy_base_local], variant) + onhost_copy_base = opts[:copy_dir_external] || host.external_copy_base + + case variant + when /^(fedora|el|redhat|centos|debian|ubuntu)$/ + if host['hypervisor'] == 'ec2' + logger.trace("#install_puppet_agent_dev_repo_on: unsupported host #{host} for repo detected. using dev package") + else + install_puppetlabs_dev_repo(host, 'puppet-agent', puppet_agent_version, nil, opts) + host.install_package('puppet-agent') + logger.trace('#install_puppet_agent_dev_repo_on: install_puppetlabs_dev_repo finished') + next + end + when /^(osx|windows|solaris|sles|aix)$/ + # Download installer package file & run install manually. + # Done below, so that el hosts on ec2 can use this + # workflow as well + else + raise "No repository installation step for #{variant} yet..." + end + + release_path_end, release_file = host.puppet_agent_dev_package_info( + opts[:puppet_collection], opts[:puppet_agent_version], opts + ) + release_path << release_path_end + logger.trace('#install_puppet_agent_dev_repo_on: dev_package_info, continuing...') + + onhost_copied_file = File.join(onhost_copy_base, release_file) + fetch_http_file(release_path, release_file, copy_dir_local) + scp_to host, File.join(copy_dir_local, release_file), onhost_copy_base + + case variant + when /^(sles|aix|fedora|el|redhat|centos)$/ + # NOTE: AIX does not support repo management. This block assumes + # that the desired rpm has been mirrored to the 'repos' location. + # NOTE: the AIX 7.1 package will only install on 7.2 with + # --ignoreos. This is a bug in package building on AIX 7.1's RPM + aix_72_ignoreos_hack = '--ignoreos' if variant == 'aix' && version == '7.2' + on host, "rpm -ivh #{aix_72_ignoreos_hack} #{onhost_copied_file}" + when /^windows$/ + result = on host, "echo #{onhost_copied_file}" + onhost_copied_file = result.raw_output.chomp + msi_opts = { debug: host[:pe_debug] || opts[:pe_debug] } + install_msi_on(host, onhost_copied_file, {}, msi_opts) + when /^osx$/ + host.install_package("puppet-agent-#{opts[:puppet_agent_version]}*") + when /^solaris$/ + host.solaris_install_local_package(release_file, onhost_copy_base) + end + configure_type_defaults_on(host) + end + end + alias install_puppetagent_dev_repo install_puppet_agent_dev_repo_on + # This method will install a pem file certificate on a windows host # # @param [Host] host A host object @@ -1428,6 +1539,45 @@ def configure_gem_mirror(hosts) on(host, "#{gem} source --add #{gem_source}") end end + + # Gets the path & file name for the puppet agent dev package on Unix + # + # @param [String] puppet_collection Name of the puppet collection to use + # @param [String] puppet_agent_version Version of puppet agent to get + # @param [Hash{Symbol=>String}] opts Options hash to provide extra values + # + # @note macOS, Solaris, and Windows require some options to be set. See + # {#solaris_puppet_agent_dev_package_info}, + # {#mac_puppet_agent_dev_package_info}, and + # {WindowsUtils#puppet_agent_dev_package_info} for more details + # + # @raise [ArgumentError] If one of the two required parameters (puppet_collection, + # puppet_agent_version) is either not passed or set to nil + # + # @return [String, String] Path to the directory and filename of the package, respectively + def puppet_agent_dev_package_info( puppet_collection = nil, puppet_agent_version = nil, opts = {} ) + error_message = "Must provide %s argument to get puppet agent dev package information" + raise ArgumentError, error_message % "puppet_collection" unless puppet_collection + raise ArgumentError, error_message % "puppet_agent_version" unless puppet_agent_version + + variant, version, arch, _codename = self['platform'].to_array + + if %w[opensuse sles aix el centos oracle redhat scientific].include?(variant) + variant = 'el' if %w[el centos oracle redhat scientific].include?(variant) + variant = 'sles' if variant == 'opensuse' + + if variant == 'aix' + arch = 'ppc' if arch == 'power' + version = '7.1' if version == '7.2' + end + release_path_end = "#{variant}/#{version}/#{puppet_collection}/#{arch}" + release_file = "puppet-agent-#{puppet_agent_version}-1.#{variant}#{version}.#{arch}.rpm" + else + msg = "puppet_agent dev package info unknown for platform '#{self['platform']}'" + raise ArgumentError, msg + end + return release_path_end, release_file + end end end end diff --git a/spec/beaker-puppet/install_utils/foss_utils_spec.rb b/spec/beaker-puppet/install_utils/foss_utils_spec.rb index d3e1f8e..a1ef7fe 100644 --- a/spec/beaker-puppet/install_utils/foss_utils_spec.rb +++ b/spec/beaker-puppet/install_utils/foss_utils_spec.rb @@ -1092,6 +1092,309 @@ def stub_uninteresting_portions_of_install_puppetlabs_dev_repo! end end + describe '#install_puppet_agent_dev_repo_on' do + let(:package_name) { 'puppet-agent' } + let(:platform) { @platform || 'other' } + let(:host) do + FakeHost.create('fakvm', platform, opts) + end + + before :each do + allow(subject).to receive(:configure_foss_defaults_on).and_return(true) + end + + it 'raises an exception when host platform is unsupported' do + host = basic_hosts.first + host['platform'] = Beaker::Platform.new('f5-5-x4') + opts = { version: '0.1.0' } + allow(subject).to receive(:options).and_return({}) + + expect do + subject.install_puppet_agent_dev_repo_on(host, opts) + end.to raise_error(RuntimeError, /No repository installation step for/) + end + + it 'runs the correct install for el-based platforms' do + host = basic_hosts.first + host['platform'] = Beaker::Platform.new('el-5-x86_64') + sha_value = 'ereiuwoiur' + opts = { version: '0.1.0', puppet_agent_sha: sha_value } + allow(subject).to receive(:options).and_return({}) + + expect(subject).to receive(:install_puppetlabs_dev_repo).with( + host, 'puppet-agent', sha_value, nil, anything + ) + expect(host).to receive(:install_package).with('puppet-agent') + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct install for el-based platforms on s390x architectures' do + host = basic_hosts.first + host['platform'] = Beaker::Platform.new('el-5-s390x') + sha_value = 'ereiuwoiur' + opts = { version: '0.1.0', puppet_agent_sha: sha_value } + allow(subject).to receive(:options).and_return({}) + + release_path_end = 'fake_release_path_end' + release_file = 'fake_29835_release_file' + expect(host).to receive(:puppet_agent_dev_package_info).and_return( + [release_path_end, release_file], + ) + + expect(subject).not_to receive(:install_puppetlabs_dev_repo) + expect(host).not_to receive(:install_package) + + expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/el$}) + expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, anything) + expect(subject).to receive(:on).ordered.with(host, /rpm -ivh.*#{release_file}$/) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct agent install for el-based platforms on ec2 hypervisor' do + host = basic_hosts.first + host['platform'] = Beaker::Platform.new('el-5-x86_64') + host['hypervisor'] = 'ec2' + sha_value = 'ereiuwoiur' + opts = { version: '0.1.0', puppet_agent_sha: sha_value } + allow(subject).to receive(:options).and_return({}) + + release_path_end = 'fake_release_path_end' + release_file = 'fake_29835_release_file' + expect(host).to receive(:puppet_agent_dev_package_info).and_return( + [release_path_end, release_file], + ) + + expect(subject).not_to receive(:install_puppetlabs_dev_repo) + expect(host).not_to receive(:install_package) + + expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/el$}) + expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, anything) + expect(subject).to receive(:on).ordered.with(host, /rpm -ivh.*#{release_file}$/) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct install for debian-based platforms' do + platform = Beaker::Platform.new('debian-5-x86_64') + host = basic_hosts.first + host['platform'] = platform + sha_value = 'ereigregerge' + opts = { version: '0.1.0', puppet_agent_sha: sha_value } + allow(subject).to receive(:options).and_return({}) + + expect(subject).to receive(:install_puppetlabs_dev_repo).with( + host, 'puppet-agent', sha_value, nil, anything + ) + expect(host).to receive(:install_package).with('puppet-agent') + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct install for windows platforms' do + host = winhost + external_copy_base = 'tmp_install_windows_copy_base_1325' + allow(host).to receive(:external_copy_base).and_return(external_copy_base) + opts = { version: '0.1.0' } + allow(subject).to receive(:options).and_return({}) + copied_path = "#{win_temp}\\puppet-agent-0.1.0-x64.msi" + mock_echo = Object.new + allow(mock_echo).to receive(:raw_output).and_return(copied_path) + + expect(subject).to receive(:fetch_http_file).once.with(%r{/windows$}, 'puppet-agent-0.1.0-x64.msi', %r{/windows$}) + expect(subject).to receive(:scp_to).once.with(host, %r{/puppet-agent-0.1.0-x64.msi$}, /#{external_copy_base}/) + expect(subject).to receive(:install_msi_on).with(host, copied_path, {}, { debug: nil }).once + expect(subject).to receive(:on).ordered.with(host, /echo/).and_return(mock_echo) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct install for osx platforms' do + host = machost + host['platform'] = Beaker::Platform.new('osx-109-x86_64') + sha_value = 'runs the correct install for osx platforms' + copy_dir_external = 'fake_15_copy_dir_external' + opts = { + version: '0.1.0', + puppet_agent_sha: sha_value, + copy_dir_external: copy_dir_external, + } + + release_path_end = 'fake_release_path_end' + release_file = 'fake_29835_release_file' + expect(host).to receive(:puppet_agent_dev_package_info).and_return( + [release_path_end, release_file], + ) + + expect(subject).to receive(:fetch_http_file).once.with(/#{release_path_end}$/, release_file, %r{/osx$}) + expect(subject).to receive(:scp_to).once.with(host, /#{release_file}$/, copy_dir_external) + # the star is necessary, as that's not the entire filename, & we rely on + # the globbing to get this right on OSX SUTs + expect(host).to receive(:install_package).with(/^puppet-agent-0.1.0\*$/) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'runs the correct install for solaris platforms' do + @platform = 'solaris-10-x86_64' + opts = { version: '0.1.0' } + allow(subject).to receive(:options).and_return({}) + + release_path_end = 'fake_release_path_end' + release_file = 'fake_sol10_8495_release_file' + expect(host).to receive(:puppet_agent_dev_package_info).and_return( + [release_path_end, release_file], + ) + + expect(subject).to receive(:fetch_http_file).once.with( + /#{release_path_end}$/, release_file, anything + ) + expect(subject).to receive(:scp_to).once.with( + host, /#{release_file}$/, anything + ) + + expect(host).to receive(:solaris_install_local_package) + + allow(subject).to receive(:configure_type_defaults_on) + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'allows you to override the local copy directory' do + # only applies to hosts that don't go down the + # install_puppetlabs_dev_repo route + host = eoshost + host['platform'] = Beaker::Platform.new('eos-5-x86_64') + sha_value = 'dahdahdahdah' + copy_base_local_override = 'face' + opts = { + version: '0.1.0', + copy_base_local: copy_base_local_override, + puppet_agent_sha: sha_value, + } + allow(subject).to receive(:options).and_return({}) + + allow(host).to receive(:puppet_agent_dev_package_info).and_return(['', '']) + + allow(host).to receive(:get_remote_file).once.with(anything) + allow(host).to receive(:install_from_file) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'allows you to override the external copy directory' do + host = basic_hosts.first + host['platform'] = Beaker::Platform.new('osx-5-x86_64') + copy_dir_custom = 'muppetsBB8-1435' + opts = { version: '0.1.0', copy_dir_external: copy_dir_custom } + allow(subject).to receive(:options).and_return({}) + + allow(host).to receive(:puppet_agent_dev_package_info).and_return(['', '']) + + allow(subject).to receive(:fetch_http_file).once + expect(subject).to receive(:scp_to).once.with( + host, anything, /#{copy_dir_custom}/ + ) + allow(host).to receive(:install_package) + + subject.install_puppet_agent_dev_repo_on(host, opts) + end + + it 'copies package to the cygwin root directory and installs it' do + @platform = 'windows-7-x86_64' + expect(subject).to receive(:install_msi_on).with(any_args) + copy_base = 'copy_base_cygwin' + allow(host).to receive(:external_copy_base).and_return(copy_base) + expect(subject).to receive(:scp_to).with(host, /puppet-agent-1\.0\.0-x64\.msi/, /#{copy_base}/) + expect(subject).to receive(:configure_type_defaults_on).with(host) + expect(subject).to receive(:fetch_http_file).with(%r{[^/]\z}, anything, anything) + subject.install_puppet_agent_dev_repo_on(host, opts.merge({ puppet_agent_version: '1.0.0' })) + end + + it 'installs on different hosts without erroring' do + mhosts = hosts + mhosts[3] = eoshost + + mhosts.each_with_index do |host, index| + if index == 0 + host['platform'] = Beaker::Platform.new('solaris-5-x4') + allow(host).to receive(:external_copy_base) { '/host0' } + elsif index == 1 + host['platform'] = Beaker::Platform.new('windows-5-x4') + allow(host).to receive(:external_copy_base) { '/host1' } + elsif index == 2 + host['platform'] = Beaker::Platform.new('osx-5-x4') + allow(host).to receive(:external_copy_base) { '/host2' } + elsif index == 3 + host['platform'] = Beaker::Platform.new('eos-5-x4') + allow(host).to receive(:external_copy_base) { '/host3' } + end + allow(host).to receive(:puppet_agent_dev_package_info).with(any_args).and_return(%w[test blah]) + end + + expect(subject).to receive(:add_role).with(any_args).exactly(mhosts.length).times + + expect(subject).to receive(:fetch_http_file).with(any_args).exactly(3).times + expect(subject).to receive(:scp_to).with(any_args).exactly(3).times + + expect(subject).to receive(:install_msi_on).with(mhosts[1], 'xyz', {}, anything).exactly(1).times + expect(mhosts[0]).to receive(:solaris_install_local_package).with('blah', '/host0').exactly(1).times + expect(mhosts[2]).to receive(:install_package).with(any_args).exactly(1).times + expect(mhosts[3]).to receive(:install_from_file).with('blah').exactly(1).times + + result = object_double(Beaker::Result.new({}, 'foo'), raw_output: 'xyz') + allow(subject).to receive(:on).with(mhosts[1], anything).and_return(result) + + expect(subject).to receive(:configure_type_defaults_on).with(any_args).exactly(mhosts.length).times + + subject.install_puppet_agent_dev_repo_on(mhosts, opts.merge({ puppet_agent_version: '1.0.0' })) + end + + it 'installs on different hosts with options specifying :copy_dir_external' do + mhosts = hosts + mhosts[3] = eoshost + + mhosts.each_with_index do |host, index| + if index == 0 + host['platform'] = Beaker::Platform.new('solaris-5-x4') + allow(host).to receive(:external_copy_base) { '/host0' } + elsif index == 1 + host['platform'] = Beaker::Platform.new('windows-5-x4') + allow(host).to receive(:external_copy_base) { '/host1' } + elsif index == 2 + host['platform'] = Beaker::Platform.new('osx-5-x4') + allow(host).to receive(:external_copy_base) { '/host2' } + elsif index == 3 + host['platform'] = Beaker::Platform.new('eos-5-x4') + allow(host).to receive(:external_copy_base) { '/host3' } + end + allow(host).to receive(:puppet_agent_dev_package_info).with(any_args).and_return(['test', '/blah']) + end + + expect(subject).to receive(:add_role).with(any_args).exactly(mhosts.length).times + + expect(subject).to receive(:fetch_http_file).with(any_args).exactly(3).times + expect(subject).to receive(:scp_to).with(any_args).exactly(3).times + + expect(subject).to receive(:install_msi_on).with(mhosts[1], 'xyz', {}, anything).exactly(1).times + expect(mhosts[0]).to receive(:solaris_install_local_package).with('/blah', '/tmp').exactly(1).times + expect(mhosts[2]).to receive(:install_package).with(any_args).exactly(1).times + expect(mhosts[3]).to receive(:install_from_file).with('/blah').exactly(1).times + expect(mhosts[0]).to receive(:external_copy_base).with(no_args).exactly(0).times + expect(mhosts[1]).to receive(:external_copy_base).with(no_args).exactly(0).times + expect(mhosts[2]).to receive(:external_copy_base).with(no_args).exactly(0).times + expect(mhosts[3]).to receive(:external_copy_base).with(no_args).exactly(0).times + + result = object_double(Beaker::Result.new({}, 'foo'), raw_output: 'xyz') + allow(subject).to receive(:on).with(mhosts[1], anything).and_return(result) + + expect(subject).to receive(:configure_type_defaults_on).with(any_args).exactly(mhosts.length).times + + subject.install_puppet_agent_dev_repo_on(mhosts, + opts.merge({ puppet_agent_version: '1.0.0', copy_dir_external: '/tmp' })) + end + end + describe '#install_puppetserver_on' do let(:host) { make_host('master', platform: 'el-7-x86_64') } @@ -1240,4 +1543,81 @@ def stub_uninteresting_portions_of_install_puppetlabs_dev_repo! expect { subject.remove_puppet_on(debian6) }.to raise_error(RuntimeError, /unsupported platform/) end end + + describe '#puppet_agent_dev_package_info' do + let(:download_opts) {{download_url: 'http://trust.me'}} + + # These platforms are consistent across puppet collections + shared_examples 'consistent platforms' do |puppet_collection, puppet_agent_version| + platforms = { 'solaris-10-x86_64' => ["solaris/10/#{puppet_collection}", "puppet-agent-#{puppet_agent_version}-1.i386.pkg.gz"], + 'solaris-11-x86_64' => ["solaris/11/#{puppet_collection}", "puppet-agent@#{puppet_agent_version},5.11-1.i386.p5p"], + 'sles-11-x86_64' => ["sles/11/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.sles11.x86_64.rpm"], + 'opensuse-15-x86_64' => ["sles/15/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.sles15.x86_64.rpm"], + 'aix-6.1-power' => ["aix/6.1/#{puppet_collection}/ppc", "puppet-agent-#{puppet_agent_version}-1.aix6.1.ppc.rpm"], + 'el-7-x86_64' => ["el/7/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el7.x86_64.rpm"], + 'centos-7-x86_64' => ["el/7/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el7.x86_64.rpm"], + 'oracle-7-x86_64' => ["el/7/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el7.x86_64.rpm"], + 'redhat-7-x86_64' => ["el/7/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el7.x86_64.rpm"], + 'scientific-7-x86_64' => ["el/7/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el7.x86_64.rpm"], + 'el-8-x86_64' => ["el/8/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el8.x86_64.rpm"], + 'centos-8-x86_64' => ["el/8/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el8.x86_64.rpm"], + 'oracle-8-x86_64' => ["el/8/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el8.x86_64.rpm"], + 'redhat-8-x86_64' => ["el/8/#{puppet_collection}/x86_64", "puppet-agent-#{puppet_agent_version}-1.el8.x86_64.rpm"], + } + platforms.each do |p, v| + it "accomodates platform #{p} without erroring" do + @opts = {'platform' => Beaker::Platform.new(p)} + allow( instance ).to receive(:link_exists?).and_return(true) + expect( instance.puppet_agent_dev_package_info(puppet_collection, puppet_agent_version, download_opts) ).to eq(v) + end + end + end + + # AIX platform/package pairs differ accross collections + shared_examples 'aix platform' do |package_version, platform_version, puppet_collection, puppet_agent_version| + it "selects AIX #{package_version} packages for AIX #{platform_version}" do + @opts = { 'platform' => Beaker::Platform.new("aix-#{platform_version}-power") } + allow( instance ).to receive(:link_exists?).and_return(true) + expect( instance.puppet_agent_dev_package_info(puppet_collection, puppet_agent_version, download_opts) ) + .to eq(["aix/#{package_version}/#{puppet_collection}/ppc", "puppet-agent-#{puppet_agent_version}-1.aix#{package_version}.ppc.rpm"]) + end + end + + context 'with puppet-agent 1.y.z' do + puppet_collection = 'PC1' + puppet_agent_version = '1.2.3' + + include_examples 'consistent platforms', puppet_collection, puppet_agent_version + include_examples 'aix platform', '5.3', '5.3', puppet_collection, puppet_agent_version + include_examples 'aix platform', '7.1', '7.1', puppet_collection, puppet_agent_version + include_examples 'aix platform', '7.1', '7.2', puppet_collection, puppet_agent_version + end + + context 'with puppet-agent 5.y.z' do + puppet_collection = 'puppet5' + puppet_agent_version = '5.4.3' + + include_examples 'consistent platforms', puppet_collection, puppet_agent_version + include_examples 'aix platform', '7.1', '7.1', puppet_collection, puppet_agent_version + include_examples 'aix platform', '7.1', '7.2', puppet_collection, puppet_agent_version + end + + context 'with puppet-agent 5.99.z' do + puppet_collection = 'puppet6' + puppet_agent_version = '5.99.0' + + include_examples 'consistent platforms', puppet_collection, puppet_agent_version + include_examples 'aix platform', '6.1', '7.1', puppet_collection, puppet_agent_version + include_examples 'aix platform', '6.1', '7.2', puppet_collection, puppet_agent_version + end + + context 'with puppet6' do + puppet_collection = 'puppet6' + puppet_agent_version = '6.6.6' + + include_examples 'consistent platforms', puppet_collection, puppet_agent_version + include_examples 'aix platform', '6.1', '7.1', puppet_collection, puppet_agent_version + include_examples 'aix platform', '6.1', '7.2', puppet_collection, puppet_agent_version + end + end end