Skip to content

Commit bfbee7c

Browse files
committed
Adjust tests for FreeBSD
This does expose config_dir in redis::instance using $redis::config_dir config_dir is used instead of using dirname(config_file) It might also fix a problem in several RHEL based operating systems as the config might have been inadvertently placed in /etc/ as opposed to /etc/redis The FreeBSD adjustments disable the systemd related testing and other clear linuxisms
1 parent 3940432 commit bfbee7c

6 files changed

Lines changed: 150 additions & 66 deletions

File tree

REFERENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,6 +2147,7 @@ The following parameters are available in the `redis::instance` defined type:
21472147
* [`output_buffer_limit_slave`](#-redis--instance--output_buffer_limit_slave)
21482148
* [`output_buffer_limit_pubsub`](#-redis--instance--output_buffer_limit_pubsub)
21492149
* [`custom_options`](#-redis--instance--custom_options)
2150+
* [`config_dir`](#-redis--instance--config_dir)
21502151

21512152
##### <a name="-redis--instance--activerehashing"></a>`activerehashing`
21522153

@@ -3183,6 +3184,14 @@ hash of custom options, not available as direct parameter.
31833184

31843185
Default value: `{}`
31853186

3187+
##### <a name="-redis--instance--config_dir"></a>`config_dir`
3188+
3189+
Data type: `Stdlib::Absolutepath`
3190+
3191+
3192+
3193+
Default value: `$redis::config_dir`
3194+
31863195
## Functions
31873196

31883197
### <a name="redis--get"></a>`redis::get`

manifests/instance.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@
310310
String[1] $output_buffer_limit_pubsub = $redis::output_buffer_limit_pubsub,
311311
String[1] $conf_template = $redis::conf_template,
312312
Stdlib::Absolutepath $config_file = $redis::config_file,
313+
Stdlib::Absolutepath $config_dir = $redis::config_dir,
313314
Stdlib::Filemode $config_file_mode = $redis::config_file_mode,
314315
Stdlib::Absolutepath $config_file_orig = $redis::config_file_orig,
315316
String[1] $config_group = $redis::config_group,
@@ -427,8 +428,8 @@
427428
$redis_file_name_orig = $config_file_orig
428429
$redis_file_name = $config_file
429430
} else {
430-
$redis_file_name_orig = sprintf('%s/%s.%s', dirname($config_file_orig), $service_name, 'conf.puppet')
431-
$redis_file_name = sprintf('%s/%s.%s', dirname($config_file), $service_name, 'conf')
431+
$redis_file_name_orig = sprintf('%s/%s.%s', $config_dir, $service_name, 'conf.puppet')
432+
$redis_file_name = sprintf('%s/%s.%s', $config_dir, $service_name, 'conf')
432433
}
433434

434435
if $log_dir != $redis::log_dir {

manifests/params.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
$pid_file = '/var/run/redis/redis.pid'
138138
$daemonize = true
139139
$service_name = 'redis'
140+
$service_user = 'redis'
141+
$service_group = 'redis'
140142
$workdir = '/var/db/redis'
141143
$bin_path = '/usr/bin'
142144
$unixsocket = '/var/run/redis/redis.sock'

metadata.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
"9",
7878
"10"
7979
]
80+
},
81+
{
82+
"operatingsystem": "FreeBSD",
83+
"operatingsystemrelease": [
84+
"13",
85+
"14",
86+
"15"
87+
]
8088
}
8189
]
8290
}

spec/classes/redis_spec.rb

Lines changed: 99 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ class { 'redis':
8888
it { is_expected.to compile.with_all_deps }
8989

9090
it do
91-
is_expected.to contain_file("/etc/security/limits.d/#{redis}.conf").with(
92-
'ensure' => 'file',
93-
'owner' => 'root',
94-
'group' => 'root',
95-
'mode' => '0644',
96-
'content' => "#{redis} soft nofile 65536\n#{redis} hard nofile 65536\n",
97-
)
91+
case facts['os']['family']
92+
when 'FreeBSD'
93+
# skip /etc/security/limits.d tests on FreeBSD
94+
else
95+
is_expected.to contain_file("/etc/security/limits.d/#{redis}.conf").with(
96+
'ensure' => 'file',
97+
'owner' => 'root',
98+
'group' => 'root',
99+
'mode' => '0644',
100+
'content' => "#{redis} soft nofile 65536\n#{redis} hard nofile 65536\n",
101+
)
102+
end
98103
end
99104

100105
context 'when not managing service' do
@@ -103,13 +108,18 @@ class { 'redis':
103108
it { is_expected.to compile.with_all_deps }
104109

105110
it do
106-
is_expected.to contain_file("/etc/security/limits.d/#{redis}.conf").with(
107-
'ensure' => 'file',
108-
'owner' => 'root',
109-
'group' => 'root',
110-
'mode' => '0644',
111-
'content' => "#{redis} soft nofile 65536\n#{redis} hard nofile 65536\n",
112-
)
111+
case facts['os']['family']
112+
when 'FreeBSD'
113+
# skip /etc/security/limits.d tests on FreeBSD
114+
else
115+
is_expected.to contain_file("/etc/security/limits.d/#{redis}.conf").with(
116+
'ensure' => 'file',
117+
'owner' => 'root',
118+
'group' => 'root',
119+
'mode' => '0644',
120+
'content' => "#{redis} soft nofile 65536\n#{redis} hard nofile 65536\n",
121+
)
122+
end
113123
end
114124
end
115125
end
@@ -121,13 +131,18 @@ class { 'redis':
121131
it { is_expected.to compile.with_all_deps }
122132

123133
it do
124-
is_expected.to contain_file("/etc/systemd/system/#{service_name}.service.d/limit.conf")
125-
.with_ensure('absent')
126-
127-
is_expected.to contain_systemd__manage_dropin("#{service_name}-90-limits.conf")
128-
.with_service_entry({ 'LimitNOFILE' => 7777 })
129-
.with_ensure('present')
130-
.with_unit("#{service_name}.service")
134+
case facts['os']['family']
135+
when 'FreeBSD'
136+
# skip systemd tests on FreeBSD
137+
else
138+
is_expected.to contain_file("/etc/systemd/system/#{service_name}.service.d/limit.conf")
139+
.with_ensure('absent')
140+
141+
is_expected.to contain_systemd__manage_dropin("#{service_name}-90-limits.conf")
142+
.with_service_entry({ 'LimitNOFILE' => 7777 })
143+
.with_ensure('present')
144+
.with_unit("#{service_name}.service")
145+
end
131146
end
132147
end
133148

@@ -137,7 +152,12 @@ class { 'redis':
137152
it { is_expected.to compile.with_all_deps }
138153

139154
it do
140-
is_expected.not_to contain_systemd__service_limits("#{service_name}.service")
155+
case facts['os']['family']
156+
when 'FreeBSD'
157+
# skip systemd tests on FreeBSD
158+
else
159+
is_expected.not_to contain_systemd__service_limits("#{service_name}.service")
160+
end
141161
end
142162
end
143163
end
@@ -279,9 +299,14 @@ class { 'redis':
279299
end
280300

281301
describe 'with parameter: config_dir_mode' do
282-
let(:params) { { config_dir_mode: '0700' } }
302+
let(:params) do
303+
{
304+
config_dir: '/etc/config_dir',
305+
config_dir_mode: '0700',
306+
}
307+
end
283308

284-
it { is_expected.to contain_file("/etc/#{redis}").with_mode('0700') }
309+
it { is_expected.to contain_file('/etc/config_dir').with_mode('0700') }
285310
end
286311

287312
describe 'with parameter: log_dir_mode' do
@@ -303,15 +328,25 @@ class { 'redis':
303328
end
304329

305330
describe 'with parameter: config_group' do
306-
let(:params) { { config_group: '_VALUE_' } }
331+
let(:params) do
332+
{
333+
config_dir: '/etc/config_dir',
334+
config_group: '_VALUE_',
335+
}
336+
end
307337

308-
it { is_expected.to contain_file("/etc/#{redis}").with_group('_VALUE_') }
338+
it { is_expected.to contain_file('/etc/config_dir').with_group('_VALUE_') }
309339
end
310340

311341
describe 'with parameter: config_owner' do
312-
let(:params) { { config_owner: '_VALUE_' } }
342+
let(:params) do
343+
{
344+
config_dir: '/etc/config_dir',
345+
config_owner: '_VALUE_',
346+
}
347+
end
313348

314-
it { is_expected.to contain_file("/etc/#{redis}").with_owner('_VALUE_') }
349+
it { is_expected.to contain_file('/etc/config_dir').with_owner('_VALUE_') }
315350
end
316351

317352
describe 'with parameter daemonize' do
@@ -1523,32 +1558,44 @@ class { 'redis':
15231558
}
15241559
end
15251560

1526-
it { is_expected.to contain_systemd__unit_file("#{service_name}.service") }
1561+
it do
1562+
case facts['os']['family']
1563+
when 'FreeBSD'
1564+
# skip systemd tests on FreeBSD
1565+
else
1566+
is_expected.to contain_systemd__unit_file("#{service_name}.service")
1567+
end
1568+
end
15271569

15281570
it do
1529-
content = <<-END.gsub(%r{^\s+\|}, '')
1530-
|[Unit]
1531-
|Description=#{redis.capitalize} Advanced key-value store for instance default
1532-
|After=network.target
1533-
|After=network-online.target
1534-
|Wants=network-online.target
1535-
|
1536-
|[Service]
1537-
|RuntimeDirectory=#{service_name}
1538-
|RuntimeDirectoryMode=2755
1539-
|Type=notify
1540-
|ExecStart=/usr/bin/#{redis}-server #{config_file} --supervised systemd --daemonize no
1541-
|ExecStop=/usr/bin/#{redis}-cli -p 6379 shutdown
1542-
|Restart=always
1543-
|User=#{redis}
1544-
|Group=#{redis}
1545-
|LimitNOFILE=65536
1546-
|
1547-
|[Install]
1548-
|WantedBy=multi-user.target
1549-
END
1550-
1551-
is_expected.to contain_systemd__unit_file("#{service_name}.service").with_content(content)
1571+
case facts['os']['family']
1572+
when 'FreeBSD'
1573+
# skip systemd tests on FreeBSD
1574+
else
1575+
content = <<-END.gsub(%r{^\s+\|}, '')
1576+
|[Unit]
1577+
|Description=#{redis.capitalize} Advanced key-value store for instance default
1578+
|After=network.target
1579+
|After=network-online.target
1580+
|Wants=network-online.target
1581+
|
1582+
|[Service]
1583+
|RuntimeDirectory=#{service_name}
1584+
|RuntimeDirectoryMode=2755
1585+
|Type=notify
1586+
|ExecStart=/usr/bin/#{redis}-server #{config_file} --supervised systemd --daemonize no
1587+
|ExecStop=/usr/bin/#{redis}-cli -p 6379 shutdown
1588+
|Restart=always
1589+
|User=#{redis}
1590+
|Group=#{redis}
1591+
|LimitNOFILE=65536
1592+
|
1593+
|[Install]
1594+
|WantedBy=multi-user.target
1595+
END
1596+
1597+
is_expected.to contain_systemd__unit_file("#{service_name}.service").with_content(content)
1598+
end
15521599
end
15531600
end
15541601

spec/defines/instance_spec.rb

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ class { 'redis':
2424
end
2525
end
2626

27+
let(:workdir) do
28+
case facts['os']['family']
29+
when 'FreeBSD'
30+
'/var/db/redis'
31+
else
32+
"/var/lib/#{redis}"
33+
end
34+
end
35+
2736
context 'with app2 title' do
2837
let(:title) { 'app2' }
2938
let(:config_file) do
3039
case facts['os']['family']
31-
when 'RedHat'
32-
if facts['os']['release']['major'].to_i > 8
33-
"/etc/#{redis}/#{redis}-server-app2.conf"
34-
else
35-
"/etc/#{redis}-server-app2.conf"
36-
end
40+
when 'Debian', 'Archlinux'
41+
"/etc/#{redis}/#{redis}-server-app2.conf"
3742
when 'FreeBSD'
3843
'/usr/local/etc/redis/redis-server-app2.conf'
39-
when 'Debian', 'Archlinux'
44+
when 'RedHat'
4045
"/etc/#{redis}/#{redis}-server-app2.conf"
4146
end
4247
end
@@ -45,18 +50,30 @@ class { 'redis':
4550
is_expected.to contain_file("#{config_file}.puppet")
4651
.with_content(%r{^bind 127.0.0.1})
4752
.with_content(%r{^logfile /var/log/#{redis}/#{redis}-server-app2\.log})
48-
.with_content(%r{^dir /var/lib/#{redis}/#{redis}-server-app2})
53+
.with_content(%r{^dir #{workdir}/#{redis}-server-app2})
4954
.with_content(%r{^unixsocket /var/run/#{redis}-server-app2/#{redis}\.sock})
5055
end
5156

52-
it { is_expected.to contain_file("/var/lib/#{redis}/#{redis}-server-app2") }
57+
it { is_expected.to contain_file("#{workdir}/#{redis}-server-app2") }
5358

5459
it do
55-
is_expected.to contain_file("/etc/systemd/system/#{redis}-server-app2.service")
56-
.with_content(%r{ExecStart=/usr/bin/#{redis}-server #{config_file}})
60+
case facts['os']['family']
61+
when 'FreeBSD'
62+
# skip systemd tests on FreeBSD
63+
else
64+
is_expected.to contain_file("/etc/systemd/system/#{redis}-server-app2.service")
65+
.with_content(%r{ExecStart=/usr/bin/#{redis}-server #{config_file}})
66+
end
5767
end
5868

59-
it { is_expected.to contain_service("#{redis}-server-app2.service").with_ensure(true).with_enable(true) }
69+
it do
70+
case facts['os']['family']
71+
when 'FreeBSD'
72+
# skip systemd tests on FreeBSD
73+
else
74+
is_expected.to contain_service("#{redis}-server-app2.service").with_ensure(true).with_enable(true)
75+
end
76+
end
6077
end
6178

6279
context 'with custom options' do

0 commit comments

Comments
 (0)