From 253c32f98a331f3e97ce30d818456a29fbfbdd96 Mon Sep 17 00:00:00 2001 From: tvpartytonight Date: Thu, 31 Aug 2023 10:55:43 -0700 Subject: [PATCH] (maint) Make spec tests pass on windows Windows requires the current puppet collection to be specified in the puppet_agent class, so that is refactored to be globally specified in the `spec_helper_acceptance`. Additionally, logic was added to specifiy default install paths for the VERSION file for both linux and windows. --- manifests/init.pp | 3 ++- spec/acceptance/class_spec.rb | 2 +- spec/spec_helper_acceptance.rb | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index c3a97b52..9649459f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -126,6 +126,7 @@ $wait_for_pxp_agent_exit = undef, $wait_for_puppet_run = undef, Array[Puppet_agent::Config] $config = [], + $version_file_path = $facts['os']['family'] ? { 'windows' => 'C:\Program Files\Puppet Labs\Puppet\VERSION', default => '/opt/puppetlabs/puppet/VERSION' } ) inherits ::puppet_agent::params { # The configure class uses $puppet_agent::config to manage settings in # puppet.conf, and will always be present. It does not require management of @@ -161,7 +162,7 @@ # The AIO package version and Puppet version can, on rare occasion, diverge. # This logic checks for the AIO version of the server, since that's what the package manager cares about. if $package_version == 'auto' { - $master_or_package_version = chomp(file('/opt/puppetlabs/puppet/VERSION')) + $master_or_package_version = chomp(file($version_file_path)) } else { $master_or_package_version = $package_version } diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index ebc592cb..25503ac5 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -5,7 +5,7 @@ context 'default parameters in apply' do before(:all) do setup_puppet_on default - pp = "class { 'puppet_agent': package_version => 'auto'}" + pp = "class { 'puppet_agent': package_version => 'auto', collection => #{PUPPET_COLLECTION}}" apply_manifest(pp, catch_failures: true) end after(:all) { teardown_puppet_on default } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 510abca6..73783b93 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -22,6 +22,7 @@ def stop_firewall_on(host) # Project root PROJ_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) TEST_FILES = File.expand_path(File.join(File.dirname(__FILE__), 'acceptance', 'files')) +PUPPET_COLLECTION = 'puppet7'.freeze def install_modules_on(host) install_ca_certs_on(host) @@ -37,7 +38,7 @@ def install_modules_on(host) master['puppetservice'] = 'puppetserver' master['puppetserver-confdir'] = '/etc/puppetlabs/puppetserver/conf.d' master['type'] = 'aio' - install_puppet_agent_on master, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: 'puppet7' } + install_puppet_agent_on master, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: PUPPET_COLLECTION } install_modules_on master stop_firewall_on master end @@ -71,7 +72,7 @@ def setup_puppet_on(host, opts = {}) puts "Setup aio puppet on #{host}" configure_type_defaults_on host - install_puppet_agent_on host, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: 'puppet7' } + install_puppet_agent_on host, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: PUPPET_COLLECTION } puppet_opts = agent_opts(master.to_s) if %r{windows}i.match?(host['platform'])