Skip to content
Closed
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
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ The following parameters are available in the `apt::backports` class:
* [`keyring`](#-apt--backports--keyring)
* [`pin`](#-apt--backports--pin)
* [`include`](#-apt--backports--include)
* [`source_format`](#-apt--backports--source_format)

##### <a name="-apt--backports--location"></a>`location`

Expand Down Expand Up @@ -575,6 +576,14 @@ Specifies whether to include 'deb' or 'src', or both.

Default value: `{}`

##### <a name="-apt--backports--source_format"></a>`source_format`

Data type: `Enum['list', 'sources']`

The file format to use for the backports source. See https://wiki.debian.org/SourcesList

Default value: `'list'`

## Defined types

### <a name="apt--auth"></a>`apt::auth`
Expand Down
36 changes: 29 additions & 7 deletions manifests/backports.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# @param include
# Specifies whether to include 'deb' or 'src', or both.
#
# @param source_format
# The file format to use for the backports source. See https://wiki.debian.org/SourcesList
#
class apt::backports (
Optional[Stdlib::HTTPUrl] $location = undef,
Optional[String[1]] $release = undef,
Expand All @@ -48,6 +51,7 @@
Stdlib::AbsolutePath $keyring = "/usr/share/keyrings/${facts['os']['name'].downcase}-archive-keyring.gpg",
Variant[Integer, String[1], Hash] $pin = 200,
Hash $include = {},
Enum['list', 'sources'] $source_format = 'list',
) {
include apt

Expand Down Expand Up @@ -107,13 +111,31 @@
fail('pin must be either a string, number or hash')
}

if $source_format == 'sources' {
$_includes = $apt::include_defaults + $include
$_source = {
'location' => [$_location],
'release' => [$_release],
'repos' => split($_repos, /\s+/),
'types' => delete_undef_values([
$_includes['deb'] ? { true => 'deb', default => undef },
$_includes['src'] ? { true => 'deb-src', default => undef },
]),
}
} else {
$_source = {
'location' => $_location,
'release' => $_release,
'repos' => $_repos,
'include' => $include,
}
}

apt::source { 'backports':
location => $_location,
release => $_release,
repos => $_repos,
include => $include,
key => $key,
keyring => $_keyring,
pin => $_pin,
source_format => $source_format,
key => $key,
keyring => $_keyring,
pin => $_pin,
* => $_source,
}
}
24 changes: 24 additions & 0 deletions spec/acceptance/apt_backports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,28 @@
run_shell('apt-cache policy | grep --quiet backports')
end
end

context 'when using source_format sources' do
let(:pp) do
<<-MANIFEST
class { 'apt::backports':
source_format => 'sources',
}
apt::setting { 'list-backports':
ensure => absent,
}
MANIFEST
end

it 'applies idempotently' do
retry_on_error_matching do
idempotent_apply(pp)
end
end

it 'provides backports apt sources' do
run_shell('test -f /etc/apt/sources.list.d/backports.sources')
run_shell('apt-cache policy | grep --quiet backports')
end
end
end
39 changes: 39 additions & 0 deletions spec/classes/apt_backports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,45 @@
}
end

context 'with source_format sources on debian' do
let(:facts) do
{
os: {
family: 'Debian',
name: 'Debian',
release: {
full: '12.5',
major: '12',
minor: '5'
},
distro: {
codename: 'bookworm',
id: 'Debian'
}
}
}
end
let(:params) do
{
source_format: 'sources',
include: { 'src' => true }
}
end

it {
expect(subject).to contain_apt__source('backports').with(
source_format: 'sources',
location: ['http://deb.debian.org/debian'],
repos: ['main', 'contrib', 'non-free', 'non-free-firmware'],
release: ['bookworm-backports'],
types: ['deb', 'deb-src'],
keyring: '/usr/share/keyrings/debian-archive-keyring.gpg',
)
}

it { is_expected.to contain_apt__setting('sources-backports').with_content(%r{^Suites: bookworm-backports$}) }
end

# Include shared examples for Ubuntu versions
include_examples 'ubuntu backports', '22.04', '22.04', 'jammy'
include_examples 'ubuntu backports', '24.04', '24.04', 'noble'
Expand Down
Loading