Skip to content

Commit be5dd55

Browse files
committed
Add support for .link units and dropins
Addition of link unit support to `systemd::manage_unit` and `systemd::manage_dropin`. * https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html This only adds a skeleton of the parameters that can be set. More will be needed to be usable.
1 parent c362496 commit be5dd55

File tree

12 files changed

+186
-2
lines changed

12 files changed

+186
-2
lines changed

REFERENCE.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
8181
* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
8282
* [`Systemd::Unit::Install`](#Systemd--Unit--Install): Possible keys for the [Install] section of a unit file
83+
* [`Systemd::Unit::Link`](#Systemd--Unit--Link): Possible keys for the [Link] section of a unit file
84+
* [`Systemd::Unit::Match`](#Systemd--Unit--Match): Possible keys for the [Match] section of a unit file
8385
* [`Systemd::Unit::Mount`](#Systemd--Unit--Mount): Possible keys for the [Mount] section of a unit file
8486
* [`Systemd::Unit::Path`](#Systemd--Unit--Path): Possible keys for the [Path] section of a unit file
8587
* [`Systemd::Unit::Percent`](#Systemd--Unit--Percent): Systemd definition of a percentage
@@ -1127,6 +1129,8 @@ The following parameters are available in the `systemd::manage_dropin` defined t
11271129
* [`socket_entry`](#-systemd--manage_dropin--socket_entry)
11281130
* [`mount_entry`](#-systemd--manage_dropin--mount_entry)
11291131
* [`swap_entry`](#-systemd--manage_dropin--swap_entry)
1132+
* [`match_entry`](#-systemd--manage_dropin--match_entry)
1133+
* [`link_entry`](#-systemd--manage_dropin--link_entry)
11301134

11311135
##### <a name="-systemd--manage_dropin--unit"></a>`unit`
11321136

@@ -1286,6 +1290,22 @@ key value pairs for the [Swap] section of the unit file
12861290

12871291
Default value: `undef`
12881292

1293+
##### <a name="-systemd--manage_dropin--match_entry"></a>`match_entry`
1294+
1295+
Data type: `Optional[Systemd::Unit::Match]`
1296+
1297+
kev value pairs for [Match] section of the unit file.
1298+
1299+
Default value: `undef`
1300+
1301+
##### <a name="-systemd--manage_dropin--link_entry"></a>`link_entry`
1302+
1303+
Data type: `Optional[Systemd::Unit::Link]`
1304+
1305+
kev value pairs for [Link] section of the unit file.
1306+
1307+
Default value: `undef`
1308+
12891309
### <a name="systemd--manage_unit"></a>`systemd::manage_unit`
12901310

12911311
Generate unit file from template
@@ -1460,6 +1480,8 @@ The following parameters are available in the `systemd::manage_unit` defined typ
14601480
* [`socket_entry`](#-systemd--manage_unit--socket_entry)
14611481
* [`mount_entry`](#-systemd--manage_unit--mount_entry)
14621482
* [`swap_entry`](#-systemd--manage_unit--swap_entry)
1483+
* [`match_entry`](#-systemd--manage_unit--match_entry)
1484+
* [`link_entry`](#-systemd--manage_unit--link_entry)
14631485

14641486
##### <a name="-systemd--manage_unit--name"></a>`name`
14651487

@@ -1643,6 +1665,22 @@ kev value pairs for [Swap] section of the unit file.
16431665

16441666
Default value: `undef`
16451667

1668+
##### <a name="-systemd--manage_unit--match_entry"></a>`match_entry`
1669+
1670+
Data type: `Optional[Systemd::Unit::Match]`
1671+
1672+
kev value pairs for [Match] section of the unit file.
1673+
1674+
Default value: `undef`
1675+
1676+
##### <a name="-systemd--manage_unit--link_entry"></a>`link_entry`
1677+
1678+
Data type: `Optional[Systemd::Unit::Link]`
1679+
1680+
kev value pairs for [Link] section of the unit file.
1681+
1682+
Default value: `undef`
1683+
16461684
### <a name="systemd--modules_load"></a>`systemd::modules_load`
16471685

16481686
Creates a modules-load.d drop file
@@ -3123,7 +3161,7 @@ custom datatype that validates different filenames for systemd units and unit te
31233161
* **See also**
31243162
* https://www.freedesktop.org/software/systemd/man/systemd.unit.html
31253163

3126-
Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]`
3164+
Alias of `Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|link)$/]`
31273165

31283166
### <a name="Systemd--Unit--Amount"></a>`Systemd::Unit::Amount`
31293167

@@ -3166,6 +3204,36 @@ Struct[{
31663204
}]
31673205
```
31683206

3207+
### <a name="Systemd--Unit--Link"></a>`Systemd::Unit::Link`
3208+
3209+
Possible keys for the [Link] section of a unit file
3210+
3211+
* **See also**
3212+
* https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html
3213+
3214+
Alias of
3215+
3216+
```puppet
3217+
Struct[{
3218+
Optional['MTUBytes'] => Integer[0],
3219+
}]
3220+
```
3221+
3222+
### <a name="Systemd--Unit--Match"></a>`Systemd::Unit::Match`
3223+
3224+
Possible keys for the [Match] section of a unit file
3225+
3226+
* **See also**
3227+
* https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html
3228+
3229+
Alias of
3230+
3231+
```puppet
3232+
Struct[{
3233+
Optional['Driver'] => String[1],
3234+
}]
3235+
```
3236+
31693237
### <a name="Systemd--Unit--Mount"></a>`Systemd::Unit::Mount`
31703238

31713239
Possible keys for the [Mount] section of a unit file

manifests/manage_dropin.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
# @param socket_entry key value pairs for the [Socket] section of the unit file
9191
# @param mount_entry key value pairs for the [Mount] section of the unit file
9292
# @param swap_entry key value pairs for the [Swap] section of the unit file
93+
# @param match_entry kev value pairs for [Match] section of the unit file.
94+
# @param link_entry kev value pairs for [Link] section of the unit file.
9395
#
9496
define systemd::manage_dropin (
9597
Systemd::Unit $unit,
@@ -112,6 +114,8 @@
112114
Optional[Systemd::Unit::Socket] $socket_entry = undef,
113115
Optional[Systemd::Unit::Mount] $mount_entry = undef,
114116
Optional[Systemd::Unit::Swap] $swap_entry = undef,
117+
Optional[Systemd::Unit::Link] $link_entry = undef,
118+
Optional[Systemd::Unit::Match] $match_entry = undef,
115119
) {
116120
if $timer_entry and $unit !~ Pattern['^[^/]+\.timer'] {
117121
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} timer_entry is only valid for timer units")
@@ -137,6 +141,14 @@
137141
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} mount_entry is only valid for swap units")
138142
}
139143

144+
if $link_entry and $unit !~ Pattern['^[^/]+\.link'] {
145+
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} link_entry is only valid for link units")
146+
}
147+
148+
if $match_entry and $unit !~ Pattern['^[^/]+\.link'] {
149+
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} match_entry is only valid for link units")
150+
}
151+
140152
systemd::dropin_file { $name:
141153
ensure => $ensure,
142154
filename => $filename,
@@ -159,6 +171,8 @@
159171
'socket_entry' => $socket_entry,
160172
'mount_entry' => $mount_entry,
161173
'swap_entry' => $swap_entry,
174+
'match_entry' => $match_entry,
175+
'link_entry' => $link_entry,
162176
}),
163177
}
164178
}

manifests/manage_unit.pp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@
154154
# @param socket_entry kev value paors for [Socket] section of the unit file.
155155
# @param mount_entry kev value pairs for [Mount] section of the unit file.
156156
# @param swap_entry kev value pairs for [Swap] section of the unit file.
157+
# @param match_entry kev value pairs for [Match] section of the unit file.
158+
# @param link_entry kev value pairs for [Link] section of the unit file.
157159
#
158160
define systemd::manage_unit (
159161
Enum['present', 'absent'] $ensure = 'present',
@@ -178,6 +180,8 @@
178180
Optional[Systemd::Unit::Socket] $socket_entry = undef,
179181
Optional[Systemd::Unit::Mount] $mount_entry = undef,
180182
Optional[Systemd::Unit::Swap] $swap_entry = undef,
183+
Optional[Systemd::Unit::Link] $link_entry = undef,
184+
Optional[Systemd::Unit::Match] $match_entry = undef,
181185
) {
182186
assert_type(Systemd::Unit, $name)
183187

@@ -205,6 +209,14 @@
205209
fail("Systemd::Manage_unit[${name}]: swap_entry is only valid for swap units")
206210
}
207211

212+
if $link_entry and $name !~ Pattern['^[^/]+\.link'] {
213+
fail("Systemd::Manage_unit[${name}]: link_entry is only valid for link units")
214+
}
215+
216+
if $match_entry and $name !~ Pattern['^[^/]+\.link'] {
217+
fail("Systemd::Manage_unit[${name}]: mantch_entry is only valid for link units")
218+
}
219+
208220
if $ensure != 'absent' and $name =~ Pattern['^[^/]+\.service'] and !$service_entry {
209221
fail("Systemd::Manage_unit[${name}]: service_entry is required for service units")
210222
}
@@ -232,6 +244,8 @@
232244
'socket_entry' => $socket_entry,
233245
'mount_entry' => $mount_entry,
234246
'swap_entry' => $swap_entry,
247+
'match_entry' => $match_entry,
248+
'link_entry' => $link_entry,
235249
}),
236250
}
237251
}

spec/defines/manage_dropin_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,31 @@
259259
with_content(%r{^ListenMessageQueue=/panic$})
260260
}
261261
end
262+
263+
context 'on a link unit dropin' do
264+
let(:params) do
265+
{
266+
unit: 'wireless.link',
267+
match_entry: {
268+
'Driver' => 'brcmsmac',
269+
},
270+
link_entry: {
271+
'MTUBytes' => 1450,
272+
}
273+
}
274+
end
275+
276+
it { is_expected.to compile.with_all_deps }
277+
278+
it {
279+
is_expected.to contain_systemd__dropin_file('foobar.conf').
280+
with_unit('wireless.link').
281+
with_content(%r{^\[Match\]$}).
282+
with_content(%r{^Driver=brcmsmac$}).
283+
with_content(%r{^\[Link\]$}).
284+
with_content(%r{^MTUBytes=1450$})
285+
}
286+
end
262287
end
263288
end
264289
end

spec/defines/manage_unit_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,30 @@
260260
}
261261
end
262262

263+
context 'on a link unit' do
264+
let(:title) { '15-wireless.link' }
265+
let(:params) do
266+
{
267+
match_entry: {
268+
'Driver' => 'brcmsmac',
269+
},
270+
link_entry: {
271+
'MTUBytes' => 1450,
272+
}
273+
}
274+
end
275+
276+
it { is_expected.to compile.with_all_deps }
277+
278+
it {
279+
is_expected.to contain_systemd__unit_file('15-wireless.link').
280+
with_content(%r{^\[Match\]$}).
281+
with_content(%r{^Driver=brcmsmac$}).
282+
with_content(%r{^\[Link\]$}).
283+
with_content(%r{^MTUBytes=1450$})
284+
}
285+
end
286+
263287
context 'on a path unit' do
264288
let(:title) { 'etc-passwd.path' }
265289

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Systemd::Unit::Link' do
6+
context 'with a key of What can have thing to link' do
7+
it { is_expected.to allow_value({ 'MTUBytes' => 1024 }) }
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Systemd::Unit::Match' do
6+
context 'with a key of What can have thing to link' do
7+
it { is_expected.to allow_value({ 'Driver' => 'brcmsmac' }) }
8+
end
9+
end

spec/type_aliases/unit_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
context 'with a permitted unit name' do
77
[
88
'foo.service',
9+
'25-wireless.link',
910
'foo.socket',
1011
1112

templates/unit_file.epp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Optional[Hash] $socket_entry,
99
Optional[Hash] $mount_entry,
1010
Optional[Hash] $swap_entry,
11+
Optional[Hash] $match_entry,
12+
Optional[Hash] $link_entry,
1113
| -%>
1214
<%-
1315

@@ -24,6 +26,8 @@
2426
'Mount',
2527
'Swap',
2628
'Install',
29+
'Match',
30+
'Link',
2731
]
2832

2933
# Directives which are pair of items to be expressed as a space seperated pair.

types/unit.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# @summary custom datatype that validates different filenames for systemd units and unit templates
22
# @see https://www.freedesktop.org/software/systemd/man/systemd.unit.html
3-
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope)$/]
3+
type Systemd::Unit = Pattern[/^[a-zA-Z0-9:\-_.\\@%]+\.(service|socket|device|mount|automount|swap|target|path|timer|slice|scope|link)$/]

types/unit/link.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @summary Possible keys for the [Link] section of a unit file
2+
# @see https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html
3+
#
4+
type Systemd::Unit::Link = Struct[
5+
{
6+
Optional['MTUBytes'] => Integer[0],
7+
}
8+
]

types/unit/match.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @summary Possible keys for the [Match] section of a unit file
2+
# @see https://www.freedesktop.org/software/systemd/man/latest/systemd.link.html
3+
#
4+
type Systemd::Unit::Match = Struct[
5+
{
6+
Optional['Driver'] => String[1],
7+
}
8+
]

0 commit comments

Comments
 (0)