Skip to content

Commit

Permalink
Add parameter to enable automatic udev rules reload
Browse files Browse the repository at this point in the history
notify will be converted to an Array, if udev_reload enabled
  • Loading branch information
deric committed Aug 27, 2024
1 parent e8e1588 commit 16d9853
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The following parameters are available in the `systemd` class:
* [`udev_resolve_names`](#-systemd--udev_resolve_names)
* [`udev_timeout_signal`](#-systemd--udev_timeout_signal)
* [`udev_rules`](#-systemd--udev_rules)
* [`udev_reload`](#-systemd--udev_reload)
* [`machine_info_settings`](#-systemd--machine_info_settings)
* [`manage_logind`](#-systemd--manage_logind)
* [`logind_settings`](#-systemd--logind_settings)
Expand Down Expand Up @@ -525,6 +526,14 @@ Config Hash that is used to generate instances of our

Default value: `{}`

##### <a name="-systemd--udev_reload"></a>`udev_reload`

Data type: `Boolean`

Whether udev rules should be automatically reloaded upon change.

Default value: `false`

##### <a name="-systemd--machine_info_settings"></a>`machine_info_settings`

Data type: `Systemd::MachineInfoSettings`
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
# Config Hash that is used to generate instances of our
# `udev::rule` define.
#
# @param udev_reload
# Whether udev rules should be automatically reloaded upon change.
#
# @param machine_info_settings
# Settings to place into /etc/machine-info (hostnamectl)
#
Expand Down Expand Up @@ -261,6 +264,7 @@
Optional[Integer] $udev_event_timeout = undef,
Optional[Enum['early', 'late', 'never']] $udev_resolve_names = undef,
Optional[Variant[Integer,String]] $udev_timeout_signal = undef,
Boolean $udev_reload = false,
Boolean $manage_logind = false,
Systemd::LogindSettings $logind_settings = {},
Boolean $manage_all_network_files = false,
Expand Down
12 changes: 11 additions & 1 deletion manifests/udev/rule.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@
fail("systemd::udev::rule - ${name}: param rules is empty, you need to pass rules")
}

if $systemd::udev_reload {
if $notify_services =~ Array {
$_notify = $notify_services << 'Exec[systemd-udev_reload]'
} else {
$_notify = [$notify_services, 'Exec[systemd-udev_reload]']
}
} else {
$_notify = $notify_services
}

file { join([$path, $name], '/'):
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0444',
notify => $notify_services << 'Exec[systemd-udev_reload]',
notify => $_notify,
selinux_ignore_defaults => $selinux_ignore_defaults,
content => epp("${module_name}/udev_rule.epp", { 'rules' => $rules }),
}
Expand Down
1 change: 0 additions & 1 deletion manifests/udevd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,4 @@
refreshonly => true,
path => $facts['path'],
}

}
3 changes: 3 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@
let(:params) do
{
manage_udevd: true,
udev_reload: true,
udev_log: 'daemon',
udev_children_max: 1,
udev_exec_delay: 2,
Expand All @@ -664,6 +665,7 @@
{
manage_udevd: true,
udev_purge_rules: true,
udev_reload: true,
}
end

Expand Down Expand Up @@ -702,6 +704,7 @@
])
}

it { is_expected.to contain_exec('systemd-udev_reload') }
it { is_expected.to contain_file('/etc/udev/rules.d/example_raw.rules').that_notifies('Exec[systemd-udev_reload]') }
end

Expand Down
19 changes: 18 additions & 1 deletion spec/defines/udev_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,24 @@ class { 'systemd': manage_udevd => true, manage_journald => false }
it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify([]) }
end

describe 'ensured absent with notify' do
describe 'ensured absent with automatic reload' do
let(:pre_condition) do
<<-PUPPET
class { 'systemd': manage_udevd => true, manage_journald => false, udev_reload => true }
PUPPET
end
let(:params) do
{
ensure: 'absent',
}
end

it { is_expected.to compile.with_all_deps }

it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) }
end

describe 'ensured absent with custom notify' do
let(:params) { { ensure: 'absent', notify_services: 'Service[systemd-udevd]', } }

it { is_expected.to compile.with_all_deps }
Expand Down

0 comments on commit 16d9853

Please sign in to comment.