← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~rjschwei/cloud-init:netV1ToTranslate into cloud-init:master

 


Diff comments:

> diff --git a/cloudinit/distros/net_util.py b/cloudinit/distros/net_util.py
> index 1ce1aa7..fad062d 100644
> --- a/cloudinit/distros/net_util.py
> +++ b/cloudinit/distros/net_util.py
> @@ -148,6 +160,16 @@ def translate_network(settings):
>                      hw_addr = hw_split[1]
>                      if hw_addr:
>                          iface_info['hwaddress'] = hw_addr
> +            if 'post-up' in info:
> +                routes = info['post-up']
> +                if isinstance(routes, list):
> +                    for route_info in routes:
> +                        if 'default gw' in route_info:
> +                            iface_info['gateway'] = ipv4.search(
> +                                route_info).group(0)
> +                elif 'default gw' in routes:

What is the second case where you have post-up in eni but routes is not a list?

> +                    iface_info['gateway'] = ipv4.search(routes).group(0)
> +
>          # If ipv6 is enabled, device will have multiple IPs, so we need to
>          # update the dictionary instead of overwriting it...
>          if dev_name in real_ifaces:
> diff --git a/tests/unittests/test_distros/text_net_util.py b/tests/unittests/test_distros/text_net_util.py
> new file mode 100644
> index 0000000..93426cf
> --- /dev/null
> +++ b/tests/unittests/test_distros/text_net_util.py
> @@ -0,0 +1,103 @@
> +# This file is part of cloud-init. See LICENSE file for license information.
> +
> +from cloudinit.distros import net_util
> +
> +from cloudinit.tests.helpers import CiTestCase
> +
> +
> +class TestNetworkConfigTransform(CiTestCase):
> +
> +    def test_basic_config_ipv4(self):
> +        basic_conf = '''

You can use textwrap.dedent() so the config doesn't have to be left-aligned.
Alternatively, you can device the basic_conf at the top of the file and reference it.

> +auto lo
> +iface lo inet loopback
> +
> +auto eth0
> +iface eth0 inet static
> +    address 192.168.1.5
> +    broadcast 192.168.1.0
> +    gateway 192.168.1.254
> +    netmask 255.255.255.0
> +    network 192.168.0.0
> +
> +auto eth1
> +iface eth1 inet dhcp
> +'''
> +        sysconfig = net_util.translate_network(basic_conf)
> +        expected = {
> +            'lo': {'auto': True, 'ipv6': {}},
> +            'eth0': {
> +                'auto': True,
> +                'ipv6': {},
> +                'broadcast': '192.168.1.0',
> +                'netmask': '255.255.255.0',
> +                'bootproto': 'static',
> +                'address': '192.168.1.5',
> +                'gateway': '192.168.1.254'
> +            },
> +            'eth1': {'auto': True, 'bootproto': 'dhcp', 'ipv6': {}}
> +        }
> +        self.assertEqual(sysconfig, expected)
> +
> +    def test_v1_confi_single_route_ipv4(self):
> +        v1_conf = '''
> +auto lo
> +iface lo inet loopback
> +
> +auto eth0
> +iface eth0 inet static
> +    hwaddress fa:16:3e:ee:2b:97
> +    address 192.168.168.30/24
> +    mtu 1500
> +    post-up route add default gw 192.168.168.1 || true
> +    pre-down route del default gw 192.168.168.1 || true
> +'''
> +        sysconfig = net_util.translate_network(v1_conf)
> +        expected = {
> +            'lo': {'auto': True, 'ipv6': {}},
> +            'eth0': {
> +                'auto': True,
> +                'bootproto': 'static',
> +                'gateway': '192.168.168.1',
> +                'address': '192.168.168.30/24',
> +                'ipv6': {}
> +            }
> +        }
> +        self.assertEqual(sysconfig, expected)
> +
> +    def test_v1_confi_multi_route_multi_nic_ipv4(self):
> +        v1_conf = '''
> +auto lo
> +iface lo inet loopback
> +
> +auto eth0
> +iface eth0 inet static
> +    hwaddress fa:16:3e:ee:2b:97
> +    address 192.168.168.30/24
> +    mtu 1500
> +    post-up route add default gw 192.168.168.1 || true
> +    pre-down route del default gw 192.168.168.1 || true

It may be worth adding a unittest that covers both your paths in the translate (one where routes is a list and a string).

Also, adding a config with multiple routes (a gateway and a secondary route).

> +
> +auto eth1
> +iface eth1 inet dhcp
> +    post-up route add 192.168.168.1 || true
> +'''
> +        sysconfig = net_util.translate_network(v1_conf)
> +        expected = {
> +            'lo': {'auto': True, 'ipv6': {}},
> +            'eth0': {
> +                'auto': True,
> +                'bootproto': 'static',
> +                'gateway': '192.168.168.1',
> +                'address': '192.168.168.30/24',
> +                'ipv6': {}
> +            },
> +            'eth1': {
> +                'auto': True,
> +                'bootproto': 'dhcp',
> +                'ipv6': {}
> +            }
> +        }
> +        self.assertEqual(sysconfig, expected)
> +
> +# vi: ts=4 expandtab


-- 
https://code.launchpad.net/~rjschwei/cloud-init/+git/cloud-init/+merge/333904
Your team cloud-init commiters is requested to review the proposed merge of ~rjschwei/cloud-init:netV1ToTranslate into cloud-init:master.


References