diff --git a/manifests/osfamily/aix.pp b/manifests/osfamily/aix.pp index 253fbc04c..32c6044a1 100644 --- a/manifests/osfamily/aix.pp +++ b/manifests/osfamily/aix.pp @@ -44,7 +44,11 @@ $aix_ver_number = '6.1' } } - $source = "puppet:///pe_packages/${pe_server_version}/aix-${aix_ver_number}-power/${::puppet_agent::package_name}-${::puppet_agent::package_version}-1.aix${aix_ver_number}.ppc.rpm" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "puppet:///pe_packages/${pe_server_version}/aix-${aix_ver_number}-power/${::puppet_agent::package_name}-${::puppet_agent::package_version}-1.aix${aix_ver_number}.ppc.rpm" + } class { '::puppet_agent::prepare::package': source => $source, diff --git a/manifests/osfamily/darwin.pp b/manifests/osfamily/darwin.pp index 9353843fa..801c644d7 100644 --- a/manifests/osfamily/darwin.pp +++ b/manifests/osfamily/darwin.pp @@ -1,7 +1,9 @@ class puppet_agent::osfamily::darwin{ assert_private() - if $::puppet_agent::is_pe { + if $::puppet_agent::source { + $source = $::puppet_agent::source + } elsif $::puppet_agent::is_pe { $pe_server_version = pe_build_version() $source = "puppet:///pe_packages/${pe_server_version}/${::platform_tag}/${puppet_agent::package_name}-${puppet_agent::package_version}-1.osx${$::macosx_productversion_major}.dmg" } else { diff --git a/manifests/osfamily/debian.pp b/manifests/osfamily/debian.pp index 400b02a36..dabba7930 100644 --- a/manifests/osfamily/debian.pp +++ b/manifests/osfamily/debian.pp @@ -7,7 +7,11 @@ if getvar('::puppet_agent::is_pe') == true { $pe_server_version = pe_build_version() - $source = "https://${::servername}:8140/packages/${pe_server_version}/${::platform_tag}" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "https://${::servername}:8140/packages/${pe_server_version}/${::platform_tag}" + } # In Puppet Enterprise, agent packages are served by the same server # as the master, which can be using either a self signed CA, or an external CA. # In order for apt to authenticate to the repo on the PE Master, it will need @@ -55,7 +59,11 @@ content => '', } } else { - $source = 'https://apt.puppet.com' + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = 'https://apt.puppet.com' + } } $legacy_keyname = 'GPG-KEY-puppetlabs' diff --git a/manifests/osfamily/redhat.pp b/manifests/osfamily/redhat.pp index 14dae844a..b71881947 100644 --- a/manifests/osfamily/redhat.pp +++ b/manifests/osfamily/redhat.pp @@ -8,7 +8,11 @@ true => "el-6-${::architecture}", default => $::platform_tag, } - $source = "https://${::servername}:8140/packages/${pe_server_version}/${pe_repo_dir}" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "https://${::servername}:8140/packages/${pe_server_version}/${pe_repo_dir}" + } # In Puppet Enterprise, agent packages are served by the same server # as the master, which can be using either a self signed CA, or an external CA. # In order for yum to authenticate to the yumrepo on the PE Master, it will need @@ -39,7 +43,11 @@ $platform_and_version = "el/${::operatingsystemmajrelease}" } } - $source = "http://yum.puppet.com/${::puppet_agent::collection}/${platform_and_version}/${::puppet_agent::arch}" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "http://yum.puppet.com/${::puppet_agent::collection}/${platform_and_version}/${::puppet_agent::arch}" + } $_sslcacert_path = undef $_sslclientcert_path = undef $_sslclientkey_path = undef diff --git a/manifests/osfamily/solaris.pp b/manifests/osfamily/solaris.pp index f60d44993..cc7f0cd8d 100644 --- a/manifests/osfamily/solaris.pp +++ b/manifests/osfamily/solaris.pp @@ -18,7 +18,11 @@ case $::operatingsystemmajrelease { '10': { $package_file_name = "${::puppet_agent::package_name}-${::puppet_agent::prepare::package_version}-1.${pkg_arch}.pkg.gz" - $source = "puppet:///pe_packages/${pe_server_version}/${::platform_tag}/${package_file_name}" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "puppet:///pe_packages/${pe_server_version}/${::platform_tag}/${package_file_name}" + } class { '::puppet_agent::prepare::package': source => $source, } @@ -44,7 +48,11 @@ '11': { if $::puppet_agent::manage_repo { $package_file_name = "${::puppet_agent::package_name}@${::puppet_agent::prepare::package_version},5.11-1.${pkg_arch}.p5p" - $source = "puppet:///pe_packages/${pe_server_version}/${::platform_tag}/${package_file_name}" + if $::puppet_agent::source { + $source = $::puppet_agent::source + } else { + $source = "puppet:///pe_packages/${pe_server_version}/${::platform_tag}/${package_file_name}" + } class { '::puppet_agent::prepare::package': source => $source, } diff --git a/manifests/osfamily/suse.pp b/manifests/osfamily/suse.pp index 9fb850de4..1181c30cf 100644 --- a/manifests/osfamily/suse.pp +++ b/manifests/osfamily/suse.pp @@ -5,7 +5,9 @@ fail("${::operatingsystem} not supported") } - if $::puppet_agent::is_pe { + if $::puppet_agent::source { + $source = $::puppet_agent::source + } elsif $::puppet_agent::is_pe { $pe_server_version = pe_build_version() $source = "https://${::servername}:8140/packages/${pe_server_version}/${::platform_tag}" } else { diff --git a/manifests/osfamily/windows.pp b/manifests/osfamily/windows.pp index 537eb6cdd..aa29ed784 100644 --- a/manifests/osfamily/windows.pp +++ b/manifests/osfamily/windows.pp @@ -1,6 +1,8 @@ class puppet_agent::osfamily::windows{ assert_private() - if $::puppet_agent::is_pe { + if $::puppet_agent::source { + $source = $::puppet_agent::source + } elsif $::puppet_agent::is_pe { $pe_server_version = pe_build_version() $tag = $::puppet_agent::arch ? { 'x64' => 'windows-x86_64', diff --git a/manifests/prepare/package.pp b/manifests/prepare/package.pp index 74a519482..08aea2b3f 100644 --- a/manifests/prepare/package.pp +++ b/manifests/prepare/package.pp @@ -16,7 +16,12 @@ ensure => directory, } - $package_file_name = basename($source) + # In order for the 'basename' function to work correctly we need to change + # any \s to /s (even for windows UNC paths) so that it will correctly pull off + # the filename. Since this operation is only grabbing the base filename and not + # any part of the path this should be safe, since the source will simply remain + # what it was before and we can still pull off the filename. + $package_file_name = basename(regsubst($source, "\\\\", '/', 'G')) if $::osfamily =~ /windows/ { $local_package_file_path = windows_native_path("${::puppet_agent::params::local_packages_dir}/${package_file_name}") $mode = undef diff --git a/spec/classes/puppet_agent_osfamily_aix_spec.rb b/spec/classes/puppet_agent_osfamily_aix_spec.rb index 76e411a51..cc8edf60d 100644 --- a/spec/classes/puppet_agent_osfamily_aix_spec.rb +++ b/spec/classes/puppet_agent_osfamily_aix_spec.rb @@ -47,6 +47,30 @@ } end + context 'with a user specified source' do + let(:facts) { + common_facts.merge({ + architecture: "PowerPC_POWER8", + platform_tag: "aix-7.2-power", + }) + } + let(:params) { + { + package_version: '5.10.100.1', + collection: 'puppet5', + source: 'https://fake-source.com/aix/packages/puppet-agent-5.10.100.1-1.aix6.1.ppc.rpm', + } + } + before(:each) do + Puppet::Parser::Functions.newfunction(:pe_build_version, type: :rvalue) { |_args| '2000.0.0' } + Puppet::Parser::Functions.newfunction(:pe_compiling_server_aio_build, type: :rvalue) { |_args| '1.10.100' } + end + + it { + is_expected.to contain_file('/opt/puppetlabs/packages/puppet-agent-5.10.100.1-1.aix6.1.ppc.rpm').with_source('https://fake-source.com/aix/packages/puppet-agent-5.10.100.1-1.aix6.1.ppc.rpm') + } + end + context 'with a PC1 collection' do let(:params) { { diff --git a/spec/classes/puppet_agent_osfamily_darwin_spec.rb b/spec/classes/puppet_agent_osfamily_darwin_spec.rb index b4aeb687d..7194d0139 100644 --- a/spec/classes/puppet_agent_osfamily_darwin_spec.rb +++ b/spec/classes/puppet_agent_osfamily_darwin_spec.rb @@ -14,7 +14,6 @@ end package_version = '1.10.100' - let(:params) {{ package_version: package_version }} facts = { :is_pe => true, @@ -29,6 +28,7 @@ } describe 'supported environment' do + let(:params) {{ package_version: package_version }} context "when running a supported OSX" do ["osx-10.12-x86_64", "osx-10.13-x86_64", "osx-10.14-x86_64"].each do |tag| context "on #{tag} with no aio_version" do @@ -66,4 +66,23 @@ end end end + + describe 'when using a user defined source' do + let(:params) { + { + package_version: '5.10.100.1', + collection: 'puppet5', + source: 'https://fake-source.com/aix/packages/puppet-agent-5.10.100.1-1.osx10.13.dmg', + } + } + let(:facts) do + facts.merge({ + :is_pe => true, + :aio_agent_version => '1.10.99', + :platform_tag => 'osx-10.13-x86_64', + :macosx_productversion_major => '10.13' + }) + end + it { is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-5.10.100.1-1.osx10.13.dmg").with_source('https://fake-source.com/aix/packages/puppet-agent-5.10.100.1-1.osx10.13.dmg') } + end end diff --git a/spec/classes/puppet_agent_osfamily_debian_spec.rb b/spec/classes/puppet_agent_osfamily_debian_spec.rb index dbd06cb5b..6014f42c9 100644 --- a/spec/classes/puppet_agent_osfamily_debian_spec.rb +++ b/spec/classes/puppet_agent_osfamily_debian_spec.rb @@ -188,6 +188,25 @@ }) } end + context "when managing PE apt repo settings and using a custom source" do + let(:params) { + { + :manage_repo => true, + :package_version => package_version, + :source => 'https://fake-apt-mirror.com/packages/debian-7-x86_64' + } + } + + it { is_expected.to contain_apt__source('pc_repo').with({ + 'location' => 'https://fake-apt-mirror.com/packages/debian-7-x86_64', + 'repos' => 'PC1', + 'key' => { + 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', + 'source' => '/etc/pki/deb-gpg/GPG-KEY-puppet', + }, + }) } + end + context "when not managing PE apt repo settings" do let(:params) { { @@ -234,6 +253,26 @@ }) } end + context "when managing FOSS apt repo and using a custom source" do + let(:params) { + { + :manage_repo => true, + :package_version => package_version, + :collection => 'puppet5', + :source => 'https://fake-apt-mirror.com/packages/debian-7-x86_64' + } + } + + it { is_expected.to contain_apt__source('pc_repo').with({ + 'location' => 'https://fake-apt-mirror.com/packages/debian-7-x86_64', + 'repos' => 'puppet5', + 'key' => { + 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', + 'source' => '/etc/pki/deb-gpg/GPG-KEY-puppet', + }, + }) } + end + context "when not managing FOSS apt repo" do let(:params) { { diff --git a/spec/classes/puppet_agent_osfamily_redhat_spec.rb b/spec/classes/puppet_agent_osfamily_redhat_spec.rb index 61091b71a..185a9eb0a 100644 --- a/spec/classes/puppet_agent_osfamily_redhat_spec.rb +++ b/spec/classes/puppet_agent_osfamily_redhat_spec.rb @@ -117,6 +117,17 @@ 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs\n file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppet", }) } end + + context 'when using a custom source' do + let(:params) { + { + :package_version => '5.2.0', + :collection => 'puppet5', + :source => "http://fake-yum.com/#{urlbit.gsub('/f','/')}/x64" + } + } + it { is_expected.to contain_yumrepo('pc_repo').with_baseurl("http://fake-yum.com/#{urlbit.gsub('/f','/')}/x64") } + end end end @@ -143,6 +154,18 @@ ) end + context 'when using a custom source' do + let(:params) { + { + :package_version => '5.2.0', + :manage_repo => true, + :source => "http://fake-yum.com/#{repodir}/x64" + } + } + it { is_expected.to contain_yumrepo('pc_repo').with_baseurl("http://fake-yum.com/#{repodir}/x64") } + end + + context 'with manage_repo enabled' do let(:params) { { diff --git a/spec/classes/puppet_agent_osfamily_solaris_spec.rb b/spec/classes/puppet_agent_osfamily_solaris_spec.rb index bcb2110a3..17de47cf6 100644 --- a/spec/classes/puppet_agent_osfamily_solaris_spec.rb +++ b/spec/classes/puppet_agent_osfamily_solaris_spec.rb @@ -57,6 +57,28 @@ pkg.stubs(:defaultprovider).returns(pkg.provider(:pkg)) end + context "when Solaris 11 i386 and a custom source" do + let(:facts) do + facts.merge({ + :is_pe => true, + :platform_tag => "solaris-11-i386", + :operatingsystemmajrelease => '11', + }) + end + let(:params) do + { + :package_version => package_version, + :source => "http://fake-solaris-source.com/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p" + } + end + it do + is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p").with({ + 'ensure' => 'present', + 'source' => "http://fake-solaris-source.com/packages/puppet-agent@#{sol11_package_version},5.11-1.i386.p5p", + }) + end + end + context "when Solaris 11 i386" do let(:facts) do facts.merge({ @@ -176,6 +198,28 @@ end end + context "when Solaris 10 i386 and a custom source" do + let(:facts) do + facts.merge({ + :is_pe => true, + :platform_tag => "solaris-10-i386", + :operatingsystemmajrelease => '10', + }) + end + let(:params) do + { + :package_version => package_version, + :source => "http://fake-solaris-source.com/packages/puppet-agent-#{package_version}-1.i386.pkg.gz" + } + end + it do + is_expected.to contain_file("/opt/puppetlabs/packages/puppet-agent-#{package_version}-1.i386.pkg.gz").with({ + 'ensure' => 'present', + 'source' => "http://fake-solaris-source.com/packages/puppet-agent-#{package_version}-1.i386.pkg.gz", + }) + end + end + context "when Solaris 10 i386" do let(:facts) do facts.merge({ diff --git a/spec/classes/puppet_agent_osfamily_suse_spec.rb b/spec/classes/puppet_agent_osfamily_suse_spec.rb index 3ce640c20..43302b05b 100644 --- a/spec/classes/puppet_agent_osfamily_suse_spec.rb +++ b/spec/classes/puppet_agent_osfamily_suse_spec.rb @@ -144,6 +144,22 @@ end end + context "with manage_repo enabled and custom source" do + let(:params) { + { + :manage_repo => true, + :package_version => package_version, + :source => "https://fake-sles-source.com/packages/sles-#{os_version}-x86_64", + } + } + it { is_expected.to contain_ini_setting("zypper pc_repo baseurl").with({ + 'path' => '/etc/zypp/repos.d/pc_repo.repo', + 'section' => 'pc_repo', + 'setting' => 'baseurl', + 'value' => "https://fake-sles-source.com/packages/sles-#{os_version}-x86_64?ssl_verify=no", + }) } + end + it do is_expected.to contain_package('puppet-agent') end diff --git a/spec/classes/puppet_agent_windows_install_spec.rb b/spec/classes/puppet_agent_windows_install_spec.rb index 7ea20e44b..48179ef31 100644 --- a/spec/classes/puppet_agent_windows_install_spec.rb +++ b/spec/classes/puppet_agent_windows_install_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' RSpec.describe 'puppet_agent', tag: 'win' do - package_version = '1.10.100.1' + package_version = '5.10.100.1' + collection = 'puppet5' global_params = { :package_version => package_version, + :collection => collection } - - ['x86', 'x64'].each do |arch| context "Windows arch #{arch}" do facts = { @@ -96,34 +96,37 @@ end context 'source =>' do - describe 'https://alterernate.com/puppet-agent.msi' do + describe 'https://alterernate.com/puppet-agent-999.1-x64.msi' do let(:params) { global_params.merge( - {:source => 'https://alternate.com/puppet-agent.msi',}) + {:source => 'https://alternate.com/puppet-agent-999.1-x64.msi',}) } it { - is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi'/) + is_expected.to contain_file('C:\ProgramData\Puppetlabs\packages\puppet-agent-999.1-x64.msi').with_source('https://alternate.com/puppet-agent-999.1-x64.msi') + is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-999.1-x64\.msi'/) is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Logfile 'C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/) } it { is_expected.to contain_exec('fix inheritable SYSTEM perms') } end - describe 'C:/tmp/puppet-agent-x64.msi' do + describe 'C:/tmp/puppet-agent-999.2-x64.msi' do let(:params) { global_params.merge( - {:source => 'C:/tmp/puppet-agent-x64.msi',}) + {:source => 'C:/tmp/puppet-agent-999.2-x64.msi',}) } it { - is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi'/) + is_expected.to contain_file('C:\ProgramData\Puppetlabs\packages\puppet-agent-999.2-x64.msi').with_source('C:/tmp/puppet-agent-999.2-x64.msi') + is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-999.2-x64\.msi'/) is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Logfile 'C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/) } it { is_expected.to contain_exec('fix inheritable SYSTEM perms') } end - describe '\\\\garded\c$\puppet-agent-x64.msi' do + describe '\\\\garded\c$\puppet-agent-999.3-x64.msi' do let(:params) { global_params.merge( - {:source => "\\\\garded\\c$\\puppet-agent-x64.msi",}) + {:source => "\\\\garded\\c$\\puppet-agent-999.3-x64.msi",}) } it { - is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi'/) + is_expected.to contain_file('C:\ProgramData\Puppetlabs\packages\puppet-agent-999.3-x64.msi').with_source('\\\\garded\c$\puppet-agent-999.3-x64.msi') + is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-999.3-x64\.msi'/) is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Logfile 'C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/) } it { is_expected.to contain_exec('fix inheritable SYSTEM perms') } @@ -131,26 +134,20 @@ describe 'default source' do it { + is_expected.to contain_file("C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi") + .with_source("https://downloads.puppet.com/windows/#{collection}/puppet-agent-#{package_version}-#{arch}.msi") is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi'/) - is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Logfile 'C:\\tmp\\puppet-\d+_\d+_\d+-\d+_\d+-installer.log'/) - } - it { - should contain_exec('install_puppet.ps1').with { { - 'command' => 'C:\windows\sysnative\cmd.exe /c start /b C:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -NoLogo -NonInteractive -Command C:\tmp\install_puppet.ps1 42', - } } - } - it { - is_expected.to_not contain_file('C:\tmp\puppet-agent.msi') } it { is_expected.to contain_exec('fix inheritable SYSTEM perms') } end - describe 'puppet:///puppet_agent/puppet-agent-1.1.0-x86.msi' do + describe 'puppet:///puppet_agent/puppet-agent-999.4-x86.msi' do let(:params) { global_params.merge( - {:source => 'puppet:///puppet_agent/puppet-agent-1.1.0-x86.msi'}) + {:source => 'puppet:///puppet_agent/puppet-agent-999.4-x86.msi'}) } it { - is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-#{package_version}-#{arch}\.msi'/) + is_expected.to contain_file('C:\ProgramData\Puppetlabs\packages\puppet-agent-999.4-x86.msi').with_source('puppet:///puppet_agent/puppet-agent-999.4-x86.msi') + is_expected.to contain_exec('install_puppet.ps1').with_command(/\-Source 'C:\\ProgramData\\Puppetlabs\\packages\\puppet-agent-999.4-x86\.msi'/) } it { is_expected.to contain_exec('fix inheritable SYSTEM perms') } end