diff options
| -rw-r--r-- | cloudinit/sources/helpers/digitalocean.py | 2 | ||||
| -rw-r--r-- | tests/unittests/test_datasource/test_digitalocean.py | 25 | 
2 files changed, 26 insertions, 1 deletions
| diff --git a/cloudinit/sources/helpers/digitalocean.py b/cloudinit/sources/helpers/digitalocean.py index 257989e8..693f8d5c 100644 --- a/cloudinit/sources/helpers/digitalocean.py +++ b/cloudinit/sources/helpers/digitalocean.py @@ -162,7 +162,7 @@ def convert_network_configuration(config, dns_servers):                  continue              sub_part = _get_subnet_part(raw_subnet) -            if netdef in ('private', 'anchor_ipv4', 'anchor_ipv6'): +            if nic_type != "public" or "anchor" in netdef:                  del sub_part['gateway']              subnets.append(sub_part) diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py index a11166a9..e97a679a 100644 --- a/tests/unittests/test_datasource/test_digitalocean.py +++ b/tests/unittests/test_datasource/test_digitalocean.py @@ -1,6 +1,8 @@  # Copyright (C) 2014 Neal Shrader  #  # Author: Neal Shrader <neal@digitalocean.com> +# Author: Ben Howard <bh@digitalocean.com> +# Author: Scott Moser <smoser@ubuntu.com>  #  # This file is part of cloud-init. See LICENSE file for license information. @@ -262,6 +264,29 @@ class TestNetworkConvert(TestCase):                  print(json.dumps(subn, indent=3))                  return subn +    def test_correct_gateways_defined(self): +        """test to make sure the eth0 ipv4 and ipv6 gateways are defined""" +        netcfg = self._get_networking() +        gateways = [] +        for nic_def in netcfg.get('config'): +            if nic_def.get('type') != 'physical': +                continue +            for subn in nic_def.get('subnets'): +                if 'gateway' in subn: +                    gateways.append(subn.get('gateway')) + +        # we should have two gateways, one ipv4 and ipv6 +        self.assertEqual(len(gateways), 2) + +        # make that the ipv6 gateway is there +        (nic_def, meta_def) = self._get_nic_definition('public', 'eth0') +        ipv4_def = meta_def.get('ipv4') +        self.assertIn(ipv4_def.get('gateway'), gateways) + +        # make sure the the ipv6 gateway is there +        ipv6_def = meta_def.get('ipv6') +        self.assertIn(ipv6_def.get('gateway'), gateways) +      def test_public_interface_defined(self):          """test that the public interface is defined as eth0"""          (nic_def, meta_def) = self._get_nic_definition('public', 'eth0') | 
