Skip to content

Commit

Permalink
(maint) Make spec tests pass on windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tvpartytonight committed Aug 31, 2023
1 parent 7935c79 commit 253c32f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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'])
Expand Down

0 comments on commit 253c32f

Please sign in to comment.