Skip to content

Commit b3f3162

Browse files
authored
Merge pull request #283 from voxpupuli/acceptance_rfc
Add more OSes, refactor acceptance tests
2 parents 6013f5c + 18bfd1c commit b3f3162

14 files changed

Lines changed: 296 additions & 318 deletions

.sync.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
.puppet-lint.rc:
33
enabled_lint_checks:
44
- parameter_types
5+
spec/spec_helper_acceptance.rb:
6+
unmanaged: false

manifests/base.pp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# @summary This class manages the base installation for rsyslog
22
class rsyslog::base {
3+
$rsyslog_package_ref = if $rsyslog::manage_package {
4+
package { $rsyslog::package_name:
5+
ensure => $rsyslog::package_version,
6+
}
7+
} else {
8+
undef
9+
}
10+
311
if $rsyslog::use_upstream_repo {
412
case $facts['os']['family'] {
513
'Debian': {
614
if $facts['os']['name'] == 'Ubuntu' {
715
include apt
8-
apt::ppa { 'ppa:adiscon/v8-stable': }
16+
apt::ppa { 'ppa:adiscon/v8-stable':
17+
before => $rsyslog_package_ref,
18+
}
919
}
1020
}
1121
'RedHat': {
@@ -16,18 +26,14 @@
1626
enabled => '1',
1727
gpgcheck => '0',
1828
gpgkey => 'http://rpms.adiscon.com/v8-stable/epel-$releasever/$basearch',
29+
priority => 50, # Prefer packages from this repo
30+
before => $rsyslog_package_ref,
1931
}
2032
}
2133
default: { fail("${facts['os']['name']} is not currently supported by upstream packages.") }
2234
}
2335
}
2436

25-
if $rsyslog::manage_package {
26-
package { $rsyslog::package_name:
27-
ensure => $rsyslog::package_version,
28-
}
29-
}
30-
3137
if $rsyslog::feature_packages {
3238
package { $rsyslog::feature_packages:
3339
ensure => installed,

manifests/init.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
# Set the file mode for the rsyslog.d configuration directory.
8686
# @param global_conf_perms
8787
# Set the file mode for the /etc/rsyslog.conf
88-
# @param config_file_include
88+
# @param config_file_include
8989
# Override the include directive in the /etc/rsyslog.conf file.
9090
#
9191
class rsyslog (
@@ -124,7 +124,7 @@
124124
) {
125125
if $manage_service == true and $external_service == true {
126126
fail('manage_service and external_service cannot be set at the same time!')
127-
} else {
128-
contain 'rsyslog::base'
129127
}
128+
129+
contain 'rsyslog::base'
130130
}

metadata.json

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
"issues_url": "https://github.com/voxpupuli/puppet-rsyslog/issues",
1010
"operatingsystem_support": [
1111
{
12-
"operatingsystem": "RedHat",
12+
"operatingsystem": "AlmaLinux",
1313
"operatingsystemrelease": [
14+
"8",
1415
"9"
1516
]
1617
},
@@ -20,21 +21,40 @@
2021
"9"
2122
]
2223
},
24+
{
25+
"operatingsystem": "Debian",
26+
"operatingsystemrelease": [
27+
"11",
28+
"12",
29+
"13"
30+
]
31+
},
2332
{
2433
"operatingsystem": "OracleLinux",
2534
"operatingsystemrelease": [
2635
"8"
2736
]
2837
},
2938
{
30-
"operatingsystem": "Ubuntu",
39+
"operatingsystem": "RedHat",
40+
"operatingsystemrelease": [
41+
"9"
42+
]
43+
},
44+
{
45+
"operatingsystem": "Rocky",
3146
"operatingsystemrelease": [
32-
"18.04"
47+
"8",
48+
"9"
3349
]
3450
},
3551
{
36-
"operatingsystem": "Debian",
37-
"operatingsystemrelease": []
52+
"operatingsystem": "Ubuntu",
53+
"operatingsystemrelease": [
54+
"18.04",
55+
"22.04",
56+
"24.04"
57+
]
3858
}
3959
],
4060
"dependencies": [

spec/acceptance/10_rsyslog_spec.rb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
def has_upstream_repo
6+
os = fact('os')
7+
case os['family']
8+
when 'RedHat'
9+
return true
10+
else
11+
case os['name']
12+
when 'Ubuntu'
13+
return true
14+
end
15+
end
16+
false
17+
end
18+
19+
describe 'rsyslog' do
20+
# Cache OS facts
21+
let(:os) { fact('os') }
22+
23+
context 'with default settings' do
24+
it_behaves_like 'an idempotent resource' do
25+
# Rsyslog requires at least one action to be defined to start
26+
let(:manifest) do
27+
<<-PUPPET
28+
include 'rsyslog'
29+
file { '/etc/rsyslog.d/50-test.conf':
30+
content => 'action(type="omfile" file="/dev/null")',
31+
before => Service['rsyslog'],
32+
}
33+
PUPPET
34+
end
35+
end
36+
37+
describe file('/etc/rsyslog.conf') do
38+
it { is_expected.to be_file }
39+
it { is_expected.to be_readable }
40+
end
41+
42+
describe file('/etc/rsyslog.d') do
43+
it { is_expected.to be_directory }
44+
it { is_expected.to exist }
45+
end
46+
47+
describe package('rsyslog') do
48+
it { is_expected.to be_installed }
49+
end
50+
51+
describe service('rsyslog') do
52+
it { is_expected.to be_running }
53+
it { is_expected.to be_enabled }
54+
end
55+
end
56+
57+
context 'with upstream repo' do
58+
before(:all) do
59+
# Skip this test for OSes w/o supported upstream repos
60+
skip 'Not supported' unless has_upstream_repo
61+
# Wipe existing rsyslog before installing from repo
62+
wipe_rsyslog
63+
end
64+
65+
it_behaves_like 'an idempotent resource' do
66+
let(:manifest) do
67+
<<-PUPPET
68+
class { 'rsyslog':
69+
use_upstream_repo => true,
70+
}
71+
file { '/etc/rsyslog.d/50-test.conf':
72+
content => 'action(type="omfile" file="/dev/null")',
73+
before => Service['rsyslog'],
74+
}
75+
PUPPET
76+
end
77+
end
78+
79+
describe package('rsyslog') do
80+
it { is_expected.to be_installed }
81+
end
82+
83+
describe service('rsyslog') do
84+
it { is_expected.to be_running }
85+
it { is_expected.to be_enabled }
86+
end
87+
88+
# Ensure the rsyslog package was installed from the upstream rsyslog repo
89+
describe 'rsyslog package' do
90+
it 'is installed from upstream repo' do
91+
case os['family']
92+
when 'RedHat'
93+
expect(command('dnf repoquery --installed --qf "%{from_repo}" rsyslog').stdout.strip).to eq('upstream_rsyslog')
94+
else
95+
case os['name']
96+
when 'Ubuntu'
97+
# Least ugly way to check where a package was installed from
98+
expect(
99+
command('python3 -c "import apt; print(apt.Cache()[\"rsyslog\"].installed.uri)"').stdout,
100+
).to start_with('https://ppa.launchpadcontent.net/adiscon/v8-stable/ubuntu')
101+
end
102+
end
103+
end
104+
end
105+
end
106+
end

spec/acceptance/actions_spec.rb

Lines changed: 27 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,38 @@
22

33
require 'spec_helper_acceptance'
44

5-
describe 'Rsyslog actions' do
6-
before(:context) do
7-
cleanup_helper
8-
end
9-
10-
context 'basic action' do
11-
it 'applies with action' do
12-
pp = <<-MANIFEST
13-
if $facts['os']['name'] == 'Fedora' {
14-
package { 'rsyslog-elasticsearch': ensure => installed }
15-
}
16-
17-
class { 'rsyslog::config':
18-
actions => {
19-
'omfile_all_logs' => {
20-
'type' => 'omfile',
21-
'config' => {
22-
'queue.type' => 'LinkedList',
23-
'queue.spoolDirectory' => '/var/log/rsyslog/queue',
24-
'file' => '/tmp/log',
25-
}
26-
},
27-
'myaction' => {
28-
'type' => 'omelasticsearch',
29-
'config' => {
30-
'host' => ["127.0.0.1", "192.168.0.1"],
31-
'queue.type' => 'linkedlist',
32-
'queue.spoolDirectory' => '/var/log/rsyslog/queue'
5+
describe 'rsyslog::config::actions' do
6+
it_behaves_like 'an idempotent resource' do
7+
let(:manifest) do
8+
<<-PUPPET
9+
class { 'rsyslog::config':
10+
actions => {
11+
'omfile_all_logs' => {
12+
'type' => 'omfile',
13+
'config' => {
14+
'queue.type' => 'LinkedList',
15+
'queue.spoolDirectory' => '/var/log/rsyslog/queue',
16+
'file' => '/tmp/log',
17+
}
18+
},
19+
'myaction' => {
20+
'type' => 'omfwd',
21+
'config' => {
22+
'target' => "127.0.0.123",
23+
'queue.type' => 'linkedlist',
24+
'queue.spoolDirectory' => '/var/log/rsyslog/queue'
25+
}
3326
}
3427
}
3528
}
36-
}
37-
MANIFEST
38-
39-
apply_manifest(pp, catch_failures: true)
40-
apply_manifest(pp, catch_changes: true)
29+
PUPPET
4130
end
31+
end
4232

43-
describe file('/etc/rsyslog.d/50_rsyslog.conf') do
44-
its(:content) do
45-
is_expected.to match(%r{# omfile_all_logs\naction\(type="omfile"\n.*name="omfile_all_logs"\n.*queue.type="LinkedList"\n.*queue.spoolDirectory="/var/log/rsyslog/queue"\n.*file="/tmp/log"\n.*\)})
46-
is_expected.to match(%r{# myaction\naction\(type="omelasticsearch"\n.*name="myaction"\n.*host=\["127.0.0.1", "192.168.0.1"\]\n.*queue.type="linkedlist"\n.*queue.spoolDirectory="/var/log/rsyslog/queue"\n.*\)})
47-
end
48-
end
49-
50-
# rm the rsyslog-elasticsearch package as it will block the uninstall of
51-
# the rsyslog package in other acceptance tests
52-
if fact('os.name') == 'Fedora'
53-
it 'applies with action' do
54-
pp = <<-MANIFEST
55-
if $facts['os']['name'] == 'Fedora' {
56-
package { 'rsyslog-elasticsearch': ensure => absent }
57-
}
58-
MANIFEST
59-
60-
apply_manifest(pp, catch_failures: true)
61-
apply_manifest(pp, catch_changes: true)
62-
end
33+
describe file('/etc/rsyslog.d/50_rsyslog.conf') do
34+
its(:content) do
35+
is_expected.to match(%r{# omfile_all_logs\naction\(type="omfile"\n.*name="omfile_all_logs"\n.*queue.type="LinkedList"\n.*queue.spoolDirectory="/var/log/rsyslog/queue"\n.*file="/tmp/log"\n.*\)})
36+
is_expected.to match(%r{# myaction\naction\(type="omfwd"\n.*name="myaction"\n.*target="127.0.0.123"\n.*queue.type="linkedlist"\n.*queue.spoolDirectory="/var/log/rsyslog/queue"\n.*\)})
6337
end
6438
end
6539
end

spec/acceptance/base_spec.rb

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)