Skip to content

Commit b2cc0eb

Browse files
committed
(PA-5826) Only read Windows VERSION file during puppet apply
Previously, puppetserver attempted to load the wrong VERSION file when managing `package_version => auto` and compiling catalogs for Windows nodes as can be seen by the new test: Evaluation Error: Error while evaluating a Function Call, Could not find any files from C:\Program Files\Puppet Labs\Puppet\VERSION (file: path/to/init.pp, line: 170, column: 42) This adds a `puppet_runmode` fact. When running as puppet agent, the run mode will be `agent`. When running as puppet apply, it will be `user`. If it's the latter and we're a Windows host, then look for the VERSION file locally. Since the default class parameter is no longer dependent on the agent fact, I regenerated the reference using rake strings:generate:reference
1 parent 560c1e8 commit b2cc0eb

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

REFERENCE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ Default value: `undef`
349349

350350
##### <a name="-puppet_agent--version_file_path"></a>`version_file_path`
351351

352-
Data type: `String`
352+
Data type: `Stdlib::Absolutepath`
353353

354354
The default install path for the VERSION file
355355

356-
Default value: `$facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION'`
356+
Default value: `'/opt/puppetlabs/puppet/VERSION'`
357357

358358
##### <a name="-puppet_agent--skip_if_unavailable"></a>`skip_if_unavailable`
359359

lib/facter/puppet_runmode.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Facter.add(:puppet_runmode) do
2+
setcode { Puppet.run_mode.name.to_s }
3+
end

manifests/init.pp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
Optional $wait_for_pxp_agent_exit = undef,
132132
Optional $wait_for_puppet_run = undef,
133133
Array[Puppet_agent::Config] $config = [],
134-
String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' }
134+
Stdlib::Absolutepath $version_file_path = '/opt/puppetlabs/puppet/VERSION'
135135
) inherits puppet_agent::params {
136136
# The configure class uses $puppet_agent::config to manage settings in
137137
# puppet.conf, and will always be present. It does not require management of
@@ -167,7 +167,11 @@
167167
# The AIO package version and Puppet version can, on rare occasion, diverge.
168168
# This logic checks for the AIO version of the server, since that's what the package manager cares about.
169169
if $package_version == 'auto' {
170-
$master_or_package_version = chomp(file($version_file_path))
170+
if $facts['os']['family'] == 'windows' and $facts['puppet_runmode'] == 'user' {
171+
$master_or_package_version = chomp(file("${facts['env_windows_installdir']}\\VERSION"))
172+
} else {
173+
$master_or_package_version = chomp(file($version_file_path))
174+
}
171175
} else {
172176
$master_or_package_version = $package_version
173177
}

spec/classes/puppet_agent_osfamily_redhat_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,37 @@
274274
it { is_expected.to contain_package('puppet-agent').with_ensure(params[:package_version].to_s) }
275275
end
276276

277+
context 'with auto package version' do
278+
let(:params) do
279+
{
280+
manage_repo: false,
281+
package_version: 'auto'
282+
}
283+
end
284+
285+
context 'with Windows agent' do
286+
let(:facts) do
287+
override_facts(
288+
super(),
289+
os: { family: 'windows', 'windows' => { 'system32' => 'C:\Windows\System32' } },
290+
'env_windows_installdir' => 'C:\Program Files\Puppet Labs\Puppet',
291+
'puppet_agent_appdata' => 'C:\ProgramData',
292+
'puppet_confdir' => 'C:\ProgramData\PuppetLabs\puppet',
293+
'puppet_runmode' => 'agent',
294+
)
295+
end
296+
297+
before :each do
298+
allow(Puppet::FileSystem).to receive(:exist?).and_call_original
299+
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).and_call_original
300+
allow(Puppet::FileSystem).to receive(:exist?).with('/opt/puppetlabs/puppet/VERSION').and_return true
301+
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with('/opt/puppetlabs/puppet/VERSION').and_return "7.6.5\n"
302+
end
303+
304+
it { is_expected.to contain_class('puppet_agent::install::windows') }
305+
end
306+
end
307+
277308
it { is_expected.to contain_class('puppet_agent::osfamily::redhat') }
278309
end
279310

spec/classes/puppet_agent_osfamily_windows_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@
9494
'source' => "puppet:///pe_packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
9595
)
9696
}
97+
98+
describe 'when applying' do
99+
let(:facts) do
100+
override_facts(
101+
super(),
102+
puppet_runmode: 'user',
103+
)
104+
end
105+
106+
it { is_expected.to contain_file("#{appdata}\\Puppetlabs") }
107+
it { is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages") }
108+
it {
109+
is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages\\puppet-agent-#{arch}.msi").with(
110+
'source' => "puppet:///pe_packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
111+
)
112+
}
113+
end
97114
end
98115
end
99116

0 commit comments

Comments
 (0)