Skip to content

(PA-5826) Only read Windows VERSION file during puppet apply #677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ Default value: `undef`

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

Data type: `String`
Data type: `Stdlib::Absolutepath`

The default install path for the VERSION file

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

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

Expand Down
3 changes: 3 additions & 0 deletions lib/facter/puppet_runmode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Facter.add(:puppet_runmode) do
setcode { Puppet.run_mode.name.to_s }
end
8 changes: 6 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
Optional $wait_for_pxp_agent_exit = undef,
Optional $wait_for_puppet_run = undef,
Array[Puppet_agent::Config] $config = [],
String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' }
Stdlib::Absolutepath $version_file_path = '/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 @@ -167,7 +167,11 @@
# 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($version_file_path))
if $facts['os']['family'] == 'windows' and $facts['puppet_runmode'] == 'user' {
$master_or_package_version = chomp(file("${facts['env_windows_installdir']}\\VERSION"))
} else {
$master_or_package_version = chomp(file($version_file_path))
}
} else {
$master_or_package_version = $package_version
}
Expand Down
31 changes: 31 additions & 0 deletions spec/classes/puppet_agent_osfamily_redhat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,37 @@
it { is_expected.to contain_package('puppet-agent').with_ensure(params[:package_version].to_s) }
end

context 'with auto package version' do
let(:params) do
{
manage_repo: false,
package_version: 'auto'
}
end

context 'with Windows agent' do
let(:facts) do
override_facts(
super(),
os: { family: 'windows', 'windows' => { 'system32' => 'C:\Windows\System32' } },
'env_windows_installdir' => 'C:\Program Files\Puppet Labs\Puppet',
'puppet_agent_appdata' => 'C:\ProgramData',
'puppet_confdir' => 'C:\ProgramData\PuppetLabs\puppet',
'puppet_runmode' => 'agent',
)
end

before :each do
allow(Puppet::FileSystem).to receive(:exist?).and_call_original
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).and_call_original
allow(Puppet::FileSystem).to receive(:exist?).with('/opt/puppetlabs/puppet/VERSION').and_return true
allow(Puppet::FileSystem).to receive(:read_preserve_line_endings).with('/opt/puppetlabs/puppet/VERSION').and_return "7.6.5\n"
end

it { is_expected.to contain_class('puppet_agent::install::windows') }
end
end

it { is_expected.to contain_class('puppet_agent::osfamily::redhat') }
end

Expand Down
17 changes: 17 additions & 0 deletions spec/classes/puppet_agent_osfamily_windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@
'source' => "puppet:///pe_packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
)
}

describe 'when applying' do
let(:facts) do
override_facts(
super(),
puppet_runmode: 'user',
)
end

it { is_expected.to contain_file("#{appdata}\\Puppetlabs") }
it { is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages") }
it {
is_expected.to contain_file("#{appdata}\\Puppetlabs\\packages\\puppet-agent-#{arch}.msi").with(
'source' => "puppet:///pe_packages/#{pe_version}/windows-#{tag}/puppet-agent-#{arch}.msi",
)
}
end
end
end

Expand Down