Skip to content

Commit

Permalink
add tests, fix default_file on Debian Bookworm
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed May 18, 2024
1 parent 9e1705d commit 5705808
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
file { $config_file:
ensure => $config_ensure,
owner => 'root',
group => 'root',
group => 0,
mode => '0644',
require => Package[$package],
notify => Exec['locale-gen'],
Expand Down Expand Up @@ -235,7 +235,7 @@
file { $default_file:
ensure => $ensure,
owner => 'root',
group => 'root',
group => 0,
mode => '0644',
content => template("${module_name}/${locale_template}"),
require => $update_locale_require,
Expand Down
22 changes: 14 additions & 8 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@

case $facts['os']['name'] {
/(Ubuntu|Debian|LinuxMint|Linuxmint|Raspbian|Kali|Pop!_OS)/: {
if $facts['os']['name'] == 'Debian' and versioncmp($facts['os']['release']['full'], '12') > 0 {
$default_file = '/etc/locale.conf'
} elsif $facts['os']['name'] == 'Ubuntu' and versioncmp($facts['os']['release']['full'], '24.04') >= 0 {
$default_file = '/etc/locale.conf'
} else {
$default_file = '/etc/default/locale'
}

$locale_gen_cmd = '/usr/sbin/locale-gen'
$update_locale_cmd = '/usr/sbin/update-locale'
$supported_locales = '/usr/share/i18n/SUPPORTED' # ALL locales support

case $facts['os']['name'] {
/(Ubuntu|LinuxMint|Linuxmint|Pop!_OS)/: {
if versioncmp($facts['os']['release']['full'], '24.04') >= 0 {
$default_file = '/etc/locale.conf'
} else {
$default_file = '/etc/default/locale'
}
$package = 'locales'
case $facts['os']['distro']['codename'] {
'hardy': {
Expand All @@ -51,6 +48,12 @@
}
}
/(Debian|Raspbian|Kali)/: {
if versioncmp($facts['os']['release']['major'], '12') == 1 {
$default_file = '/etc/locale.conf'
} else {
$default_file = '/etc/default/locale'
}

$package = 'locales-all'
# If config_file is not set, we will end up with the error message:
# Missing title. The title expression resulted in undef at [init.pp
Expand Down Expand Up @@ -85,13 +88,16 @@
$locale_gen_cmd = undef
$update_locale_cmd = undef
$config_file = undef
$supported_locales = undef
$default_file = '/etc/sysconfig/language'
}
/(Archlinux)/: {
$package = 'glibc'
$update_locale_pkg = false
$locale_gen_cmd = '/usr/bin/locale-gen' # /usr/sbin will also work but considered legacy
$update_locale_cmd = undef
$config_file = '/etc/locale.gen'
$supported_locales = undef
$default_file = '/etc/locale.conf'
}
/(Gentoo|Sabayon)/: {
Expand Down
13 changes: 11 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
"operatingsystem": "Raspbian"
},
{
"operatingsystem": "Debian"
"operatingsystem": "Debian",
"operatingsystemrelease": [
"11",
"12"
]
},
{
"operatingsystem": "Ubuntu"
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"20.04",
"22.04",
"24.04"
]
},
{
"operatingsystem": "openSUSE"
Expand Down
61 changes: 61 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'locales' do
let :node do
'rspec.puppet.com'
end

on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

describe 'with all defaults' do
it { is_expected.to compile.with_all_deps }

case facts[:os]['family'].downcase
when 'debian'
case facts[:os]['name'].downcase
when 'debian'
default_file = if Gem::Version.new(facts[:os]['release']['major']) > Gem::Version.new('12')
'/etc/locale.conf'
else
'/etc/default/locale'
end
when 'ubuntu'
default_file = if Gem::Version.new(facts[:os]['release']['full']) >= Gem::Version.new('24.04')
'/etc/locale.conf'
else
'/etc/default/locale'
end
end
when 'sles', 'suse'
default_file = '/etc/sysconfig/language'
else
default_file = '/etc/locale.conf'
end

it do
is_expected.to contain_file(default_file).with(
'ensure' => 'present',
'owner' => 'root',
'group' => 0,
'mode' => '0644'
)
end

if os =~ (%r{^(debian|ubuntu)}) && (default_file != '/etc/default/locale')
it do
is_expected.to contain_file(default_file).with(
'ensure' => 'present',
'target' => '/etc/locale.conf'
)
end
end
end
end
end
end

0 comments on commit 5705808

Please sign in to comment.