Skip to content

Commit 76f1061

Browse files
Felix Wischke (65278)wikkyk
authored andcommitted
cloudinit/network_test: test cases for newly added interface config
1 parent b7d130d commit 76f1061

File tree

3 files changed

+219
-4
lines changed

3 files changed

+219
-4
lines changed

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachines.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ spec:
262262
description: RoutingPolicy is an interface-specific policy
263263
inserted into FIB (forwarding information base).
264264
items:
265-
description: RoutingPolicySpec is a linux FIB rule.
265+
description: RoutingPolicySpec is a Linux FIB rule.
266266
properties:
267267
from:
268268
description: From is the subnet of the source.
@@ -278,7 +278,7 @@ spec:
278278
kernel rules
279279
rule: (self > 0 && self < 32765) || (self > 32766)
280280
table:
281-
description: Table is the routing table id.
281+
description: Table is the routing table ID.
282282
format: int32
283283
type: integer
284284
to:

config/crd/bases/infrastructure.cluster.x-k8s.io_proxmoxmachinetemplates.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ spec:
284284
policy inserted into FIB (forwarding information
285285
base).
286286
items:
287-
description: RoutingPolicySpec is a linux FIB
287+
description: RoutingPolicySpec is a Linux FIB
288288
rule.
289289
properties:
290290
from:
@@ -302,7 +302,7 @@ spec:
302302
rule: (self > 0 && self < 32765) || (self
303303
> 32766)
304304
table:
305-
description: Table is the routing table id.
305+
description: Table is the routing table ID.
306306
format: int32
307307
type: integer
308308
to:

pkg/cloudinit/network_test.go

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ const (
4444
- '8.8.8.8'
4545
- '8.8.4.4'`
4646

47+
expectedValidNetworkConfigWithLinkMTU = `network:
48+
version: 2
49+
renderer: networkd
50+
ethernets:
51+
eth0:
52+
match:
53+
macaddress: 92:60:a0:5b:22:c2
54+
dhcp4: false
55+
dhcp6: false
56+
addresses:
57+
- 10.10.10.12/24
58+
routes:
59+
- to: 0.0.0.0/0
60+
metric: 100
61+
via: 10.10.10.1
62+
nameservers:
63+
addresses:
64+
- '8.8.8.8'
65+
- '8.8.4.4'
66+
mtu: 9001`
67+
4768
expectedValidNetworkConfigWithoutDNS = `network:
4869
version: 2
4970
renderer: networkd
@@ -201,6 +222,92 @@ const (
201222
- '8.8.8.8'
202223
- '8.8.4.4'`
203224

225+
expectedValidNetworkConfigIPAndDHCP = `network:
226+
version: 2
227+
renderer: networkd
228+
ethernets:
229+
eth0:
230+
match:
231+
macaddress: 92:60:a0:5b:22:c2
232+
dhcp4: true
233+
dhcp6: false
234+
addresses:
235+
- 10.10.10.12/24
236+
routes:
237+
- to: 0.0.0.0/0
238+
metric: 100
239+
via: 10.10.10.1
240+
nameservers:
241+
addresses:
242+
- '8.8.8.8'
243+
- '8.8.4.4'`
244+
245+
expectedValidNetworkConfigWithRoutes = `network:
246+
version: 2
247+
renderer: networkd
248+
ethernets:
249+
eth0:
250+
match:
251+
macaddress: 92:60:a0:5b:22:c2
252+
dhcp4: false
253+
dhcp6: true
254+
addresses:
255+
- 10.10.10.12/24
256+
routes:
257+
- to: 0.0.0.0/0
258+
metric: 100
259+
via: 10.10.10.1
260+
nameservers:
261+
addresses:
262+
- '8.8.8.8'
263+
- '8.8.4.4'
264+
eth1:
265+
match:
266+
macaddress: 92:60:a0:5b:22:c3
267+
dhcp4: false
268+
dhcp6: false
269+
addresses:
270+
- 10.10.11.12/24
271+
routes:
272+
- to: 0.0.0.0/0
273+
metric: 200
274+
via: 10.10.11.1
275+
- { "to": "172.16.24.1/24", "via": "10.10.10.254", "metric": 50, }
276+
- { "to": "2002::/64", "via": "2001:db8::1", }`
277+
278+
expectedValidNetworkConfigWithFIBRules = `network:
279+
version: 2
280+
renderer: networkd
281+
ethernets:
282+
eth0:
283+
match:
284+
macaddress: 92:60:a0:5b:22:c2
285+
dhcp4: false
286+
dhcp6: true
287+
addresses:
288+
- 10.10.10.12/24
289+
routes:
290+
- to: 0.0.0.0/0
291+
metric: 100
292+
via: 10.10.10.1
293+
nameservers:
294+
addresses:
295+
- '8.8.8.8'
296+
- '8.8.4.4'
297+
eth1:
298+
match:
299+
macaddress: 92:60:a0:5b:22:c3
300+
dhcp4: false
301+
dhcp6: false
302+
addresses:
303+
- 10.10.11.12/24
304+
routes:
305+
- to: 0.0.0.0/0
306+
metric: 200
307+
via: 10.10.11.1
308+
routing-policy:
309+
- { "to": "0.0.0.0/0", "from": "192.168.178.1/24", "priority": 999, "table": 100, }`
310+
204311
expectedValidNetworkConfigMultipleNicsVRF = `network:
205312
version: 2
206313
renderer: networkd
@@ -343,6 +450,26 @@ func TestNetworkConfig_Render(t *testing.T) {
343450
err: nil,
344451
},
345452
},
453+
"ValidStaticNetworkConfigWithLinkMTU": {
454+
reason: "render valid network-config with static ip and mtu",
455+
args: args{
456+
nics: []NetworkConfigData{
457+
{
458+
Type: "ethernet",
459+
Name: "eth0",
460+
MacAddress: "92:60:a0:5b:22:c2",
461+
IPAddress: "10.10.10.12/24",
462+
Gateway: "10.10.10.1",
463+
DNSServers: []string{"8.8.8.8", "8.8.4.4"},
464+
LinkMTU: func(i uint16) *uint16 { return &i }(9001),
465+
},
466+
},
467+
},
468+
want: want{
469+
network: expectedValidNetworkConfigWithLinkMTU,
470+
err: nil,
471+
},
472+
},
346473
"ValidStaticNetworkConfigWithDHCP": {
347474
reason: "render valid network-config with ipv6 static ip and dhcp",
348475
args: args{
@@ -363,6 +490,94 @@ func TestNetworkConfig_Render(t *testing.T) {
363490
err: nil,
364491
},
365492
},
493+
"ValidStaticNetworkConfigIPWithDHCP": {
494+
reason: "render valid network-config with ipv6 static ip and dhcp",
495+
args: args{
496+
nics: []NetworkConfigData{
497+
{
498+
Type: "ethernet",
499+
Name: "eth0",
500+
MacAddress: "92:60:a0:5b:22:c2",
501+
DHCP4: true,
502+
IPAddress: "10.10.10.12/24",
503+
Gateway: "10.10.10.1",
504+
DNSServers: []string{"8.8.8.8", "8.8.4.4"},
505+
},
506+
},
507+
},
508+
want: want{
509+
network: expectedValidNetworkConfigIPAndDHCP,
510+
err: nil,
511+
},
512+
},
513+
"ValidStaticNetworkConfigWithRoutes": {
514+
reason: "render valid network-config with ipv6 static ip and dhcp and routes",
515+
args: args{
516+
nics: []NetworkConfigData{
517+
{
518+
Type: "ethernet",
519+
Name: "eth0",
520+
MacAddress: "92:60:a0:5b:22:c2",
521+
DHCP6: true,
522+
IPAddress: "10.10.10.12/24",
523+
Gateway: "10.10.10.1",
524+
DNSServers: []string{"8.8.8.8", "8.8.4.4"},
525+
}, {
526+
Type: "ethernet",
527+
Name: "eth1",
528+
MacAddress: "92:60:a0:5b:22:c3",
529+
IPAddress: "10.10.11.12/24",
530+
Gateway: "10.10.11.1",
531+
Routes: []RoutingData{{
532+
To: "172.16.24.1/24",
533+
Metric: 50,
534+
Via: "10.10.10.254",
535+
}, {
536+
To: "2002::/64",
537+
Via: "2001:db8::1",
538+
},
539+
},
540+
},
541+
},
542+
},
543+
want: want{
544+
network: expectedValidNetworkConfigWithRoutes,
545+
err: nil,
546+
},
547+
},
548+
"ValidStaticNetworkConfigWithFIBRules": {
549+
reason: "render valid network-config with FIB rules/routing policy",
550+
args: args{
551+
nics: []NetworkConfigData{
552+
{
553+
Type: "ethernet",
554+
Name: "eth0",
555+
MacAddress: "92:60:a0:5b:22:c2",
556+
DHCP6: true,
557+
IPAddress: "10.10.10.12/24",
558+
Gateway: "10.10.10.1",
559+
DNSServers: []string{"8.8.8.8", "8.8.4.4"},
560+
}, {
561+
Type: "ethernet",
562+
Name: "eth1",
563+
IPAddress: "10.10.11.12/24",
564+
Gateway: "10.10.11.1",
565+
MacAddress: "92:60:a0:5b:22:c3",
566+
FIBRules: []FIBRuleData{{
567+
To: "0.0.0.0/0",
568+
From: "192.168.178.1/24",
569+
Priority: 999,
570+
Table: 100,
571+
},
572+
},
573+
},
574+
},
575+
},
576+
want: want{
577+
network: expectedValidNetworkConfigWithFIBRules,
578+
err: nil,
579+
},
580+
},
366581
"InvalidNetworkConfigIp": {
367582
reason: "ip address is not set",
368583
args: args{

0 commit comments

Comments
 (0)