-
Notifications
You must be signed in to change notification settings - Fork 816
/
test_net.py
8268 lines (7587 loc) · 258 KB
/
test_net.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is part of cloud-init. See LICENSE file for license information.
import base64
import copy
import gzip
import io
import json
import os
import re
import textwrap
import pytest
from yaml.serializer import Serializer
from cloudinit import distros, net
from cloudinit import safeyaml as yaml
from cloudinit import subp, temp_utils, util
from cloudinit.net import (
cmdline,
eni,
interface_has_own_mac,
mask_and_ipv4_to_bcast_addr,
natural_sort_key,
netplan,
network_manager,
network_state,
networkd,
renderers,
sysconfig,
)
from cloudinit.sources.helpers import openstack
from tests.unittests.helpers import (
CiTestCase,
FilesystemMockingTestCase,
dir2dict,
mock,
populate_dir,
)
DHCP_CONTENT_1 = """
DEVICE='eth0'
PROTO='dhcp'
IPV4ADDR='192.168.122.89'
IPV4BROADCAST='192.168.122.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='192.168.122.1'
IPV4DNS0='192.168.122.1'
IPV4DNS1='0.0.0.0'
HOSTNAME='foohost'
DNSDOMAIN=''
NISDOMAIN=''
ROOTSERVER='192.168.122.1'
ROOTPATH=''
filename=''
UPTIME='21'
DHCPLEASETIME='3600'
DOMAINSEARCH='foo.com'
"""
DHCP_EXPECTED_1 = {
"name": "eth0",
"type": "physical",
"subnets": [
{
"broadcast": "192.168.122.255",
"control": "manual",
"gateway": "192.168.122.1",
"dns_search": ["foo.com"],
"type": "dhcp",
"netmask": "255.255.255.0",
"dns_nameservers": ["192.168.122.1"],
}
],
}
DHCP6_CONTENT_1 = """
DEVICE6=eno1
HOSTNAME=
DNSDOMAIN=
IPV6PROTO=dhcp6
IPV6ADDR=2001:67c:1562:8010:0:1::
IPV6NETMASK=64
IPV6DNS0=2001:67c:1562:8010::2:1
IPV6DOMAINSEARCH=
HOSTNAME=
DNSDOMAIN=
"""
DHCP6_EXPECTED_1 = {
"name": "eno1",
"type": "physical",
"subnets": [
{
"control": "manual",
"dns_nameservers": ["2001:67c:1562:8010::2:1"],
"netmask": "64",
"type": "dhcp6",
}
],
}
STATIC_CONTENT_1 = """
DEVICE='eth1'
PROTO='none'
IPV4ADDR='10.0.0.2'
IPV4BROADCAST='10.0.0.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='10.0.0.1'
IPV4DNS0='10.0.1.1'
IPV4DNS1='0.0.0.0'
HOSTNAME='foohost'
UPTIME='21'
DHCPLEASETIME='3600'
DOMAINSEARCH='foo.com'
"""
STATIC_EXPECTED_1 = {
"name": "eth1",
"type": "physical",
"subnets": [
{
"broadcast": "10.0.0.255",
"control": "manual",
"gateway": "10.0.0.1",
"dns_search": ["foo.com"],
"type": "static",
"netmask": "255.255.255.0",
"dns_nameservers": ["10.0.1.1"],
"address": "10.0.0.2",
}
],
}
V1_NAMESERVER_ALIAS = """
config:
- id: eno1
mac_address: 08:94:ef:51:ae:e0
mtu: 1500
name: eno1
subnets:
- type: manual
type: physical
- id: eno2
mac_address: 08:94:ef:51:ae:e1
mtu: 1500
name: eno2
subnets:
- type: manual
type: physical
- id: eno3
mac_address: 08:94:ef:51:ae:de
mtu: 1500
name: eno3
subnets:
- type: manual
type: physical
- bond_interfaces:
- eno1
- eno3
id: bondM
mac_address: 08:94:ef:51:ae:e0
mtu: 1500
name: bondM
params:
bond-downdelay: 0
bond-lacp-rate: fast
bond-miimon: 100
bond-mode: 802.3ad
bond-updelay: 0
bond-xmit-hash-policy: layer3+4
subnets:
- address: 10.101.10.47/23
gateway: 10.101.11.254
type: static
type: bond
- id: eno4
mac_address: 08:94:ef:51:ae:df
mtu: 1500
name: eno4
subnets:
- type: manual
type: physical
- id: enp0s20f0u1u6
mac_address: 0a:94:ef:51:a4:b9
mtu: 1500
name: enp0s20f0u1u6
subnets:
- type: manual
type: physical
- id: enp216s0f0
mac_address: 68:05:ca:81:7c:e8
mtu: 9000
name: enp216s0f0
subnets:
- type: manual
type: physical
- id: enp216s0f1
mac_address: 68:05:ca:81:7c:e9
mtu: 9000
name: enp216s0f1
subnets:
- type: manual
type: physical
- id: enp47s0f0
mac_address: 68:05:ca:64:d3:6c
mtu: 9000
name: enp47s0f0
subnets:
- type: manual
type: physical
- bond_interfaces:
- enp216s0f0
- enp47s0f0
id: bond0
mac_address: 68:05:ca:64:d3:6c
mtu: 9000
name: bond0
params:
bond-downdelay: 0
bond-lacp-rate: fast
bond-miimon: 100
bond-mode: 802.3ad
bond-updelay: 0
bond-xmit-hash-policy: layer3+4
subnets:
- type: manual
type: bond
- id: bond0.3502
mtu: 9000
name: bond0.3502
subnets:
- address: 172.20.80.4/25
type: static
type: vlan
vlan_id: 3502
vlan_link: bond0
- id: bond0.3503
mtu: 9000
name: bond0.3503
subnets:
- address: 172.20.80.129/25
type: static
type: vlan
vlan_id: 3503
vlan_link: bond0
- id: enp47s0f1
mac_address: 68:05:ca:64:d3:6d
mtu: 9000
name: enp47s0f1
subnets:
- type: manual
type: physical
- bond_interfaces:
- enp216s0f1
- enp47s0f1
id: bond1
mac_address: 68:05:ca:64:d3:6d
mtu: 9000
name: bond1
params:
bond-downdelay: 0
bond-lacp-rate: fast
bond-miimon: 100
bond-mode: 802.3ad
bond-updelay: 0
bond-xmit-hash-policy: layer3+4
subnets:
- address: 10.101.8.65/26
routes:
- destination: 213.119.192.0/24
gateway: 10.101.8.126
metric: 0
type: static
type: bond
- address:
- 10.101.10.1
- 10.101.10.2
- 10.101.10.3
- 10.101.10.5
search:
- foo.bar
- maas
type: nameserver
version: 1
"""
NETPLAN_NO_ALIAS = """
network:
version: 2
ethernets:
eno1:
match:
macaddress: 08:94:ef:51:ae:e0
mtu: 1500
set-name: eno1
eno2:
match:
macaddress: 08:94:ef:51:ae:e1
mtu: 1500
set-name: eno2
eno3:
match:
macaddress: 08:94:ef:51:ae:de
mtu: 1500
set-name: eno3
eno4:
match:
macaddress: 08:94:ef:51:ae:df
mtu: 1500
set-name: eno4
enp0s20f0u1u6:
match:
macaddress: 0a:94:ef:51:a4:b9
mtu: 1500
set-name: enp0s20f0u1u6
enp216s0f0:
match:
macaddress: 68:05:ca:81:7c:e8
mtu: 9000
set-name: enp216s0f0
enp216s0f1:
match:
macaddress: 68:05:ca:81:7c:e9
mtu: 9000
set-name: enp216s0f1
enp47s0f0:
match:
macaddress: 68:05:ca:64:d3:6c
mtu: 9000
set-name: enp47s0f0
enp47s0f1:
match:
macaddress: 68:05:ca:64:d3:6d
mtu: 9000
set-name: enp47s0f1
bonds:
bond0:
interfaces:
- enp216s0f0
- enp47s0f0
macaddress: 68:05:ca:64:d3:6c
mtu: 9000
parameters:
down-delay: 0
lacp-rate: fast
mii-monitor-interval: 100
mode: 802.3ad
transmit-hash-policy: layer3+4
up-delay: 0
bond1:
addresses:
- 10.101.8.65/26
interfaces:
- enp216s0f1
- enp47s0f1
macaddress: 68:05:ca:64:d3:6d
mtu: 9000
nameservers:
addresses:
- 10.101.10.1
- 10.101.10.2
- 10.101.10.3
- 10.101.10.5
search:
- foo.bar
- maas
parameters:
down-delay: 0
lacp-rate: fast
mii-monitor-interval: 100
mode: 802.3ad
transmit-hash-policy: layer3+4
up-delay: 0
routes:
- metric: 0
to: 213.119.192.0/24
via: 10.101.8.126
bondM:
addresses:
- 10.101.10.47/23
gateway4: 10.101.11.254
interfaces:
- eno1
- eno3
macaddress: 08:94:ef:51:ae:e0
mtu: 1500
nameservers:
addresses:
- 10.101.10.1
- 10.101.10.2
- 10.101.10.3
- 10.101.10.5
search:
- foo.bar
- maas
parameters:
down-delay: 0
lacp-rate: fast
mii-monitor-interval: 100
mode: 802.3ad
transmit-hash-policy: layer3+4
up-delay: 0
vlans:
bond0.3502:
addresses:
- 172.20.80.4/25
id: 3502
link: bond0
mtu: 9000
nameservers:
addresses:
- 10.101.10.1
- 10.101.10.2
- 10.101.10.3
- 10.101.10.5
search:
- foo.bar
- maas
bond0.3503:
addresses:
- 172.20.80.129/25
id: 3503
link: bond0
mtu: 9000
nameservers:
addresses:
- 10.101.10.1
- 10.101.10.2
- 10.101.10.3
- 10.101.10.5
search:
- foo.bar
- maas
"""
NETPLAN_BOND_GRAT_ARP = """
network:
bonds:
bond0:
interfaces:
- ens3
macaddress: 68:05:ca:64:d3:6c
mtu: 9000
parameters:
gratuitous-arp: 1
bond1:
interfaces:
- ens4
macaddress: 68:05:ca:64:d3:6d
mtu: 9000
parameters:
gratuitous-arp: 2
bond2:
interfaces:
- ens5
macaddress: 68:05:ca:64:d3:6e
mtu: 9000
ethernets:
ens3:
dhcp4: false
dhcp6: false
match:
macaddress: 52:54:00:ab:cd:ef
ens4:
dhcp4: false
dhcp6: false
match:
macaddress: 52:54:00:11:22:ff
ens5:
dhcp4: false
dhcp6: false
match:
macaddress: 52:54:00:99:11:99
version: 2
"""
NETPLAN_DHCP_FALSE = """
version: 2
ethernets:
ens3:
match:
macaddress: 52:54:00:ab:cd:ef
dhcp4: false
dhcp6: false
addresses:
- 192.168.42.100/24
- 2001:db8::100/32
gateway4: 192.168.42.1
gateway6: 2001:db8::1
nameservers:
search: [example.com]
addresses: [192.168.42.53, 1.1.1.1]
"""
# Examples (and expected outputs for various renderers).
OS_SAMPLES = [
{
"in_data": {
"services": [{"type": "dns", "address": "172.19.0.12"}],
"networks": [
{
"network_id": "dacd568d-5be6-4786-91fe-750c374b78b4",
"type": "ipv4",
"netmask": "255.255.252.0",
"link": "tap1a81968a-79",
"routes": [
{
"netmask": "0.0.0.0",
"network": "0.0.0.0",
"gateway": "172.19.3.254",
}
],
"ip_address": "172.19.1.34",
"id": "network0",
}
],
"links": [
{
"ethernet_mac_address": "fa:16:3e:ed:9a:59",
"mtu": None,
"type": "bridge",
"id": "tap1a81968a-79",
"vif_id": "1a81968a-797a-400f-8a80-567f997eb93f",
},
],
},
"in_macs": {
"fa:16:3e:ed:9a:59": "eth0",
},
"out_sysconfig_opensuse": [
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
LLADDR=fa:16:3e:ed:9a:59
NETMASK=255.255.252.0
STARTMODE=auto
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/85-persistent-net-cloud-init.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
"out_sysconfig_rhel": [
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=172.19.3.254
HWADDR=fa:16:3e:ed:9a:59
IPADDR=172.19.1.34
NETMASK=255.255.252.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/70-persistent-net.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
"expected_network_manager": [
(
"".join(
[
"etc/NetworkManager/system-connections",
"/cloud-init-eth0.nmconnection",
]
),
"""
# Generated by cloud-init. Changes will be lost.
[connection]
id=cloud-init eth0
uuid=1dd9a779-d327-56e1-8454-c65e2556c12c
type=ethernet
[user]
org.freedesktop.NetworkManager.origin=cloud-init
[ethernet]
mac-address=FA:16:3E:ED:9A:59
[ipv4]
method=manual
may-fail=false
address1=172.19.1.34/22
route1=0.0.0.0/0,172.19.3.254
""".lstrip(),
),
],
},
{
"in_data": {
"services": [{"type": "dns", "address": "172.19.0.12"}],
"networks": [
{
"network_id": "public-ipv4",
"type": "ipv4",
"netmask": "255.255.252.0",
"link": "tap1a81968a-79",
"routes": [
{
"netmask": "0.0.0.0",
"network": "0.0.0.0",
"gateway": "172.19.3.254",
}
],
"ip_address": "172.19.1.34",
"id": "network0",
},
{
"network_id": "private-ipv4",
"type": "ipv4",
"netmask": "255.255.255.0",
"link": "tap1a81968a-79",
"routes": [],
"ip_address": "10.0.0.10",
"id": "network1",
},
],
"links": [
{
"ethernet_mac_address": "fa:16:3e:ed:9a:59",
"mtu": None,
"type": "bridge",
"id": "tap1a81968a-79",
"vif_id": "1a81968a-797a-400f-8a80-567f997eb93f",
},
],
},
"in_macs": {
"fa:16:3e:ed:9a:59": "eth0",
},
"out_sysconfig_opensuse": [
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
IPADDR1=10.0.0.10
LLADDR=fa:16:3e:ed:9a:59
NETMASK=255.255.252.0
NETMASK1=255.255.255.0
STARTMODE=auto
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/85-persistent-net-cloud-init.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
"out_sysconfig_rhel": [
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=172.19.3.254
HWADDR=fa:16:3e:ed:9a:59
IPADDR=172.19.1.34
IPADDR1=10.0.0.10
NETMASK=255.255.252.0
NETMASK1=255.255.255.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/70-persistent-net.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
},
{
"in_data": {
"services": [{"type": "dns", "address": "172.19.0.12"}],
"networks": [
{
"network_id": "public-ipv4",
"type": "ipv4",
"netmask": "255.255.252.0",
"link": "tap1a81968a-79",
"routes": [
{
"netmask": "0.0.0.0",
"network": "0.0.0.0",
"gateway": "172.19.3.254",
}
],
"ip_address": "172.19.1.34",
"id": "network0",
},
{
"network_id": "public-ipv6-a",
"type": "ipv6",
"netmask": "",
"link": "tap1a81968a-79",
"routes": [
{
"gateway": "2001:DB8::1",
"netmask": "::",
"network": "::",
}
],
"ip_address": "2001:DB8::10",
"id": "network1",
},
{
"network_id": "public-ipv6-b",
"type": "ipv6",
"netmask": "64",
"link": "tap1a81968a-79",
"routes": [],
"ip_address": "2001:DB9::10",
"id": "network2",
},
{
"network_id": "public-ipv6-c",
"type": "ipv6",
"netmask": "64",
"link": "tap1a81968a-79",
"routes": [],
"ip_address": "2001:DB10::10",
"id": "network3",
},
],
"links": [
{
"ethernet_mac_address": "fa:16:3e:ed:9a:59",
"mtu": None,
"type": "bridge",
"id": "tap1a81968a-79",
"vif_id": "1a81968a-797a-400f-8a80-567f997eb93f",
},
],
},
"in_macs": {
"fa:16:3e:ed:9a:59": "eth0",
},
"out_sysconfig_opensuse": [
(
"etc/sysconfig/network/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=static
IPADDR=172.19.1.34
IPADDR6=2001:DB8::10/64
IPADDR6_1=2001:DB9::10/64
IPADDR6_2=2001:DB10::10/64
LLADDR=fa:16:3e:ed:9a:59
NETMASK=255.255.252.0
STARTMODE=auto
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/85-persistent-net-cloud-init.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
"out_sysconfig_rhel": [
(
"etc/sysconfig/network-scripts/ifcfg-eth0",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=none
DEFROUTE=yes
DEVICE=eth0
GATEWAY=172.19.3.254
HWADDR=fa:16:3e:ed:9a:59
IPADDR=172.19.1.34
IPV6ADDR=2001:DB8::10/64
IPV6ADDR_SECONDARIES="2001:DB9::10/64 2001:DB10::10/64"
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6_DEFAULTGW=2001:DB8::1
IPV6_FORCE_ACCEPT_RA=no
NETMASK=255.255.252.0
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
""".lstrip(),
),
(
"etc/resolv.conf",
"""
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 172.19.0.12
""".lstrip(),
),
(
"etc/NetworkManager/conf.d/99-cloud-init.conf",
"""
# Created by cloud-init on instance boot automatically, do not edit.
#
[main]
dns = none
""".lstrip(),
),
(
"etc/udev/rules.d/70-persistent-net.rules",
"".join(
[
'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ',
'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n',
]
),
),
],
},
]
EXAMPLE_ENI = """
auto lo
iface lo inet loopback
dns-nameservers 10.0.0.1
dns-search foo.com
auto eth0
iface eth0 inet static
address 1.2.3.12
netmask 255.255.255.248
broadcast 1.2.3.15
gateway 1.2.3.9
dns-nameservers 69.9.160.191 69.9.191.4
auto eth1
iface eth1 inet static
address 10.248.2.4
netmask 255.255.255.248
broadcast 10.248.2.7
"""
RENDERED_ENI = """
auto lo
iface lo inet loopback
dns-nameservers 10.0.0.1
dns-search foo.com
auto eth0
iface eth0 inet static
address 1.2.3.12/29
broadcast 1.2.3.15
dns-nameservers 69.9.160.191 69.9.191.4
gateway 1.2.3.9
auto eth1
iface eth1 inet static
address 10.248.2.4/29
broadcast 10.248.2.7
""".lstrip()
NETWORK_CONFIGS = {
"small": {
"expected_networkd_eth99": textwrap.dedent(
"""\
[Match]
Name=eth99
MACAddress=c0:d6:9f:2c:e8:80
[Address]
Address=192.168.21.3/24
[Network]
DHCP=ipv4
Domains=barley.maas sach.maas
Domains=wark.maas
DNS=1.2.3.4 5.6.7.8
DNS=8.8.8.8 8.8.4.4
[Route]