Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional hash parameters for defined types #223

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ This module allows triggering systemd commands once for all modules
The following parameters are available in the `systemd` class:

* [`service_limits`](#service_limits)
* [`networks`](#networks)
* [`timers`](#timers)
* [`tmpfiles`](#tmpfiles)
* [`unit_files`](#unit_files)
* [`manage_resolved`](#manage_resolved)
* [`resolved_ensure`](#resolved_ensure)
* [`dns`](#dns)
Expand Down Expand Up @@ -100,13 +104,45 @@ The following parameters are available in the `systemd` class:

##### <a name="service_limits"></a>`service_limits`

Data type: `Hash[String,Hash[String, Any]]`
Data type: `Hash[String[1],Hash[String[1], Any]]`

May be passed a resource hash suitable for passing directly into the
``create_resources()`` function as called on ``systemd::service_limits``

Default value: `{}`

##### <a name="networks"></a>`networks`

Data type: `Hash[String[1],Hash[String[1], Any]]`

Hash of `systemd::network` resources

Default value: `{}`

##### <a name="timers"></a>`timers`

Data type: `Hash[String[1],Hash[String[1], Any]]`

Hash of `systemd::timer` resources

Default value: `{}`

##### <a name="tmpfiles"></a>`tmpfiles`

Data type: `Hash[String[1],Hash[String[1], Any]]`

Hash of `systemd::tmpfile` resources

Default value: `{}`

##### <a name="unit_files"></a>`unit_files`

Data type: `Hash[String[1],Hash[String[1], Any]]`

Hash of `systemd::unit_file` resources

Default value: `{}`

##### <a name="manage_resolved"></a>`manage_resolved`

Data type: `Boolean`
Expand Down
44 changes: 42 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
# May be passed a resource hash suitable for passing directly into the
# ``create_resources()`` function as called on ``systemd::service_limits``
#
# @param networks
# Hash of `systemd::network` resources
#
# @param timers
# Hash of `systemd::timer` resources
#
# @param tmpfiles
# Hash of `systemd::tmpfile` resources
#
# @param unit_files
# Hash of `systemd::unit_file` resources
#
# @param manage_resolved
# Manage the systemd resolver
#
Expand Down Expand Up @@ -130,7 +142,11 @@
#
class systemd (
Hash[String,String] $accounting,
Hash[String,Hash[String, Any]] $service_limits = {},
Hash[String[1],Hash[String[1], Any]] $service_limits = {},
Hash[String[1],Hash[String[1], Any]] $networks = {},
Hash[String[1],Hash[String[1], Any]] $timers = {},
Hash[String[1],Hash[String[1], Any]] $tmpfiles = {},
Hash[String[1],Hash[String[1], Any]] $unit_files = {},
Boolean $manage_resolved = false,
Enum['stopped','running'] $resolved_ensure = 'running',
Optional[Variant[Array[String],String]] $dns = undef,
Expand Down Expand Up @@ -168,7 +184,31 @@
Hash $dropin_files = {},
Hash $udev_rules = {},
) {
create_resources('systemd::service_limits', $service_limits)
$service_limits.each |$service_limit, $service_limit_data| {
systemd::service_limits { $service_limit:
* => $service_limit_data,
}
}
$networks.each |$network, $network_data| {
systemd::network { $network:
* => $network_data,
}
}
$timers.each |$timer, $timer_data| {
systemd::timer { $timer:
* => $timer_data,
}
}
$tmpfiles.each |$tmpfile, $tmpfile_data| {
systemd::tmpfile { $tmpfile:
* => $tmpfile_data,
}
}
$unit_files.each |$unit_file, $unit_file_data| {
systemd::unit_file { $unit_file:
* => $unit_file_data,
}
}

if $manage_resolved and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-resolved.service'] {
contain systemd::resolved
Expand Down
58 changes: 58 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,65 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__service_limits('openstack-nova-compute.service').with_limits('LimitNOFILE' => 32_768) }
end
context 'when passing networks' do
let :params do
{
networks: { 'uplink.network' => { 'content' => 'foo' }, 'uplink.netdev' => { 'content' => 'bar' }, },
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__network('uplink.network').with_content('foo') }
it { is_expected.to contain_systemd__network('uplink.netdev').with_content('bar') }
it { is_expected.to contain_file('/etc/systemd/network/uplink.network') }
it { is_expected.to contain_file('/etc/systemd/network/uplink.netdev') }
it { is_expected.to have_systemd__network_resource_count(2) }
end
context 'when passing timers' do
let :params do
{
timers: { 'first.timer' => { 'timer_content' => 'foo' }, 'second.timer' => { 'timer_content' => 'bar' }, },
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__timer('first.timer').with_timer_content('foo') }
it { is_expected.to contain_systemd__timer('second.timer').with_timer_content('bar') }
it { is_expected.to contain_systemd__unit_file('first.timer').with_content('foo') }
it { is_expected.to contain_systemd__unit_file('second.timer').with_content('bar') }
it { is_expected.to contain_file('/etc/systemd/system/first.timer') }
it { is_expected.to contain_file('/etc/systemd/system/second.timer') }
it { is_expected.to have_systemd__timer_resource_count(2) }
it { is_expected.to have_systemd__unit_file_resource_count(2) }
end
context 'when passing tmpfiles' do
let :params do
{
tmpfiles: { 'first_tmpfile.conf' => { 'content' => 'foo' }, 'second_tmpfile.conf' => { 'content' => 'bar' }, },
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__tmpfile('first_tmpfile.conf').with_content('foo') }
it { is_expected.to contain_systemd__tmpfile('second_tmpfile.conf').with_content('bar') }
it { is_expected.to contain_file('/etc/tmpfiles.d/first_tmpfile.conf') }
it { is_expected.to contain_file('/etc/tmpfiles.d/second_tmpfile.conf') }
it { is_expected.to have_systemd__tmpfile_resource_count(2) }
end
context 'when passing unit_files' do
let :params do
{
unit_files: { 'first.service' => { 'content' => 'foo' }, 'second.service' => { 'content' => 'bar' }, },
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__unit_file('first.service').with_content('foo') }
it { is_expected.to contain_systemd__unit_file('second.service').with_content('bar') }
it { is_expected.to contain_file('/etc/systemd/system/first.service') }
it { is_expected.to contain_file('/etc/systemd/system/second.service') }
it { is_expected.to have_systemd__unit_file_resource_count(2) }
end
context 'when managing Accounting options' do
let :params do
{
Expand Down