Skip to content

Commit e80c795

Browse files
authored
Merge pull request #665 from tvpartytonight/make_acceptance_work_on_windows
(maint) Make spec tests pass on windows
2 parents 04bee65 + 58901da commit e80c795

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

manifests/init.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
$wait_for_pxp_agent_exit = undef,
127127
$wait_for_puppet_run = undef,
128128
Array[Puppet_agent::Config] $config = [],
129+
$version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' }
129130
) inherits ::puppet_agent::params {
130131
# The configure class uses $puppet_agent::config to manage settings in
131132
# puppet.conf, and will always be present. It does not require management of
@@ -161,7 +162,7 @@
161162
# The AIO package version and Puppet version can, on rare occasion, diverge.
162163
# This logic checks for the AIO version of the server, since that's what the package manager cares about.
163164
if $package_version == 'auto' {
164-
$master_or_package_version = chomp(file('/opt/puppetlabs/puppet/VERSION'))
165+
$master_or_package_version = chomp(file($version_file_path))
165166
} else {
166167
$master_or_package_version = $package_version
167168
}

spec/acceptance/class_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
context 'default parameters in apply' do
66
before(:all) do
77
setup_puppet_on default
8-
pp = "class { 'puppet_agent': package_version => 'auto'}"
8+
pp = "class { 'puppet_agent': package_version => 'auto', collection => #{PUPPET_COLLECTION}}"
99
apply_manifest(pp, catch_failures: true)
1010
end
1111
after(:all) { teardown_puppet_on default }

spec/classes/puppet_agent_osfamily_windows_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
let(:params) { { package_version: package_version } }
88
let(:version_file) { '/opt/puppetlabs/puppet/VERSION' }
9+
let(:windows_version_file) { 'C:\Program Files\Puppet Labs\Puppet\VERSION' }
910

1011
before(:each) do
1112
# Need to mock the PE functions
@@ -15,10 +16,13 @@
1516

1617
allow(Puppet::Util).to receive(:absolute_path?).and_call_original
1718
allow(Puppet::Util).to receive(:absolute_path?).with(version_file).and_return true
19+
allow(Puppet::Util).to receive(:absolute_path?).with(windows_version_file).and_return true
1820
allow(Puppet::FileSystem).to receive(:exist?).and_call_original
1921
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).and_call_original
2022
allow(Puppet::FileSystem).to receive(:exist?).with(version_file).and_return true
23+
allow(Puppet::FileSystem).to receive(:exist?).with(windows_version_file).and_return true
2124
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with(version_file).and_return "1.10.100\n"
25+
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with(windows_version_file).and_return "1.10.100\n"
2226
end
2327

2428
[['x64', 'x86_64'], ['x86', 'i386']].each do |arch, tag|
@@ -65,6 +69,7 @@
6569
aio_agent_version: '1.0.0',
6670
clientcert: 'foo.example.vm',
6771
env_temp_variable: 'C:/tmp',
72+
env_windows_installdir: windows_version_file.chomp('\VERSION'),
6873
is_pe: true,
6974
os: {
7075
architecture: arch,
@@ -104,6 +109,7 @@
104109
clientcert: 'foo.example.vm',
105110
env_temp_variable: 'C:/tmp',
106111
is_pe: true,
112+
env_windows_installdir: windows_version_file.chomp('\VERSION'),
107113
fips_enabled: true,
108114
os: {
109115
architecture: arch,

spec/spec_helper_acceptance.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def stop_firewall_on(host)
2222
# Project root
2323
PROJ_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
2424
TEST_FILES = File.expand_path(File.join(File.dirname(__FILE__), 'acceptance', 'files'))
25+
PUPPET_COLLECTION = 'puppet7'.freeze
2526

2627
def install_modules_on(host)
2728
install_ca_certs_on(host)
@@ -37,7 +38,7 @@ def install_modules_on(host)
3738
master['puppetservice'] = 'puppetserver'
3839
master['puppetserver-confdir'] = '/etc/puppetlabs/puppetserver/conf.d'
3940
master['type'] = 'aio'
40-
install_puppet_agent_on master, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: 'puppet7' }
41+
install_puppet_agent_on master, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: PUPPET_COLLECTION }
4142
install_modules_on master
4243
stop_firewall_on master
4344
end
@@ -71,7 +72,7 @@ def setup_puppet_on(host, opts = {})
7172

7273
puts "Setup aio puppet on #{host}"
7374
configure_type_defaults_on host
74-
install_puppet_agent_on host, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: 'puppet7' }
75+
install_puppet_agent_on host, { version: ENV['PUPPET_CLIENT_VERSION'] || '7.23.0', puppet_collection: PUPPET_COLLECTION }
7576

7677
puppet_opts = agent_opts(master.to_s)
7778
if %r{windows}i.match?(host['platform'])

0 commit comments

Comments
 (0)