Skip to content

Commit 1496772

Browse files
committed
Fix bugs, add spec tests and CI workflow
- Fix missing mark/type_of_service in routing_policy across all 9 templates - Fix trailing space in tunnels.pp checksums enum - Fix incomplete wakeonwlan enum in wifis.pp - Fix learn_packet_interval type in bonds.pp (String -> Variant[Integer, Float]) - Add spec tests for all defines and the main class - Add GitHub Actions workflow for validation and unit tests (Puppet 7/8) - Enable stdlib and concat fixture dependencies
1 parent 866073b commit 1496772

24 files changed

Lines changed: 1162 additions & 4 deletions

.fixtures.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
---
44
fixtures:
55
forge_modules:
6-
# stdlib: "puppetlabs/stdlib"
6+
stdlib: "puppetlabs/stdlib"
7+
concat: "puppetlabs/concat"

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Puppet Tests
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
push:
7+
branches: [master]
8+
9+
jobs:
10+
validate:
11+
name: Validate
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install PDK
16+
run: |
17+
wget -q https://apt.puppet.com/puppet-tools-release-jammy.deb
18+
sudo dpkg -i puppet-tools-release-jammy.deb
19+
sudo apt-get update -qq
20+
sudo apt-get install -y pdk
21+
- name: PDK Validate
22+
run: pdk validate --parallel
23+
24+
unit-test:
25+
name: Unit Tests (Puppet ${{ matrix.puppet }})
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
puppet: ['7', '8']
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Install PDK
34+
run: |
35+
wget -q https://apt.puppet.com/puppet-tools-release-jammy.deb
36+
sudo dpkg -i puppet-tools-release-jammy.deb
37+
sudo apt-get update -qq
38+
sudo apt-get install -y pdk
39+
- name: Run Unit Tests
40+
run: pdk test unit --puppet-version=${{ matrix.puppet }}

manifests/bonds.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
Optional['packets_per_member'] => Integer,
328328
Optional['primary_reselect_policy'] => Enum['always', 'better', 'failure'],
329329
Optional['resend_igmp'] => Integer,
330-
Optional['learn_packet_interval'] => String,
330+
Optional['learn_packet_interval'] => Variant[Integer, Float],
331331
Optional['primary'] => String,
332332
}]] $parameters = undef,
333333

manifests/tunnels.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
Optional[Enum['l2-miss', 'l3-miss']] $notifications = undef,
361361
Optional[Boolean] $short_circuit = undef,
362362
Optional[Enum['udp', 'zero-udp6-tx', 'zero-udp6-rx',
363-
'remote-tx', 'remote-rx ']] $checksums = undef,
363+
'remote-tx', 'remote-rx']] $checksums = undef,
364364
Optional[Enum['group-policy', 'generic-protocol']] $extensions = undef,
365365
Optional[Tuple[Stdlib::Port, Stdlib::Port]] $port_range = undef,
366366
Optional[Integer[1,1048575]] $flow_label = undef,

manifests/wifis.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,10 @@
413413
Optional['phase2_auth'] => String,
414414
}]
415415
}]]] $access_points = undef,
416-
Optional[Array[Enum['any', 'disconnect']]] $wakeonwlan = undef,
416+
Optional[Array[Enum['any', 'disconnect', 'magic_pkt',
417+
'gtk_rekey_failure', 'eap_identity_req',
418+
'four_way_handshake', 'rfkill_release',
419+
'tcp', 'default']]] $wakeonwlan = undef,
417420
Optional[String] $regulatory_domain = undef,
418421

419422
){

spec/classes/netplan_spec.rb

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'netplan' do
6+
on_supported_os.each do |os, os_facts|
7+
context "on #{os}" do
8+
let(:facts) { os_facts }
9+
10+
context 'with defaults' do
11+
it { is_expected.to compile.with_all_deps }
12+
it { is_expected.to contain_file('/etc/netplan').with_ensure('directory') }
13+
it {
14+
is_expected.to contain_concat('/etc/netplan/01-netcfg.yaml').with(
15+
'mode' => '0600',
16+
)
17+
}
18+
it {
19+
is_expected.to contain_concat__fragment('netplan_header').with(
20+
'target' => '/etc/netplan/01-netcfg.yaml',
21+
'order' => '01',
22+
)
23+
}
24+
it {
25+
is_expected.to contain_exec('netplan_apply').with(
26+
'command' => '/usr/sbin/netplan apply',
27+
)
28+
}
29+
end
30+
31+
context 'with purge_config disabled' do
32+
let(:params) { { purge_config: false } }
33+
34+
it { is_expected.to compile.with_all_deps }
35+
it { is_expected.to contain_file('/etc/netplan').without_purge }
36+
end
37+
38+
context 'with netplan_apply disabled' do
39+
let(:params) { { netplan_apply: false } }
40+
41+
it { is_expected.to compile.with_all_deps }
42+
it { is_expected.not_to contain_exec('netplan_apply') }
43+
end
44+
45+
context 'with custom config_file and mode' do
46+
let(:params) do
47+
{
48+
config_file: '/etc/netplan/99-custom.yaml',
49+
config_file_mode: '0644',
50+
}
51+
end
52+
53+
it { is_expected.to compile.with_all_deps }
54+
it {
55+
is_expected.to contain_concat('/etc/netplan/99-custom.yaml').with(
56+
'mode' => '0644',
57+
)
58+
}
59+
end
60+
61+
context 'with NetworkManager renderer' do
62+
let(:params) { { renderer: 'NetworkManager' } }
63+
64+
it { is_expected.to compile.with_all_deps }
65+
end
66+
67+
context 'with ethernets' do
68+
let(:params) do
69+
{
70+
ethernets: {
71+
'eth0' => {
72+
'dhcp4' => true,
73+
},
74+
},
75+
}
76+
end
77+
78+
it { is_expected.to compile.with_all_deps }
79+
it { is_expected.to contain_netplan__ethernets('eth0') }
80+
it {
81+
is_expected.to contain_concat__fragment('ethernets_header').with(
82+
'order' => '10',
83+
)
84+
}
85+
end
86+
87+
context 'with vlans' do
88+
let(:params) do
89+
{
90+
vlans: {
91+
'vlan50' => {
92+
'id' => 50,
93+
'link' => 'eth0',
94+
'dhcp4' => true,
95+
},
96+
},
97+
}
98+
end
99+
100+
it { is_expected.to compile.with_all_deps }
101+
it { is_expected.to contain_netplan__vlans('vlan50') }
102+
end
103+
104+
context 'with bridges' do
105+
let(:params) do
106+
{
107+
bridges: {
108+
'br0' => {
109+
'interfaces' => ['eth0', 'eth1'],
110+
'dhcp4' => true,
111+
},
112+
},
113+
}
114+
end
115+
116+
it { is_expected.to compile.with_all_deps }
117+
it { is_expected.to contain_netplan__bridges('br0') }
118+
end
119+
120+
context 'with bonds' do
121+
let(:params) do
122+
{
123+
bonds: {
124+
'bond0' => {
125+
'interfaces' => ['eth0', 'eth1'],
126+
'dhcp4' => true,
127+
},
128+
},
129+
}
130+
end
131+
132+
it { is_expected.to compile.with_all_deps }
133+
it { is_expected.to contain_netplan__bonds('bond0') }
134+
end
135+
136+
context 'with tunnels' do
137+
let(:params) do
138+
{
139+
tunnels: {
140+
'tun0' => {
141+
'mode' => 'gre',
142+
'local' => '10.0.0.1',
143+
'remote' => '10.0.0.2',
144+
},
145+
},
146+
}
147+
end
148+
149+
it { is_expected.to compile.with_all_deps }
150+
it { is_expected.to contain_netplan__tunnels('tun0') }
151+
end
152+
153+
context 'with dummy_devices' do
154+
let(:params) do
155+
{
156+
dummy_devices: {
157+
'dummy0' => {
158+
'addresses' => ['10.0.0.1/24'],
159+
},
160+
},
161+
}
162+
end
163+
164+
it { is_expected.to compile.with_all_deps }
165+
it { is_expected.to contain_netplan__dummy_devices('dummy0') }
166+
end
167+
168+
context 'with vrfs' do
169+
let(:params) do
170+
{
171+
vrfs: {
172+
'vrf0' => {
173+
'table' => 100,
174+
'interfaces' => ['eth0'],
175+
},
176+
},
177+
}
178+
end
179+
180+
it { is_expected.to compile.with_all_deps }
181+
it { is_expected.to contain_netplan__vrfs('vrf0') }
182+
end
183+
end
184+
end
185+
end

spec/defines/bonds_spec.rb

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'netplan::bonds' do
6+
let(:pre_condition) { 'include netplan' }
7+
8+
on_supported_os.each do |os, os_facts|
9+
context "on #{os}" do
10+
let(:facts) { os_facts }
11+
let(:title) { 'bond0' }
12+
13+
context 'with minimal parameters' do
14+
let(:params) do
15+
{
16+
interfaces: ['eth0', 'eth1'],
17+
dhcp4: true,
18+
}
19+
end
20+
21+
it { is_expected.to compile.with_all_deps }
22+
it {
23+
is_expected.to contain_concat__fragment('bond0').with(
24+
'target' => '/etc/netplan/01-netcfg.yaml',
25+
'order' => '51',
26+
)
27+
}
28+
end
29+
30+
context 'with bond parameters' do
31+
let(:params) do
32+
{
33+
interfaces: ['eth0', 'eth1'],
34+
dhcp4: true,
35+
parameters: {
36+
'mode' => '802.3ad',
37+
'lacp_rate' => 'fast',
38+
'mii_monitor_interval' => 100,
39+
'min_links' => 1,
40+
'transmit_hash_policy' => 'layer3+4',
41+
'up_delay' => 200,
42+
'down_delay' => 200,
43+
'learn_packet_interval' => 5,
44+
},
45+
}
46+
end
47+
48+
it { is_expected.to compile.with_all_deps }
49+
it {
50+
is_expected.to contain_concat__fragment('bond0').with_content(
51+
%r{parameters:},
52+
)
53+
}
54+
end
55+
56+
context 'with learn_packet_interval as float' do
57+
let(:params) do
58+
{
59+
interfaces: ['eth0', 'eth1'],
60+
parameters: {
61+
'mode' => 'balance-rr',
62+
'learn_packet_interval' => 1.5,
63+
},
64+
}
65+
end
66+
67+
it { is_expected.to compile.with_all_deps }
68+
end
69+
70+
context 'rejects learn_packet_interval as string' do
71+
let(:params) do
72+
{
73+
interfaces: ['eth0', 'eth1'],
74+
parameters: {
75+
'mode' => 'balance-rr',
76+
'learn_packet_interval' => 'invalid',
77+
},
78+
}
79+
end
80+
81+
it { is_expected.to compile.and_raise_error(%r{}) }
82+
end
83+
84+
context 'with routing_policy including mark and type_of_service' do
85+
let(:params) do
86+
{
87+
interfaces: ['eth0', 'eth1'],
88+
dhcp4: true,
89+
routing_policy: [
90+
{
91+
'from' => '10.0.0.0/8',
92+
'to' => '192.168.0.0/16',
93+
'mark' => 10,
94+
'type_of_service' => 4,
95+
},
96+
],
97+
}
98+
end
99+
100+
it { is_expected.to compile.with_all_deps }
101+
it {
102+
is_expected.to contain_concat__fragment('bond0').with_content(
103+
%r{mark: 10},
104+
)
105+
}
106+
it {
107+
is_expected.to contain_concat__fragment('bond0').with_content(
108+
%r{type-of-service: 4},
109+
)
110+
}
111+
end
112+
end
113+
end
114+
end

0 commit comments

Comments
 (0)