Skip to content

Commit 4948161

Browse files
committed
Add acceptance tests
1 parent 390b978 commit 4948161

File tree

4 files changed

+776
-0
lines changed

4 files changed

+776
-0
lines changed
Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'network_config with nm provider' do
4+
context 'when nmstate is available' do
5+
before(:all) do
6+
# Check if nmstate is available
7+
result = shell('which nmstatectl', acceptable_exit_codes: [0, 1])
8+
skip 'nmstatectl is not available' if result.exit_code != 0
9+
10+
# Check if NetworkManager is running
11+
result = shell('systemctl is-active NetworkManager', acceptable_exit_codes: [0, 1])
12+
skip 'NetworkManager is not running' if result.exit_code != 0
13+
14+
# Load dummy kernel module if not already loaded
15+
shell('modprobe dummy', acceptable_exit_codes: [0, 1])
16+
end
17+
18+
context 'managing a dummy interface' do
19+
let(:manifest) do
20+
<<-MANIFEST
21+
network_config { 'dummy0':
22+
ensure => 'present',
23+
provider => 'nm',
24+
onboot => true,
25+
method => 'manual',
26+
mtu => 1500,
27+
}
28+
MANIFEST
29+
end
30+
31+
let(:cleanup_manifest) do
32+
<<-MANIFEST
33+
network_config { 'dummy0':
34+
ensure => 'absent',
35+
provider => 'nm',
36+
}
37+
MANIFEST
38+
end
39+
40+
after(:all) do
41+
# Cleanup - remove the dummy interface
42+
apply_manifest(cleanup_manifest, catch_failures: true)
43+
end
44+
45+
it 'creates a dummy interface' do
46+
# Apply the manifest
47+
apply_manifest(manifest, catch_failures: true)
48+
49+
# Check if the interface was created - allow some time for NetworkManager to process
50+
sleep(2)
51+
result = shell('nmcli device show dummy0', acceptable_exit_codes: [0, 1])
52+
if result.exit_code != 0
53+
# Try with ip command as fallback
54+
result = shell('ip link show dummy0', acceptable_exit_codes: [0, 1])
55+
expect(result.exit_code).to eq(0), 'dummy0 interface was not created'
56+
end
57+
end
58+
59+
it 'is idempotent' do
60+
# Apply twice to ensure idempotency
61+
apply_manifest(manifest, catch_failures: true)
62+
apply_manifest(manifest, catch_changes: true)
63+
end
64+
end
65+
66+
context 'managing a dummy interface with static IP' do
67+
let(:manifest) do
68+
<<-MANIFEST
69+
network_config { 'dummy1':
70+
ensure => 'present',
71+
provider => 'nm',
72+
onboot => true,
73+
method => 'static',
74+
family => 'inet',
75+
ipaddress => '192.0.2.100',
76+
netmask => '255.255.255.0',
77+
mtu => 1500,
78+
}
79+
MANIFEST
80+
end
81+
82+
let(:cleanup_manifest) do
83+
<<-MANIFEST
84+
network_config { 'dummy1':
85+
ensure => 'absent',
86+
provider => 'nm',
87+
}
88+
MANIFEST
89+
end
90+
91+
after(:all) do
92+
# Cleanup - remove the dummy interface
93+
apply_manifest(cleanup_manifest, catch_failures: true)
94+
end
95+
96+
it 'creates a dummy interface with static IP' do
97+
# Apply the manifest
98+
apply_manifest(manifest, catch_failures: true)
99+
100+
# Check if the interface was created and has the IP - allow some time for NetworkManager to process
101+
sleep(2)
102+
result = shell('nmcli device show dummy1', acceptable_exit_codes: [0, 1])
103+
if result.exit_code == 0
104+
expect(result.stdout).to match(%r{192\.0\.2\.100})
105+
else
106+
# Try with ip command as fallback
107+
result = shell('ip addr show dummy1')
108+
expect(result.stdout).to match(%r{192\.0\.2\.100})
109+
end
110+
end
111+
112+
it 'is idempotent' do
113+
# Apply twice to ensure idempotency
114+
apply_manifest(manifest, catch_failures: true)
115+
apply_manifest(manifest, catch_changes: true)
116+
end
117+
end
118+
119+
context 'managing a dummy interface with IPv6' do
120+
let(:manifest) do
121+
<<-MANIFEST
122+
network_config { 'dummy2':
123+
ensure => 'present',
124+
provider => 'nm',
125+
onboot => true,
126+
method => 'static',
127+
family => 'inet6',
128+
ipaddress => '2001:db8::100',
129+
netmask => '64',
130+
mtu => 1500,
131+
}
132+
MANIFEST
133+
end
134+
135+
let(:cleanup_manifest) do
136+
<<-MANIFEST
137+
network_config { 'dummy2':
138+
ensure => 'absent',
139+
provider => 'nm',
140+
}
141+
MANIFEST
142+
end
143+
144+
after(:all) do
145+
# Cleanup - remove the dummy interface
146+
apply_manifest(cleanup_manifest, catch_failures: true)
147+
end
148+
149+
it 'creates a dummy interface with IPv6' do
150+
# Apply the manifest
151+
apply_manifest(manifest, catch_failures: true)
152+
153+
# Check if the interface was created and has the IPv6 address - allow some time for NetworkManager to process
154+
sleep(2)
155+
result = shell('nmcli device show dummy2', acceptable_exit_codes: [0, 1])
156+
if result.exit_code == 0
157+
expect(result.stdout).to match(%r{2001:db8::100})
158+
else
159+
# Try with ip command as fallback
160+
result = shell('ip addr show dummy2')
161+
expect(result.stdout).to match(%r{2001:db8::100})
162+
end
163+
end
164+
165+
it 'is idempotent' do
166+
# Apply twice to ensure idempotency
167+
apply_manifest(manifest, catch_failures: true)
168+
apply_manifest(manifest, catch_changes: true)
169+
end
170+
end
171+
172+
context 'managing interface with provider options' do
173+
let(:manifest) do
174+
<<-MANIFEST
175+
network_config { 'dummy3':
176+
ensure => 'present',
177+
provider => 'nm',
178+
onboot => true,
179+
method => 'manual',
180+
mtu => 1400,
181+
options => { 'accept-ra' => false },
182+
}
183+
MANIFEST
184+
end
185+
186+
let(:cleanup_manifest) do
187+
<<-MANIFEST
188+
network_config { 'dummy3':
189+
ensure => 'absent',
190+
provider => 'nm',
191+
}
192+
MANIFEST
193+
end
194+
195+
after(:all) do
196+
# Cleanup - remove the dummy interface
197+
apply_manifest(cleanup_manifest, catch_failures: true)
198+
end
199+
200+
it 'creates a dummy interface with custom options' do
201+
# Apply the manifest
202+
apply_manifest(manifest, catch_failures: true)
203+
204+
# Check if the interface was created - allow some time for NetworkManager to process
205+
sleep(2)
206+
result = shell('nmcli device show dummy3', acceptable_exit_codes: [0, 1])
207+
if result.exit_code != 0
208+
# Try with ip command as fallback
209+
result = shell('ip link show dummy3', acceptable_exit_codes: [0, 1])
210+
expect(result.exit_code).to eq(0), 'dummy3 interface was not created'
211+
end
212+
end
213+
214+
it 'is idempotent' do
215+
# Apply twice to ensure idempotency
216+
apply_manifest(manifest, catch_failures: true)
217+
apply_manifest(manifest, catch_changes: true)
218+
end
219+
end
220+
221+
context 'updating interface configuration' do
222+
let(:initial_manifest) do
223+
<<-MANIFEST
224+
network_config { 'dummy4':
225+
ensure => 'present',
226+
provider => 'nm',
227+
onboot => true,
228+
method => 'static',
229+
family => 'inet',
230+
ipaddress => '192.0.2.200',
231+
netmask => '255.255.255.0',
232+
mtu => 1500,
233+
}
234+
MANIFEST
235+
end
236+
237+
let(:updated_manifest) do
238+
<<-MANIFEST
239+
network_config { 'dummy4':
240+
ensure => 'present',
241+
provider => 'nm',
242+
onboot => true,
243+
method => 'static',
244+
family => 'inet',
245+
ipaddress => '192.0.2.201',
246+
netmask => '255.255.255.0',
247+
mtu => 1400,
248+
}
249+
MANIFEST
250+
end
251+
252+
let(:cleanup_manifest) do
253+
<<-MANIFEST
254+
network_config { 'dummy4':
255+
ensure => 'absent',
256+
provider => 'nm',
257+
}
258+
MANIFEST
259+
end
260+
261+
after(:all) do
262+
# Cleanup - remove the dummy interface
263+
apply_manifest(cleanup_manifest, catch_failures: true)
264+
end
265+
266+
it 'updates interface configuration' do
267+
# Apply the initial manifest
268+
apply_manifest(initial_manifest, catch_failures: true)
269+
270+
# Verify initial configuration - allow some time for NetworkManager to process
271+
sleep(2)
272+
result = shell('nmcli device show dummy4', acceptable_exit_codes: [0, 1])
273+
if result.exit_code == 0
274+
expect(result.stdout).to match(%r{192\.0\.2\.200})
275+
else
276+
# Try with ip command as fallback
277+
result = shell('ip addr show dummy4')
278+
expect(result.stdout).to match(%r{192\.0\.2\.200})
279+
end
280+
281+
# Apply the updated manifest
282+
apply_manifest(updated_manifest, catch_failures: true)
283+
284+
# Verify updated configuration - allow some time for NetworkManager to process
285+
sleep(2)
286+
result = shell('nmcli device show dummy4', acceptable_exit_codes: [0, 1])
287+
if result.exit_code == 0
288+
expect(result.stdout).to match(%r{192\.0\.2\.201})
289+
else
290+
# Try with ip command as fallback
291+
result = shell('ip addr show dummy4')
292+
expect(result.stdout).to match(%r{192\.0\.2\.201})
293+
end
294+
end
295+
end
296+
end
297+
298+
context 'when nmstate is not available' do
299+
before(:all) do
300+
# Check if nmstate is available
301+
result = shell('which nmstatectl', acceptable_exit_codes: [0, 1])
302+
skip 'nmstatectl is available' if result.exit_code == 0
303+
end
304+
305+
let(:manifest) do
306+
<<-MANIFEST
307+
network_config { 'dummy0':
308+
ensure => 'present',
309+
provider => 'nm',
310+
onboot => true,
311+
method => 'manual',
312+
}
313+
MANIFEST
314+
end
315+
316+
it 'fails gracefully when nmstatectl is not available' do
317+
# This should fail because nmstatectl is not available
318+
apply_manifest(manifest, expect_failures: true)
319+
end
320+
end
321+
end

0 commit comments

Comments
 (0)