149
iface lo inet loopback
150
dns-nameservers 10.0.0.1
154
iface eth0 inet static
156
netmask 255.255.255.248
159
dns-nameservers 69.9.160.191 69.9.191.4
161
iface eth1 inet static
163
netmask 255.255.255.248
169
iface lo inet loopback
170
dns-nameservers 10.0.0.1
174
iface eth0 inet static
177
dns-nameservers 69.9.160.191 69.9.191.4
179
netmask 255.255.255.248
182
iface eth1 inet static
185
netmask 255.255.255.248
190
'expected_eni': textwrap.dedent("""\
192
iface lo inet loopback
193
dns-nameservers 1.2.3.4 5.6.7.8
196
iface eth1 inet manual
199
iface eth99 inet dhcp
204
iface eth99:1 inet static
205
address 192.168.21.3/24
206
dns-nameservers 8.8.8.8 8.8.4.4
207
dns-search barley.maas sach.maas
208
post-up route add default gw 65.61.151.37 || true
209
pre-down route del default gw 65.61.151.37 || true
211
'yaml': textwrap.dedent("""
214
# Physical interfaces.
217
mac_address: "c0:d6:9f:2c:e8:80"
221
address: 192.168.21.3/24
225
dns_search: barley.maas sach.maas
227
- gateway: 65.61.151.37
233
mac_address: "cf:d6:af:48:e8:80"
243
'expected_eni': ("""\
245
iface lo inet loopback
246
dns-nameservers 8.8.8.8 4.4.4.4 8.8.4.4
247
dns-search barley.maas wark.maas foobar.maas
249
iface eth0 inet manual
252
iface eth1 inet manual
254
bond-mode active-backup
257
iface eth2 inet manual
259
bond-mode active-backup
261
iface eth3 inet manual
263
iface eth4 inet manual
265
# control-manual eth5
269
iface bond0 inet6 dhcp
270
bond-mode active-backup
272
hwaddress aa:bb:cc:dd:ee:ff
275
iface br0 inet static
276
address 192.168.14.2/24
277
bridge_ports eth3 eth4
283
iface br0:1 inet6 static
287
iface bond0.200 inet dhcp
288
vlan-raw-device bond0
292
iface eth0.101 inet static
293
address 192.168.0.2/24
294
dns-nameservers 192.168.0.10 10.23.23.134
295
dns-search barley.maas sacchromyces.maas brettanomyces.maas
300
post-up ifup eth0.101:1
304
iface eth0.101:1 inet static
305
address 192.168.2.10/24
307
post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
308
pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true
310
'yaml': textwrap.dedent("""
313
# Physical interfaces.
316
mac_address: "c0:d6:9f:2c:e8:80"
319
mac_address: "aa:d6:9f:2c:e8:80"
322
mac_address: "c0:bb:9f:2c:e8:80"
325
mac_address: "66:bb:9f:2c:e8:80"
328
mac_address: "98:bb:9f:2c:e8:80"
329
# specify how ifupdown should treat iface
330
# control is one of ['auto', 'hotplug', 'manual']
331
# with manual meaning ifup/ifdown should not affect the iface
332
# useful for things like iscsi root + dhcp
335
mac_address: "98:bb:9f:2c:e8:8a"
347
address: 192.168.0.2/24
357
address: 192.168.2.10/24
361
# if 'mac_address' is omitted, the MAC is taken from
363
mac_address: "aa:bb:cc:dd:ee:ff"
368
bond-mode: active-backup
393
# basically anything in /proc/sys/net/ipv6/conf/.../
400
address: 192.168.14.2/24
402
address: 2001:1::1/64 # default to /64
403
# A global nameserver.
407
# global nameservers and search in list form
417
destination: 10.0.0.0/8
145
425
def _setup_test(tmp_dir, mock_get_devicelist, mock_sys_netdev_info,
146
426
mock_sys_dev_path):
354
634
self.assertEqual(found, self.simple_cfg)
637
class TestEniRoundTrip(TestCase):
639
super(TestCase, self).setUp()
640
self.tmp_dir = tempfile.mkdtemp()
641
self.addCleanup(shutil.rmtree, self.tmp_dir)
643
def _render_and_read(self, network_config=None, state=None, eni_path=None,
644
links_prefix=None, netrules_path=None):
646
ns = network_state.parse_net_config_data(network_config)
650
raise ValueError("Expected data or state, got neither")
653
eni_path = 'etc/network/interfaces'
655
renderer = eni.Renderer(
656
config={'eni_path': eni_path, 'links_path_prefix': links_prefix,
657
'netrules_path': netrules_path})
659
renderer.render_network_state(self.tmp_dir, ns)
660
return dir2dict(self.tmp_dir)
662
def testsimple_convert_and_render(self):
663
network_config = eni.convert_eni_data(EXAMPLE_ENI)
664
files = self._render_and_read(network_config=network_config)
666
RENDERED_ENI.splitlines(),
667
files['/etc/network/interfaces'].splitlines())
669
def testsimple_render_all(self):
670
entry = NETWORK_CONFIGS['all']
671
files = self._render_and_read(network_config=yaml.load(entry['yaml']))
673
entry['expected_eni'].splitlines(),
674
files['/etc/network/interfaces'].splitlines())
676
def testsimple_render_small(self):
677
entry = NETWORK_CONFIGS['small']
678
files = self._render_and_read(network_config=yaml.load(entry['yaml']))
680
entry['expected_eni'].splitlines(),
681
files['/etc/network/interfaces'].splitlines())
357
684
def _gzip_data(data):
358
685
with io.BytesIO() as iobuf:
359
686
gzfp = gzip.GzipFile(mode="wb", fileobj=iobuf)