← 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
> @@ -67,6 +67,11 @@
>  #     }
>  # }
>  
> +import re
> +
> +ipv4 = re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")

We need to escape the dot otherwise we match any one character.  This should be "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"

> +
> +
>  def translate_network(settings):
>      # Get the standard cmd, args from the ubuntu format
>      entries = []
> 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

Thanks for adding unit tests for this uncovered module. 

We are generally starting to move test modules to the tests subdirectory under the related module path.
Since it's a new test module, can we instead create a cloudinit/distros/tests subdir, touch cloudinit/distros/tests/__init__.py and git mv tests/unittests/test_distros/text_net_util.py cloudinit/distros/tests/test_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 = '''
> +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
> +
> +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