Skip to content

Commit

Permalink
Install systemd-networkd package, if any
Browse files Browse the repository at this point in the history
On Red Hat systems networkd is packaged as systemd-networkd. In
particular:

* EL7
* EL8/EL9 shipped in EPEL
* Fedora since 33
  • Loading branch information
ekohl committed Oct 18, 2023
1 parent 28a3093 commit 2818ce7
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ The following parameters are available in the `systemd` class:
* [`use_stub_resolver`](#-systemd--use_stub_resolver)
* [`manage_networkd`](#-systemd--manage_networkd)
* [`networkd_ensure`](#-systemd--networkd_ensure)
* [`networkd_package`](#-systemd--networkd_package)
* [`manage_timesyncd`](#-systemd--manage_timesyncd)
* [`timesyncd_ensure`](#-systemd--timesyncd_ensure)
* [`timesyncd_package`](#-systemd--timesyncd_package)
Expand Down Expand Up @@ -321,6 +322,14 @@ The state that the ``networkd`` service should be in

Default value: `'running'`

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

Data type: `Optional[String[1]]`

Name of the package required for systemd-networkd, if any

Default value: `undef`

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

Data type: `Boolean`
Expand Down
2 changes: 2 additions & 0 deletions data/RedHat-family.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
systemd::networkd_package: systemd-networkd
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
# @param networkd_ensure
# The state that the ``networkd`` service should be in
#
# @param networkd_package
# Name of the package required for systemd-networkd, if any
#
# @param manage_timesyncd
# Manage the systemd timesyncd daemon
#
Expand Down Expand Up @@ -201,6 +204,7 @@
Boolean $use_stub_resolver = false,
Boolean $manage_networkd = false,
Enum['stopped','running'] $networkd_ensure = 'running',
Optional[String[1]] $networkd_package = undef,
Boolean $manage_timesyncd = false,
Enum['stopped','running'] $timesyncd_ensure = 'running',
Optional[String[1]] $timesyncd_package = undef,
Expand Down Expand Up @@ -281,6 +285,7 @@

if $manage_networkd and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-networkd.service'] {
contain systemd::networkd
Class['systemd::install'] -> Class['systemd::networkd']
}

if $manage_timesyncd and $facts['systemd_internal_services'] and $facts['systemd_internal_services']['systemd-timesyncd.service'] {
Expand Down
6 changes: 6 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# @api private
#
class systemd::install {
if $systemd::manage_networkd and $systemd::networkd_package {
package { $systemd::networkd_package:
ensure => present,
}
}

if $systemd::manage_resolved and $systemd::resolved_package {
package { $systemd::resolved_package:
ensure => present,
Expand Down
52 changes: 52 additions & 0 deletions spec/acceptance/networkd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'systemd with manage_networkd true' do
has_package = fact('os.family') == 'RedHat'

context 'configure systemd-networkd' do
let(:manifest) do
<<~PUPPET
class { 'systemd':
manage_networkd => true,
}
PUPPET
end

it 'works idempotently with no errors' do
apply_manifest(manifest, catch_failures: true)
# Package systemd-networkd needs to be installed before fact $facts['internal_services'] is set
apply_manifest(manifest, catch_failures: true) if has_package
apply_manifest(manifest, catch_changes: true)
end

describe service('systemd-networkd') do
it { is_expected.to be_running }
it { is_expected.to be_enabled }
end

it { expect(package('systemd-networkd')).to be_installed } if has_package
end

context 'configure systemd stopped' do
let(:manifest) do
<<~PUPPET
class { 'systemd':
manage_networkd => true,
networkd_ensure => 'stopped',
}
PUPPET
end

it 'works idempotently with no errors' do
apply_manifest(manifest, catch_failures: true)
apply_manifest(manifest, catch_changes: true)
end

describe service('systemd-networkd') do
it { is_expected.not_to be_running }
it { is_expected.not_to be_enabled }
end
end
end
7 changes: 7 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
it { is_expected.not_to create_service('systemd-resolved') }
it { is_expected.not_to create_service('systemd-networkd') }
it { is_expected.not_to create_service('systemd-timesyncd') }
it { is_expected.not_to contain_package('systemd-networkd') }
it { is_expected.not_to contain_package('systemd-timesyncd') }
it { is_expected.not_to contain_package('systemd-resolved') }
it { is_expected.not_to contain_class('systemd::coredump') }
Expand All @@ -39,6 +40,12 @@
it { is_expected.to create_service('systemd-networkd').with_enable(true) }
it { is_expected.not_to contain_file('/etc/systemd/network') }

if facts[:os]['family'] == 'RedHat'
it { is_expected.to contain_package('systemd-networkd') }
else
it { is_expected.not_to contain_package('systemd-networkd') }
end

case [facts[:os]['family'], facts[:os]['release']['major']]
when %w[RedHat 7], %w[RedHat 9]
it { is_expected.to contain_package('systemd-resolved') }
Expand Down

0 comments on commit 2818ce7

Please sign in to comment.