Skip to content

Commit

Permalink
Merge pull request #204 from b1-systems/fix/ubuntu-legacy
Browse files Browse the repository at this point in the history
Replace legacy Allowed-Origins with Origins-Pattern on all distros
  • Loading branch information
bastelfreak authored Nov 3, 2021
2 parents 427bd1b + 0c582cb commit 3605678
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 73 deletions.
3 changes: 1 addition & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
Optional[Integer[0]] $dl_limit = undef,
Integer[0, 1] $enable = 1,
Boolean $install_on_shutdown = false,
Boolean $legacy_origin = $unattended_upgrades::params::legacy_origin,
Unattended_upgrades::Mail $mail = {},
Boolean $minimal_steps = true,
Array[String[1]] $origins = $unattended_upgrades::params::origins,
Array[Unattended_upgrades::Origin] $origins = $unattended_upgrades::params::origins,
String[1] $package_ensure = installed,
Array[String[1]] $extra_origins = [],
Optional[Integer[0]] $random_sleep = undef,
Expand Down
20 changes: 5 additions & 15 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
'debian', 'raspbian': {
case fact('lsbdistcodename') {
'bullseye': {
$legacy_origin = false
$origins = [
'origin=Debian,codename=${distro_codename},label=Debian', #lint:ignore:single_quote_string_with_variables
'origin=Debian,codename=${distro_codename}-security,label=Debian-Security', #lint:ignore:single_quote_string_with_variables
]
}
default: {
$legacy_origin = false
$origins = [
'origin=Debian,codename=${distro_codename},label=Debian', #lint:ignore:single_quote_string_with_variables
'origin=Debian,codename=${distro_codename},label=Debian-Security', #lint:ignore:single_quote_string_with_variables
Expand All @@ -38,33 +36,25 @@
}
'ubuntu', 'neon': {
# Ubuntu: https://ubuntu.com/about/release-cycle and https://wiki.ubuntu.com/Releases
$legacy_origin = true
# Ubuntu 18.04 and up do allow the use of Origins-Pattern; 16.04 is out of support for Vox Pupuli.
$origins = [
'${distro_id}:${distro_codename}', #lint:ignore:single_quote_string_with_variables
'${distro_id}:${distro_codename}-security', #lint:ignore:single_quote_string_with_variables
'${distro_id}ESMApps:${distro_codename}-apps-security', #lint:ignore:single_quote_string_with_variables
'${distro_id}ESM:${distro_codename}-infra-security', #lint:ignore:single_quote_string_with_variables
'origin=${distro_id},suite=${distro_codename}', #lint:ignore:single_quote_string_with_variables
'origin=${distro_id},suite=${distro_codename}-security', #lint:ignore:single_quote_string_with_variables
'origin=${distro_id}ESMApps,suite=${distro_codename}-apps-security', #lint:ignore:single_quote_string_with_variables
'origin=${distro_id}ESM,suite=${distro_codename}-infra-security', #lint:ignore:single_quote_string_with_variables
]
}
'LinuxMint': {
case fact('lsbmajdistrelease') {
# Linux Mint 18* is based on Ubuntu 16.04
'18': {
$legacy_origin = true
$origins = [
'Ubuntu:xenial-security',
]
}
default: {
$legacy_origin = true
$origins = [
'${distro_id}:${distro_codename}-security', #lint:ignore:single_quote_string_with_variables
]
}
}
}
default: {
$legacy_origin = undef
$origins = undef
}
}
Expand Down
18 changes: 9 additions & 9 deletions spec/classes/os_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,33 @@
case os_facts[:operatingsystem]
when 'Debian'
case os_facts[:lsbdistcodename]
when 'buster'
when 'bullseye'
it do
is_expected.to create_file(file_unattended).with_content(
/Unattended-Upgrade::Origins-Pattern\ {\n
\t"origin=Debian,codename=\${distro_codename},label=Debian";\n
\t"origin=Debian,codename=\${distro_codename},label=Debian-Security";\n
\t"origin=Debian,codename=\${distro_codename}-security,label=Debian-Security";\n
};/x
)
end
when 'bullseye'
else
it do
is_expected.to create_file(file_unattended).with_content(
/Unattended-Upgrade::Origins-Pattern\ {\n
\t"origin=Debian,codename=\${distro_codename},label=Debian";\n
\t"origin=Debian,codename=\${distro_codename}-security,label=Debian-Security";\n
\t"origin=Debian,codename=\${distro_codename},label=Debian-Security";\n
};/x
)
end
end
when 'Ubuntu'
it do
is_expected.to create_file(file_unattended).with_content(
/Unattended-Upgrade::Allowed-Origins\ {\n
\t"\${distro_id}\:\${distro_codename}";\n
\t"\${distro_id}\:\${distro_codename}-security";\n
\t"\${distro_id}ESMApps\:\${distro_codename}-apps-security";\n
\t"\${distro_id}ESM\:\${distro_codename}-infra-security";\n
/Unattended-Upgrade::Origins-Pattern\ {\n
\t"origin=\${distro_id},suite=\${distro_codename}";\n
\t"origin=\${distro_id},suite=\${distro_codename}-security";\n
\t"origin=\${distro_id}ESMApps,suite=\${distro_codename}-apps-security";\n
\t"origin=\${distro_id}ESM,suite=\${distro_codename}-infra-security";\n
};/x
)
end
Expand Down
31 changes: 0 additions & 31 deletions spec/classes/other_debians_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,4 @@
)
end
end

context 'with defaults on Linux Mint 18 Sarah' do
let(:facts) do
{
os: {
name: 'LinuxMint',
family: 'Debian',
release: {
full: '18'
}
},
osfamily: 'Debian',
lsbdistid: 'LinuxMint',
lsbdistcodename: 'sarah',
lsbdistrelease: '18',
lsbmajdistrelease: '18'
}
end

it do
is_expected.to create_file(file_unattended).with(
'owner' => 'root',
'group' => 'root'
).with_content(
# This is the only section that's different for Ubuntu compared to Debian
%r{\Unattended-Upgrade::Allowed-Origins\ {\n
\t"Ubuntu\:xenial-security";\n
};}x
)
end
end
end
14 changes: 2 additions & 12 deletions spec/classes/unattended_upgrades_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
'reboot_time' => '03:00'
},
verbose: 1,
legacy_origin: true,
origins: %w[bananas],
origins: %w[codename=bananas],
blacklist: %w[foo bar],
whitelist: %w[foo bar],
minimal_steps: false,
Expand Down Expand Up @@ -119,7 +118,7 @@
owner: 'root',
group: 'root'
).with_content(
/Unattended-Upgrade::Allowed-Origins {\n\t"bananas";\n};/
/Unattended-Upgrade::Origins-Pattern {\n\t"codename=bananas";\n};/
).with_content(
/Unattended-Upgrade::Package-Blacklist {\n\t"foo";\n\t"bar";\n};/
).with_content(
Expand Down Expand Up @@ -234,15 +233,6 @@

it { is_expected.to compile.and_raise_error(/got String/) }
end
context 'bad legacy_origin' do
let :params do
{
legacy_origin: 'foo'
}
end

it { is_expected.to compile.and_raise_error(/got String/) }
end
context 'bad minimal_steps' do
let :params do
{
Expand Down
4 changes: 0 additions & 4 deletions templates/unattended-upgrades.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
<%- if @legacy_origin -%>
Unattended-Upgrade::Allowed-Origins {
<%- else -%>
Unattended-Upgrade::Origins-Pattern {
<%- end -%>
<% @origins.each do |origin| -%>
"<%= origin %>";
<% end -%>
Expand Down
2 changes: 2 additions & 0 deletions types/origin.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @summary Validate that the given input is accepted as an `Unattended-Upgrade::Origin-Pattern`.
type Unattended_upgrades::Origin = Pattern[/^(origin|codename|label|site|suite|component|archive|[oalcn])=[^,]+(,(origin|codename|label|site|suite|component|archive|[oalcn])=[^,]+)*/]

0 comments on commit 3605678

Please sign in to comment.