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

Install systemd-networkd package, if any #380

Merged
merged 2 commits into from
Oct 29, 2023
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
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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 @@ -330,6 +331,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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
4 changes: 3 additions & 1 deletion hiera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ hierarchy:
- name: 'Distribution Name'
path: '%{facts.os.name}.yaml'
- name: 'OS Family Major Version'
path: '%{facts.os.family}-%{facts.os.release.major}.yaml'
path: '%{facts.os.family}-family-%{facts.os.release.major}.yaml'
- name: 'OS Family'
path: '%{facts.os.family}-family.yaml'
- name: 'common'
path: 'common.yaml'
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,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 @@ -205,6 +208,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 @@ -285,6 +289,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
55 changes: 55 additions & 0 deletions spec/acceptance/networkd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'systemd with manage_networkd true' do
Copy link
Member Author

@ekohl ekohl Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we skip this on EL8 & EL9, since we don't install EPEL?

Also, OracleLinux 7 looks messed up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with skipping or installing epel. and I think we should remove OL7 from metadata.json, their repo is broken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented: it now installs EPEL

has_package = fact('os.family') == 'RedHat'

# On Enterprise Linux 8 & 9 the package is shipped in EPEL
before { install_package(default, 'epel-release') if has_package && %w[8 9].include?(fact('os.release.major')) }

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