1
from . import logger, helpers
2
from .releases import base_vm_classes as relbase
3
from .test_network import TestNetworkBaseTestsAbs
10
class TestNetworkENISource(TestNetworkBaseTestsAbs):
11
""" Curtin now emits a source /etc/network/interfaces.d/*.cfg
12
line. This test exercises this feature by emitting additional
13
network configuration in /etc/network/interfaces.d/interface2.cfg
15
This relies on the network_config.yaml of the TestClass to
16
define a spare nic with no configuration. This ensures that
17
a udev rule for interface2 is emitted so we can reference the interface
18
in our injected configuration.
20
Note, ifupdown allows multiple stanzas with the same iface name
21
and combines the options together during ifup. We rely on this
22
feature allowing etc/network/interfaces to have an unconfigured
23
iface interface2 inet manual line, and then defer the configuration
24
to /etc/network/interfaces.d/interface2.cfg
26
This testcase then uses curtin.net.deb_parse_config method to
27
extract information about what curtin wrote and compare that
28
with what was actually configured (which we capture via ifconfig)
31
conf_file = "examples/tests/network_source.yaml"
33
def test_source_cfg_exists(self):
34
"""Test that our curthooks wrote our injected config."""
35
self.output_files_exist(["interfaces.d/interface2.cfg"])
37
def test_etc_network_interfaces_source_cfg(self):
38
""" Compare injected configuration as parsed by curtin matches
39
how ifup configured the interface."""
40
# interfaces uses absolute paths, fix for test-case
41
interfaces = os.path.join(self.td.collect, "interfaces")
42
cmd = ['sed', '-i.orig', '-e', 's,/etc/network/,,g',
43
'{}'.format(interfaces)]
44
subprocess.check_call(cmd, stderr=subprocess.STDOUT)
46
curtin_ifaces = self.parse_deb_config(interfaces)
47
logger.debug('parsed eni dict:\n{}'.format(
48
yaml.dump(curtin_ifaces, default_flow_style=False, indent=4)))
49
print('parsed eni dict:\n{}'.format(
50
yaml.dump(curtin_ifaces, default_flow_style=False, indent=4)))
52
ip_a = self.load_collect_file("ip_a")
53
logger.debug('ip a:\n{}'.format(ip_a))
55
ip_a_dict = helpers.ip_a_to_dict(ip_a)
56
logger.debug('parsed ip_a dict:\n{}'.format(
57
yaml.dump(ip_a_dict, default_flow_style=False, indent=4)))
58
print('parsed ip_a dict:\n{}'.format(
59
yaml.dump(ip_a_dict, default_flow_style=False, indent=4)))
62
self.assertTrue(iface in curtin_ifaces)
64
expected_address = curtin_ifaces[iface].get('address', None)
65
self.assertIsNotNone(expected_address)
67
# handle CIDR notation
69
return addr.split("/")[0]
71
[actual_address] = [ip.get('address') for ip in
72
ip_a_dict[iface].get('inet4', [])]
73
self.assertEqual(_nocidr(expected_address), _nocidr(actual_address))
76
class PreciseTestNetworkENISource(relbase.precise, TestNetworkENISource):
78
# not working, still debugging though; possible older ifupdown doesn't
79
# like the multiple iface method.
82
class TrustyTestNetworkENISource(relbase.trusty, TestNetworkENISource):
86
class XenialTestNetworkENISource(relbase.xenial, TestNetworkENISource):
90
class YakketyTestNetworkENISource(relbase.yakkety, TestNetworkENISource):