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 | diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 2f505d9..4faf2c8 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -161,6 +161,24 @@ network:
dhcp4: true
"""
+V1_BOND_VLAN_CFG = {'config': [{'name': 'eth0',
+ 'type': 'physical'},
+ {'name': 'eth1',
+ 'type': 'physical'},
+ {'name': 'bond0',
+ 'type': 'bond',
+ 'bond_interfaces': ['eth0', 'eth1'],
+ 'params': {'bond-mode': 'active-backup'},
+ 'subnets': [{'type': 'static',
+ 'address': '10.23.23.2/24'}]},
+ {'name': 'bond0.99',
+ 'type': 'vlan',
+ 'vlan_id': 99,
+ 'vlan_link': 'bond0',
+ 'subnets': [{'type': 'static',
+ 'address': '192.168.31/24'}]}],
+ 'version': 1}
+
class WriteBuffer(object):
def __init__(self):
@@ -666,6 +684,127 @@ IPV6_AUTOCONF=no
self.assertCfgEquals(expected_buf, str(write_buf))
self.assertEqual(write_buf.mode, 0o644)
+ def test_apply_network_config_rh_virtual(self):
+ """Test sysconfig rendering of virtual interfaces with subnets"""
+ renderers = ['sysconfig']
+ rh_distro = self._get_distro('rhel', renderers=renderers)
+
+ write_bufs = {}
+
+ def replace_write(filename, content, mode=0o644, omode="wb"):
+ buf = WriteBuffer()
+ buf.mode = mode
+ buf.omode = omode
+ buf.write(content)
+ write_bufs[filename] = buf
+
+ with ExitStack() as mocks:
+ # sysconfig availability checks
+ mocks.enter_context(
+ mock.patch.object(util, 'which', return_value=True))
+ mocks.enter_context(
+ mock.patch.object(util, 'write_file', replace_write))
+ mocks.enter_context(
+ mock.patch.object(util, 'load_file', return_value=''))
+ mocks.enter_context(
+ mock.patch.object(os.path, 'isfile', return_value=True))
+
+ rh_distro.apply_network_config(V1_BOND_VLAN_CFG, False)
+
+ self.assertEqual(len(write_bufs), 7)
+
+ # network
+ self.assertIn('/etc/sysconfig/network', write_bufs)
+ write_buf = write_bufs['/etc/sysconfig/network']
+ expected_buf = '''
+# Created by cloud-init v. 0.7
+NETWORKING=yes
+'''
+ self.assertCfgEquals(expected_buf, str(write_buf))
+ self.assertEqual(write_buf.mode, 0o644)
+
+ # eth0
+ ifcfg = '/etc/sysconfig/network-scripts/ifcfg-eth0'
+ self.assertIn(ifcfg, write_bufs)
+ write_buf = write_bufs[ifcfg]
+ expected_buf = '''
+# Created by cloud-init on instance boot automatically, do not edit.
+#
+BOOTPROTO=none
+DEVICE=eth0
+MASTER=bond0
+NM_CONTROLLED=no
+ONBOOT=yes
+SLAVE=yes
+TYPE=Ethernet
+USERCTL=no
+'''
+ self.assertCfgEquals(expected_buf, str(write_buf))
+ self.assertEqual(write_buf.mode, 0o644)
+
+ # eth1
+ ifcfg = '/etc/sysconfig/network-scripts/ifcfg-eth1'
+ self.assertIn(ifcfg, write_bufs)
+ write_buf = write_bufs[ifcfg]
+ expected_buf = '''
+# Created by cloud-init on instance boot automatically, do not edit.
+#
+BOOTPROTO=none
+DEVICE=eth1
+MASTER=bond0
+NM_CONTROLLED=no
+ONBOOT=yes
+SLAVE=yes
+TYPE=Ethernet
+USERCTL=no
+'''
+ self.assertCfgEquals(expected_buf, str(write_buf))
+ self.assertEqual(write_buf.mode, 0o644)
+
+ # bond0
+ ifcfg = '/etc/sysconfig/network-scripts/ifcfg-bond0'
+ self.assertIn(ifcfg, write_bufs)
+ write_buf = write_bufs[ifcfg]
+ expected_buf = '''
+# Created by cloud-init on instance boot automatically, do not edit.
+#
+BONDING_MASTER=yes
+BONDING_OPTS=mode=active-backup
+BONDING_SLAVE0=eth0
+BONDING_SLAVE1=eth1
+BOOTPROTO=none
+DEVICE=bond0
+IPADDR=10.23.23.2
+NETMASK=255.255.255.0
+NM_CONTROLLED=no
+ONBOOT=yes
+TYPE=Bond
+USERCTL=no
+'''
+ self.assertCfgEquals(expected_buf, str(write_buf))
+ self.assertEqual(write_buf.mode, 0o644)
+
+ # bond0.99
+ ifcfg = '/etc/sysconfig/network-scripts/ifcfg-bond0.99'
+ self.assertIn(ifcfg, write_bufs)
+ write_buf = write_bufs[ifcfg]
+ expected_buf = '''
+# Created by cloud-init on instance boot automatically, do not edit.
+#
+BOOTPROTO=none
+DEVICE=bond0.99
+IPADDR=192.168.31
+NETMASK=255.255.255.0
+NM_CONTROLLED=no
+ONBOOT=yes
+PHYSDEV=bond0
+TYPE=Ethernet
+USERCTL=no
+VLAN=yes
+'''
+ self.assertCfgEquals(expected_buf, str(write_buf))
+ self.assertEqual(write_buf.mode, 0o644)
+
def test_simple_write_freebsd(self):
fbsd_distro = self._get_distro('freebsd')
|