1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
require 'spec_helper'
describe 'systemd::dropin_file' do
context 'supported operating systems' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) { facts }
let(:title) { 'test.conf' }
let(:params) do
{
unit: 'test.service',
content: 'random stuff',
}
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d").with(
ensure: 'directory',
recurse: 'true',
purge: 'true',
selinux_ignore_defaults: false,
)
}
it {
is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with(
ensure: 'file',
content: %r{#{params[:content]}},
mode: '0444',
selinux_ignore_defaults: false,
)
}
context 'with selinux_ignore_defaults set to true' do
let(:params) do
super().merge(selinux_ignore_defaults: true)
end
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d").with_selinux_ignore_defaults(true) }
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with_selinux_ignore_defaults(true) }
end
context 'with daemon_reload => lazy (default)' do
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").that_notifies('Class[systemd::systemctl::daemon_reload]') }
it { is_expected.not_to create_exec("#{params[:unit]}-systemctl-daemon-reload") }
end
context 'with daemon_reload => eager' do
let(:params) do
super().merge(daemon_reload: 'eager')
end
it { is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").that_notifies("Exec[#{params[:unit]}-systemctl-daemon-reload]") }
it { is_expected.to create_exec("#{params[:unit]}-systemctl-daemon-reload") }
end
context 'with a bad unit type' do
let(:title) { 'test.badtype' }
it {
expect {
is_expected.to compile.with_all_deps
}.to raise_error(%r{expects a match for Systemd::Dropin})
}
end
context 'with a bad unit type containing a slash' do
let(:title) { 'test/bad.conf' }
it {
expect {
is_expected.to compile.with_all_deps
}.to raise_error(%r{expects a match for Systemd::Dropin})
}
end
context 'with another drop-in file with the same filename (and content)' do
let(:default_params) do
{
filename: 'longer-timeout.conf',
content: 'random stuff',
}
end
# Create drop-in file longer-timeout.conf for unit httpd.service
let(:pre_condition) do
"systemd::dropin_file { 'httpd_longer-timeout':
filename => '#{default_params[:filename]}',
unit => 'httpd.service',
content => '#{default_params[:context]}',
}"
end
#
# Create drop-in file longer-timeout.conf for unit ftp.service
let(:title) { 'ftp_longer-timeout' }
let(:params) do
default_params.merge(unit: 'ftp.service')
end
it {
is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{params[:filename]}").with(
ensure: 'file',
content: %r{#{params[:content]}},
mode: '0444',
)
}
end
context 'with sensitve content' do
let(:title) { 'sensitive.conf' }
let(:params) do
{
unit: 'sensitive.service',
content: RSpec::Puppet::RawString.new("Sensitive('TEST_CONTENT')"),
}
end
it {
is_expected.to create_file("/etc/systemd/system/#{params[:unit]}.d/#{title}").with(
ensure: 'file',
content: sensitive('TEST_CONTENT'),
)
}
end
end
end
end
end
|