~curtin-dev/curtin/trunk

« back to all changes in this revision

Viewing changes to tests/vmtests/test_network_vlan.py

  • Committer: Ryan Harper
  • Date: 2016-08-29 21:06:46 UTC
  • mfrom: (416.4.28 trunk.more-ipv6)
  • Revision ID: ryan.harper@canonical.com-20160829210646-1f9pv8r691iggedz
curtin/net: overhaul of eni rendering to handle mixed ipv4/ipv6 configs

To ensure complete ipv4/ipv6 support for advanced and stacked
configurations update how curtin.net renders /etc/network/interfaces for
different releases (precise -> yakkety). ifupdown has subtle issues with
various networking features and curtin needs to ensure consistent
behavior.

- Propery handle emitting the 'auto' control tag for stacked interfaces,
  like vlans over bonds
- Workaround LP:1609367 by rendering ifupdown hooks to handle the various
  cases. This works generically in all ubuntu releases 
- Add vmtests for mtu settings
- Drop the use of ipv4 alias interfaces (eth0:1, eth0:2) and instead just
  add additional e/n/i stanzas. ifupdown already uses iproute2's /sbin/ip
  which supports adding additional ip addresses to an interface without the
  use of the v4-only interface alias structure. This provides consistent
  behavior for all types of interfaces (physical, vlan, bonds, and stacked
  interfaces) across all releases. Two side-effects: 1) users can no longer
  `ifdown eth0:1` to remove a single ip address from an interface; if down
  eth0 will take _all_ ip addresses on that interface. 2) ifconfig output
  only shows *one* ipv4 address, so users will need to use /sbin/ip addr
  show <interface> to see all ip addresses assigned to an interface.
- Add vmtests for alias settings
- Restructure all of the common network testcases into a single class
  TestNetworkTestBaseAbs, all varients testing network inherit from this
  class and override only the config file and any special case test-cases
  and file collection
- Global replace of testcase use of 'with open' and instead use
  load_collect_file()
  - Fix falsepositive uefi and multipath test this replacement exposed.
- Add ip_a_to_dict parser for `/sbin/ip a` output
  - drop ifconfig_a parser

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from . import logger
 
2
from .releases import base_vm_classes as relbase
 
3
from .test_network import TestNetworkBaseTestsAbs
 
4
 
 
5
import textwrap
 
6
import yaml
 
7
 
 
8
 
 
9
class TestNetworkVlanAbs(TestNetworkBaseTestsAbs):
 
10
    conf_file = "examples/tests/vlan_network.yaml"
 
11
    collect_scripts = TestNetworkBaseTestsAbs.collect_scripts + [
 
12
        textwrap.dedent("""
 
13
             cd OUTPUT_COLLECT_D
 
14
             dpkg-query -W -f '${Status}' vlan > vlan_installed
 
15
             ip -d link show interface1.2667 > ip_link_show_interface1.2667
 
16
             ip -d link show interface1.2668 > ip_link_show_interface1.2668
 
17
             ip -d link show interface1.2669 > ip_link_show_interface1.2669
 
18
             ip -d link show interface1.2670 > ip_link_show_interface1.2670
 
19
             """)]
 
20
 
 
21
    def get_vlans(self):
 
22
        network_state = self.get_network_state()
 
23
        logger.debug('get_vlans ns:\n%s', yaml.dump(network_state,
 
24
                                                    default_flow_style=False,
 
25
                                                    indent=4))
 
26
        interfaces = network_state.get('interfaces')
 
27
        return [iface for iface in interfaces.values()
 
28
                if iface['type'] == 'vlan']
 
29
 
 
30
    def test_output_files_exist_vlan(self):
 
31
        link_files = ["ip_link_show_%s" % vlan['name']
 
32
                      for vlan in self.get_vlans()]
 
33
        self.output_files_exist(["vlan_installed"] + link_files)
 
34
 
 
35
    def test_vlan_installed(self):
 
36
        status = self.load_collect_file("vlan_installed").strip()
 
37
        logger.debug('vlan installed?: %s', status)
 
38
        self.assertEqual('install ok installed', status)
 
39
 
 
40
    def test_vlan_enabled(self):
 
41
 
 
42
        # we must have at least one
 
43
        self.assertGreaterEqual(len(self.get_vlans()), 1)
 
44
 
 
45
        # did they get configured?
 
46
        for vlan in self.get_vlans():
 
47
            link_file = "ip_link_show_" + vlan['name']
 
48
            vlan_msg = "vlan protocol 802.1Q id " + str(vlan['vlan_id'])
 
49
            self.check_file_regex(link_file, vlan_msg)
 
50
 
 
51
 
 
52
class PreciseTestNetworkVlan(relbase.precise, TestNetworkVlanAbs):
 
53
    __test__ = True
 
54
 
 
55
    # precise ip -d link show output is different (of course)
 
56
    def test_vlan_enabled(self):
 
57
 
 
58
        # we must have at least one
 
59
        self.assertGreaterEqual(len(self.get_vlans()), 1)
 
60
 
 
61
        # did they get configured?
 
62
        for vlan in self.get_vlans():
 
63
            link_file = "ip_link_show_" + vlan['name']
 
64
            vlan_msg = "vlan id " + str(vlan['vlan_id'])
 
65
            self.check_file_regex(link_file, vlan_msg)
 
66
 
 
67
 
 
68
class TrustyTestNetworkVlan(relbase.trusty, TestNetworkVlanAbs):
 
69
    __test__ = True
 
70
 
 
71
 
 
72
class XenialTestNetworkVlan(relbase.xenial, TestNetworkVlanAbs):
 
73
    __test__ = True
 
74
 
 
75
 
 
76
class YakketyTestNetworkVlan(relbase.yakkety, TestNetworkVlanAbs):
 
77
    __test__ = True