From 762f688ac0c20b860f39d0cda35d30d69fd6e51d Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 6 Jan 2025 13:46:41 +0100 Subject: [PATCH 1/4] Shorten the conditionals in apt::source Rather than writing: type($release, 'generalized') !~ Type[Array] This uses: $release !~ Array Which is equal, but shorter. It also refactors some conditionals merge some branches which results in shorter code and arguably easier to read. --- manifests/source.pp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/manifests/source.pp b/manifests/source.pp index 70191993f7..5082a89f21 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -288,11 +288,10 @@ fail('cannot create a source entry without specifying a location') } } - if (type($location, 'generalized') !~ Type[Array]) { + if $location !~ Array { warning('For deb822 sources, location must be specified as an array.') $_location = [$location] - } - else { + } else { $_location = $location } @@ -302,30 +301,23 @@ } else { fail('os.distro.codename fact not available: release parameter required') } + } elsif $release !~ Array { + warning("For deb822 sources, 'release' must be specified as an array. Converting to array.") + $_release = [$release] } else { - if (type($release, 'generalized') !~ Type[Array]) { - warning("For deb822 sources, 'release' must be specified as an array. Converting to array.") - $_release = [$release] - } else { - $_release = $release - } + $_release = $release } - if (type($repos, 'generalized') !~ Type[Array]) { + if $repos !~ Array { warning("For deb822 sources, 'repos' must be specified as an array. Converting to array.") $_repos = split($repos, /\s+/) } else { $_repos = $repos } - if $architecture != undef { - if (type($architecture, 'generalized') !~ Type[Array]) { - warning("For deb822 sources, 'architecture' must be specified as an array. Converting to array.") - $_architecture = split($architecture, '[,]') - } - else { - $_architecture = $architecture - } + if $architecture and $architecture !~ Array { + warning("For deb822 sources, 'architecture' must be specified as an array. Converting to array.") + $_architecture = split($architecture, '[,]') } else { $_architecture = $architecture } From 00c401c4523632369b04078792ff88f0a9c8a9a6 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 6 Jan 2025 16:39:04 +0100 Subject: [PATCH 2/4] Handle repos passed as an array for list format In 9876c31aff7e738c9d533c556192591f991aa4af the parameter repos was changed to no longer allow an empty string. It does allow an array, but that isn't specifically handled for the list format. Fixes: 9876c31aff7e ("Add support for deb822 APT sources (#1167)") --- manifests/source.pp | 2 ++ spec/defines/source_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/manifests/source.pp b/manifests/source.pp index 5082a89f21..8ad30aa7b8 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -139,6 +139,8 @@ if $release =~ Pattern[/\/$/] { $_components = $_release + } elsif $repos =~ Array { + $_components = join([$_release] + $repos, ' ') } else { $_components = "${_release} ${repos}" } diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 9c619439c0..450b850f47 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -36,6 +36,24 @@ it { expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main\n}) } + + context 'with repos' do + context 'as empty array' do + let(:params) { super().merge(repos: []) } + + it { + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy\n}) + } + end + + context 'as non-empty array' do + let(:params) { super().merge(repos: ['main', 'non-free', 'contrib']) } + + it { + expect(subject).to contain_apt__setting('list-my_source').with(ensure: 'present').without_content(%r{# my_source\ndeb-src hello.there wheezy main non-free contrib\n}) + } + end + end end end From a2a872dda6435c1895ea9a12d02a96824a38b5f0 Mon Sep 17 00:00:00 2001 From: Amit Karsale Date: Thu, 16 Jan 2025 23:14:48 +0530 Subject: [PATCH 3/4] (CAT-2134) Removing legacy facts --- hiera.yaml | 4 ++-- lib/facter/apt_reboot_required.rb | 2 +- lib/facter/apt_sources.rb | 2 +- lib/facter/apt_update_last_success.rb | 2 +- lib/facter/apt_updates.rb | 4 ++-- lib/puppet/provider/apt_key/apt_key.rb | 4 ++-- spec/unit/facter/apt_dist_has_updates_spec.rb | 6 +++--- spec/unit/facter/apt_dist_package_security_updates_spec.rb | 2 +- spec/unit/facter/apt_dist_package_updates_spec.rb | 2 +- spec/unit/facter/apt_dist_security_updates_spec.rb | 2 +- spec/unit/facter/apt_dist_updates_spec.rb | 2 +- spec/unit/facter/apt_has_updates_spec.rb | 6 +++--- spec/unit/facter/apt_package_security_updates_spec.rb | 2 +- spec/unit/facter/apt_package_updates_spec.rb | 2 +- spec/unit/facter/apt_reboot_required_spec.rb | 4 ++-- spec/unit/facter/apt_security_updates_spec.rb | 2 +- spec/unit/facter/apt_update_last_success_spec.rb | 4 ++-- spec/unit/facter/apt_updates_spec.rb | 2 +- 18 files changed, 27 insertions(+), 27 deletions(-) diff --git a/hiera.yaml b/hiera.yaml index 545fff3272..72369de4ba 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -6,14 +6,14 @@ defaults: # Used for any hierarchy level that omits these keys. data_hash: yaml_data # Use the built-in YAML backend. hierarchy: - - name: "osfamily/major release" + - name: "os.family/major release" paths: # Used to distinguish between Debian and Ubuntu - "os/%{facts.os.name}/%{facts.os.release.major}.yaml" - "os/%{facts.os.family}/%{facts.os.release.major}.yaml" # Used for Solaris - "os/%{facts.os.family}/%{facts.kernelrelease}.yaml" - - name: "osfamily" + - name: "os.family" paths: - "os/%{facts.os.name}.yaml" - "os/%{facts.os.family}.yaml" diff --git a/lib/facter/apt_reboot_required.rb b/lib/facter/apt_reboot_required.rb index 7656f705aa..27239b302b 100644 --- a/lib/facter/apt_reboot_required.rb +++ b/lib/facter/apt_reboot_required.rb @@ -2,7 +2,7 @@ # apt_reboot_required.rb Facter.add(:apt_reboot_required) do - confine osfamily: 'Debian' + confine 'os.family': 'Debian' setcode do File.file?('/var/run/reboot-required') end diff --git a/lib/facter/apt_sources.rb b/lib/facter/apt_sources.rb index 17c5d089e8..4afa1c6967 100644 --- a/lib/facter/apt_sources.rb +++ b/lib/facter/apt_sources.rb @@ -2,7 +2,7 @@ # This fact lists the .list filenames that are used by apt. Facter.add(:apt_sources) do - confine osfamily: 'Debian' + confine 'os.family': 'Debian' setcode do sources = ['sources.list'] Dir.glob('/etc/apt/sources.list.d/*.{list,sources}').each do |file| diff --git a/lib/facter/apt_update_last_success.rb b/lib/facter/apt_update_last_success.rb index 84acec162c..f00cd1865b 100644 --- a/lib/facter/apt_update_last_success.rb +++ b/lib/facter/apt_update_last_success.rb @@ -6,7 +6,7 @@ # This is generated upon a successful apt-get update run natively in ubuntu. # the Puppetlabs-apt module deploys this same functionality for other debian-ish OSes Facter.add('apt_update_last_success') do - confine osfamily: 'Debian' + confine 'os.family': 'Debian' setcode do if File.exist?('/var/lib/apt/periodic/update-success-stamp') # get epoch time diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb index 66c6a89286..cd9772a232 100644 --- a/lib/facter/apt_updates.rb +++ b/lib/facter/apt_updates.rb @@ -31,7 +31,7 @@ def get_updates(upgrade_option) end Facter.add('apt_has_updates') do - confine osfamily: 'Debian' + confine 'os.family': 'Debian' setcode do apt_package_updates = get_updates('upgrade') apt_package_updates != [[], []] if !apt_package_updates.nil? && apt_package_updates.length == 2 @@ -39,7 +39,7 @@ def get_updates(upgrade_option) end Facter.add('apt_has_dist_updates') do - confine osfamily: 'Debian' + confine 'os.family': 'Debian' setcode do apt_dist_updates = get_updates('dist-upgrade') apt_dist_updates != [[], []] if !apt_dist_updates.nil? && apt_dist_updates.length == 2 diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 1c28cc4b03..0f0abfdc4e 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -11,8 +11,8 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do desc 'apt-key provider for apt_key resource' - confine osfamily: :debian - defaultfor osfamily: :debian + confine 'os.family': :debian + defaultfor 'os.family': :debian commands apt_key: 'apt-key' commands gpg: '/usr/bin/gpg' diff --git a/spec/unit/facter/apt_dist_has_updates_spec.rb b/spec/unit/facter/apt_dist_has_updates_spec.rb index b5b05b6f05..d74b27d0fb 100644 --- a/spec/unit/facter/apt_dist_has_updates_spec.rb +++ b/spec/unit/facter/apt_dist_has_updates_spec.rb @@ -9,7 +9,7 @@ describe 'on non-Debian distro' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') + allow(Facter.fact(:'os.family')).to receive(:value).once.and_return('Redhat') end it { is_expected.to be_nil } @@ -17,7 +17,7 @@ describe 'on Debian based distro missing apt-get' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end @@ -27,7 +27,7 @@ describe 'on Debian based distro' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_dist_package_security_updates_spec.rb b/spec/unit/facter/apt_dist_package_security_updates_spec.rb index 1e8aeb8a58..bdc4e5ebcd 100644 --- a/spec/unit/facter/apt_dist_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_security_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_dist_package_updates_spec.rb b/spec/unit/facter/apt_dist_package_updates_spec.rb index 43e2d7e7d9..dddb9b3336 100644 --- a/spec/unit/facter/apt_dist_package_updates_spec.rb +++ b/spec/unit/facter/apt_dist_package_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_dist_security_updates_spec.rb b/spec/unit/facter/apt_dist_security_updates_spec.rb index baaf0484e9..8ea66bc3db 100644 --- a/spec/unit/facter/apt_dist_security_updates_spec.rb +++ b/spec/unit/facter/apt_dist_security_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has security updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_dist_updates_spec.rb b/spec/unit/facter/apt_dist_updates_spec.rb index ac87f666a1..a5327c7398 100644 --- a/spec/unit/facter/apt_dist_updates_spec.rb +++ b/spec/unit/facter/apt_dist_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_has_updates_spec.rb b/spec/unit/facter/apt_has_updates_spec.rb index 77a95b4391..01079b6094 100644 --- a/spec/unit/facter/apt_has_updates_spec.rb +++ b/spec/unit/facter/apt_has_updates_spec.rb @@ -9,7 +9,7 @@ describe 'on non-Debian distro' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Redhat') + allow(Facter.fact(:'os.family')).to receive(:value).once.and_return('Redhat') end it { is_expected.to be_nil } @@ -17,7 +17,7 @@ describe 'on Debian based distro missing apt-get' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).once.and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).once.and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(false) end @@ -27,7 +27,7 @@ describe 'on Debian based distro' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_package_security_updates_spec.rb b/spec/unit/facter/apt_package_security_updates_spec.rb index d546715426..d842b018c3 100644 --- a/spec/unit/facter/apt_package_security_updates_spec.rb +++ b/spec/unit/facter/apt_package_security_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb index 7960306e00..e71a9d8bbe 100644 --- a/spec/unit/facter/apt_package_updates_spec.rb +++ b/spec/unit/facter/apt_package_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_reboot_required_spec.rb b/spec/unit/facter/apt_reboot_required_spec.rb index b60724514e..2345954450 100644 --- a/spec/unit/facter/apt_reboot_required_spec.rb +++ b/spec/unit/facter/apt_reboot_required_spec.rb @@ -9,7 +9,7 @@ describe 'if a reboot is required' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(true) end @@ -19,7 +19,7 @@ describe 'if a reboot is not required' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:file?).and_return(true) allow(File).to receive(:file?).once.with('/var/run/reboot-required').and_return(false) end diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb index 25ba3114ed..01b68fa965 100644 --- a/spec/unit/facter/apt_security_updates_spec.rb +++ b/spec/unit/facter/apt_security_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has security updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) diff --git a/spec/unit/facter/apt_update_last_success_spec.rb b/spec/unit/facter/apt_update_last_success_spec.rb index 05a12240aa..455159a3a6 100644 --- a/spec/unit/facter/apt_update_last_success_spec.rb +++ b/spec/unit/facter/apt_update_last_success_spec.rb @@ -9,7 +9,7 @@ describe 'on Debian based distro which has not yet created the update-success-stamp file' do it 'has a value of -1' do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).with('/var/lib/apt/periodic/update-success-stamp').and_return(false) expect(subject).to eq(-1) end @@ -17,7 +17,7 @@ describe 'on Debian based distro which has created the update-success-stamp' do it 'has the value of the mtime of the file' do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:exist?).and_return(true) allow(File).to receive(:mtime).and_return(1_407_660_561) expect(subject).to eq(1_407_660_561) diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb index 4397f766bb..4048453e42 100644 --- a/spec/unit/facter/apt_updates_spec.rb +++ b/spec/unit/facter/apt_updates_spec.rb @@ -17,7 +17,7 @@ describe 'when apt has updates' do before(:each) do - allow(Facter.fact(:osfamily)).to receive(:value).and_return('Debian') + allow(Facter.fact(:'os.family')).to receive(:value).and_return('Debian') allow(File).to receive(:executable?) # Stub all other calls allow(Facter::Core::Execution).to receive(:execute) # Catch all other calls allow(File).to receive(:executable?).with('/usr/bin/apt-get').and_return(true) From c3a882d615868c0183662b8724fcdd945348ceec Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 24 Jan 2025 06:07:12 +0000 Subject: [PATCH 4/4] Release prep v10.0.1 --- CHANGELOG.md | 14 ++++++++++++-- metadata.json | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ed7f9274..ad6f39f03c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org). -## [v10.0.0](https://github.com/puppetlabs/puppetlabs-apt/tree/v10.0.0) - 2024-11-25 +## [v10.0.1](https://github.com/puppetlabs/puppetlabs-apt/tree/v10.0.1) - 2025-01-24 + +[Full Changelog](https://github.com/puppetlabs/puppetlabs-apt/compare/v10.0.0...v10.0.1) + +### Fixed + +- Handle repos passed as an array for list format [#1215](https://github.com/puppetlabs/puppetlabs-apt/pull/1215) ([ekohl](https://github.com/ekohl)) + +## [v10.0.0](https://github.com/puppetlabs/puppetlabs-apt/tree/v10.0.0) - 2024-12-18 [Full Changelog](https://github.com/puppetlabs/puppetlabs-apt/compare/v9.4.0...v10.0.0) @@ -17,14 +25,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added - Add Debian 12 "bookworm" support [#1178](https://github.com/puppetlabs/puppetlabs-apt/pull/1178) ([kenyon](https://github.com/kenyon)) +- Support PPA in deb822 format [#1169](https://github.com/puppetlabs/puppetlabs-apt/pull/1169) ([fredericgiquel](https://github.com/fredericgiquel)) +- Add support for deb822 APT sources [#1167](https://github.com/puppetlabs/puppetlabs-apt/pull/1167) ([jps-help](https://github.com/jps-help)) ### Fixed - apt::setting: Dont expect source/content when removing settings [#1208](https://github.com/puppetlabs/puppetlabs-apt/pull/1208) ([bastelfreak](https://github.com/bastelfreak)) +- apt::keyring: Require "source" or "content" only if ensure=present [#1198](https://github.com/puppetlabs/puppetlabs-apt/pull/1198) ([webcompas](https://github.com/webcompas)) ### Other -- apt::keyring: Require "source" or "content" only if ensure=present [#1198](https://github.com/puppetlabs/puppetlabs-apt/pull/1198) ([webcompas](https://github.com/webcompas)) - Eliminate `params.pp` and `create_resources()` [#1172](https://github.com/puppetlabs/puppetlabs-apt/pull/1172) ([kenyon](https://github.com/kenyon)) ## [v9.4.0](https://github.com/puppetlabs/puppetlabs-apt/tree/v9.4.0) - 2024-02-15 diff --git a/metadata.json b/metadata.json index 915153d8bf..eb35497c5e 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppetlabs-apt", - "version": "10.0.0", + "version": "10.0.1", "author": "puppetlabs", "summary": "Provides an interface for managing Apt source, key, and definitions with Puppet", "license": "Apache-2.0",