From 4b6742b0e3d798adeca86b03c944053bf2077402 Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Sun, 31 Dec 2023 17:09:19 -0800 Subject: [PATCH 1/3] backports unit tests: minor fixes and updates * Use `include apt` instead of a resource-like class declaration * Use modern Debian and Ubuntu releases * Correct the Ubuntu major version --- spec/classes/apt_backports_spec.rb | 43 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index cb2d421d50..bc77dd8efb 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -3,21 +3,22 @@ require 'spec_helper' describe 'apt::backports', type: :class do - let(:pre_condition) { "class{ '::apt': }" } + let(:pre_condition) { 'include apt' } describe 'debian/ubuntu tests' do - context 'with defaults on deb' do + context 'with defaults on debian' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '9', - full: '9.0' + full: '11.8', + major: '11', + minor: '8' }, distro: { - codename: 'stretch', + codename: 'bullseye', id: 'Debian' } } @@ -27,8 +28,8 @@ it { expect(subject).to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian', repos: 'main contrib non-free', - release: 'stretch-backports', - pin: { 'priority' => 200, 'release' => 'stretch-backports' }) + release: 'bullseye-backports', + pin: { 'priority' => 200, 'release' => 'bullseye-backports' }) } end @@ -39,11 +40,11 @@ family: 'Debian', name: 'Ubuntu', release: { - major: '18', - full: '18.04' + major: '22.04', + full: '22.04' }, distro: { - codename: 'bionic', + codename: 'jammy', id: 'Ubuntu' } } @@ -53,8 +54,8 @@ it { expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', repos: 'main universe multiverse restricted', - release: 'bionic-backports', - pin: { 'priority' => 200, 'release' => 'bionic-backports' }) + release: 'jammy-backports', + pin: { 'priority' => 200, 'release' => 'jammy-backports' }) } end @@ -65,11 +66,11 @@ family: 'Debian', name: 'Ubuntu', release: { - major: '18', - full: '18.04' + major: '22.04', + full: '22.04' }, distro: { - codename: 'bionic', + codename: 'jammy', id: 'Ubuntu' } } @@ -101,11 +102,11 @@ family: 'Debian', name: 'Ubuntu', release: { - major: '18', - full: '18.04' + major: '22.04', + full: '22.04' }, distro: { - codename: 'bionic', + codename: 'jammy', id: 'Ubuntu' } } @@ -230,11 +231,11 @@ family: 'Debian', name: 'Ubuntu', release: { - major: '18', - full: '18.04' + major: '22.04', + full: '22.04' }, distro: { - codename: 'bionic', + codename: 'jammy', id: 'Ubuntu' } } From 22396239a40f526ffc265c13572e0a48f35a8bbf Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Mon, 1 Jan 2024 08:34:44 -0800 Subject: [PATCH 2/3] backports: improve test formatting --- spec/classes/apt_backports_spec.rb | 56 +++++++++++++++++++----------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index bc77dd8efb..3e8b750a14 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -26,10 +26,15 @@ end it { - expect(subject).to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian', - repos: 'main contrib non-free', - release: 'bullseye-backports', - pin: { 'priority' => 200, 'release' => 'bullseye-backports' }) + expect(subject).to contain_apt__source('backports').with( + location: 'http://deb.debian.org/debian', + repos: 'main contrib non-free', + release: 'bullseye-backports', + pin: { + 'priority' => 200, + 'release' => 'bullseye-backports' + }, + ) } end @@ -52,10 +57,15 @@ end it { - expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', - repos: 'main universe multiverse restricted', - release: 'jammy-backports', - pin: { 'priority' => 200, 'release' => 'jammy-backports' }) + expect(subject).to contain_apt__source('backports').with( + location: 'http://archive.ubuntu.com/ubuntu', + repos: 'main universe multiverse restricted', + release: 'jammy-backports', + pin: { + 'priority' => 200, + 'release' => 'jammy-backports' + }, + ) } end @@ -87,11 +97,13 @@ end it { - expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu-test', - key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', - repos: 'main', - release: 'vivid', - pin: { 'priority' => 90, 'release' => 'vivid' }) + expect(subject).to contain_apt__source('backports').with( + location: 'http://archive.ubuntu.com/ubuntu-test', + key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553', + repos: 'main', + release: 'vivid', + pin: { 'priority' => 90, 'release' => 'vivid' }, + ) } end @@ -124,8 +136,10 @@ end it { - expect(subject).to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, - pin: { 'priority' => '90' }) + expect(subject).to contain_apt__source('backports').with( + key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' }, + pin: { 'priority' => '90' }, + ) } end end @@ -159,11 +173,13 @@ end it { - expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu', - key: '630239CC130E1A7FD81A27B140976EAF437D05B5', - repos: 'main universe multiverse restricted', - release: 'trusty-backports', - pin: { 'priority' => 200, 'release' => 'trusty-backports' }) + expect(subject).to contain_apt__source('backports').with( + location: 'http://archive.ubuntu.com/ubuntu', + key: '630239CC130E1A7FD81A27B140976EAF437D05B5', + repos: 'main universe multiverse restricted', + release: 'trusty-backports', + pin: { 'priority' => 200, 'release' => 'trusty-backports' }, + ) } end From 46f53b83b0940f51a0cc44f0e07fb007b11d2f4d Mon Sep 17 00:00:00 2001 From: Kenyon Ralph Date: Mon, 1 Jan 2024 08:35:02 -0800 Subject: [PATCH 3/3] backports: add keyring support --- examples/backports.pp | 4 ---- manifests/backports.pp | 34 +++++++++++++++++++----------- spec/classes/apt_backports_spec.rb | 24 ++++++--------------- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/examples/backports.pp b/examples/backports.pp index ff56666629..d747f8f70d 100644 --- a/examples/backports.pp +++ b/examples/backports.pp @@ -4,8 +4,4 @@ location => 'http://us.archive.ubuntu.com/ubuntu', release => 'trusty-backports', repos => 'main universe multiverse restricted', - key => { - id => '630239CC130E1A7FD81A27B140976EAF437D05B5', - server => 'keyserver.ubuntu.com', - }, } diff --git a/manifests/backports.pp b/manifests/backports.pp index 8cb32eb1c9..7606a4b463 100644 --- a/manifests/backports.pp +++ b/manifests/backports.pp @@ -1,15 +1,7 @@ # @summary Manages backports. # -# @example Set up a backport source for Linux Mint qiana -# class { 'apt::backports': -# location => 'http://us.archive.ubuntu.com/ubuntu', -# release => 'trusty-backports', -# repos => 'main universe multiverse restricted', -# key => { -# id => '630239CC130E1A7FD81A27B140976EAF437D05B5', -# server => 'keyserver.ubuntu.com', -# }, -# } +# @example Set up a backport source for Ubuntu +# include apt::backports # # @param location # Specifies an Apt repository containing the backports to manage. Valid options: a string containing a URL. Default value for Debian and @@ -36,6 +28,11 @@ # Specifies a key to authenticate the backports. Valid options: a string to be passed to the id parameter of the apt::key defined type, or a # hash of parameter => value pairs to be passed to apt::key's id, server, content, source, and/or options parameters. # +# @param keyring +# Absolute path to a file containing the PGP keyring used to sign this +# repository. Value is passed to the apt::source and used to set signed-by on +# the source entry. +# # @param pin # Specifies a pin priority for the backports. Valid options: a number or string to be passed to the `id` parameter of the `apt::pin` defined # type, or a hash of `parameter => value` pairs to be passed to `apt::pin`'s corresponding parameters. @@ -48,6 +45,7 @@ Optional[String] $release = undef, Optional[String] $repos = undef, Optional[Variant[String, Hash]] $key = undef, + Stdlib::AbsolutePath $keyring = "/usr/share/keyrings/${facts['os']['name'].downcase}-archive-keyring.gpg", Variant[Integer, String, Hash] $pin = 200, Variant[Hash] $include = {}, ) { @@ -56,21 +54,25 @@ if $location { $_location = $location } + if $release { $_release = $release } + if $repos { $_repos = $repos } if (!($facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu')) { - unless $location and $release and $repos and $key { - fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key') + unless $location and $release and $repos { + fail('If not on Debian or Ubuntu, you must explicitly pass location, release, and repos') } } + unless $location { $_location = $apt::backports['location'] } + unless $release { if fact('os.distro.codename') { $_release = "${fact('os.distro.codename')}-backports" @@ -78,10 +80,17 @@ fail('os.distro.codename fact not available: release parameter required') } } + unless $repos { $_repos = $apt::backports['repos'] } + $_keyring = if $key { + undef + } else { + $keyring + } + if $pin =~ Hash { $_pin = $pin } elsif $pin =~ Numeric or $pin =~ String { @@ -101,6 +110,7 @@ repos => $_repos, include => $include, key => $key, + keyring => $_keyring, pin => $_pin, } } diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb index 3e8b750a14..3945449f6c 100644 --- a/spec/classes/apt_backports_spec.rb +++ b/spec/classes/apt_backports_spec.rb @@ -34,6 +34,7 @@ 'priority' => 200, 'release' => 'bullseye-backports' }, + keyring: '/usr/share/keyrings/debian-archive-keyring.gpg', ) } end @@ -65,6 +66,7 @@ 'priority' => 200, 'release' => 'jammy-backports' }, + keyring: '/usr/share/keyrings/ubuntu-archive-keyring.gpg', ) } end @@ -144,7 +146,7 @@ end end - describe 'mint tests' do + describe 'linuxmint tests' do let(:facts) do { os: { @@ -193,7 +195,7 @@ end it do - expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos}) end end @@ -207,7 +209,7 @@ end it do - expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos}) end end @@ -221,21 +223,7 @@ end it do - expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) - end - end - - context 'with missing key' do - let(:params) do - { - location: 'http://archive.ubuntu.com/ubuntu', - release: 'trusty-backports', - repos: 'main universe multiverse restricted' - } - end - - it do - expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key}) + expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, and repos}) end end end