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 88efbb7
Show file tree
Hide file tree
Showing 6 changed files with 41 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
15 changes: 14 additions & 1 deletion spec/defines/udev_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,20 @@ 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(:params) do
{
ensure: 'absent',
udev_reload: true,
}
end

it { is_expected.to compile.with_all_deps }

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on debian-11-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on debian-12-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on ubuntu-20.04-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on ubuntu-22.04-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on sles-12-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on debian-11-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on debian-12-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on ubuntu-20.04-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on ubuntu-22.04-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 99 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on sles-12-x86_64 ensured absent with automatic reload is expected to compile into a catalogue without dependency cycles Failure/Error: it { is_expected.to compile.with_all_deps } error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

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

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on debian-11-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on debian-12-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on ubuntu-20.04-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on ubuntu-22.04-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

systemd::udev::rule supported operating systems on sles-12-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az985-468.4j5qjbg331oedl4sqeow5vdphg.cx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on debian-11-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on debian-12-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on ubuntu-20.04-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on ubuntu-22.04-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net

Check failure on line 101 in spec/defines/udev_rules_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

systemd::udev::rule supported operating systems on sles-12-x86_64 ensured absent with automatic reload is expected to contain File[/etc/udev/rules.d/test.rules] with ensure => "absent" and notify => ["Exec[systemd-udev_reload]"] Failure/Error: it { is_expected.to contain_file("/etc/udev/rules.d/#{title}").with_ensure('absent').with_notify(['Exec[systemd-udev_reload]']) } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Resource Statement, Systemd::Udev::Rule[test.rules]: has no parameter named 'udev_reload' (line: 5) on node fv-az658-240.lxhe5nczbbeupcbb3gjj1uzxzg.dx.internal.cloudapp.net
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 88efbb7

Please sign in to comment.