diff --git a/tripleoclient/tests/v1/undercloud/test_config.py b/tripleoclient/tests/v1/undercloud/test_config.py index 624b43792..5ec75ee4e 100644 --- a/tripleoclient/tests/v1/undercloud/test_config.py +++ b/tripleoclient/tests/v1/undercloud/test_config.py @@ -874,6 +874,26 @@ class TestNetworkSettings(base.TestCase): } self.assertEqual(expected, env) + def test_generate_inspection_subnets(self): + result = undercloud_config._generate_inspection_subnets() + expected = [{'gateway': '192.168.24.1', + 'host_routes': [], + 'ip_range': '192.168.24.100,192.168.24.120', + 'mtu': 1500, + 'netmask': '255.255.255.0', + 'tag': 'ctlplane-subnet'}] + self.assertEqual(expected, result) + + def test_generate_inspection_subnets_invalid(self): + self.conf.config(subnets=['ctlplane-subnet', 'subnet1']) + self.conf.config(host_routes=[{'destination': '10.10.10.254/32', + 'nexthop': '192.168.24.1'}], + group='ctlplane-subnet') + self.conf.register_opts(self.opts, group=self.grp1) + self.conf.config(group='subnet1') + self.assertRaises(exceptions.DeploymentError, + undercloud_config._generate_inspection_subnets) + class TestTLSSettings(base.TestCase): def test_public_host_with_ip_should_give_ip_endpoint_environment(self): diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index 68140dcfd..3d94893cd 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -224,23 +224,30 @@ def _generate_inspection_subnets(): env_dict = {} s = CONF.get(subnet) env_dict['tag'] = subnet - if netaddr.IPNetwork(s.cidr).version == 4: - env_dict['ip_range'] = s.inspection_iprange - if netaddr.IPNetwork(s.cidr).version == 6: - if CONF['ipv6_address_mode'] == 'dhcpv6-stateful': + try: + if netaddr.IPNetwork(s.cidr).version == 4: env_dict['ip_range'] = s.inspection_iprange - if CONF['ipv6_address_mode'] == 'dhcpv6-stateless': - # dnsmasq(8): A static-only subnet with address all zeros may - # be used as a "catch-all" address to enable replies to all - # Information-request packets on a subnet which is provided - # with stateless DHCPv6, ie --dhcp-range=::,static - env_dict['ip_range'] = ','.join( - [str(netaddr.IPNetwork(s.cidr).ip), 'static']) - env_dict['netmask'] = str(netaddr.IPNetwork(s.cidr).netmask) - env_dict['gateway'] = s.gateway - env_dict['host_routes'] = s.host_routes - env_dict['mtu'] = CONF.local_mtu - env_list.append(env_dict) + if netaddr.IPNetwork(s.cidr).version == 6: + if CONF['ipv6_address_mode'] == 'dhcpv6-stateful': + env_dict['ip_range'] = s.inspection_iprange + if CONF['ipv6_address_mode'] == 'dhcpv6-stateless': + # dnsmasq(8): A static-only subnet with address all zeros + # may be used as a "catch-all" address to enable replies to + # all Information-request packets on a subnet which is + # provided with stateless DHCPv6, ie --dhcp-range=::,static + env_dict['ip_range'] = ','.join( + [str(netaddr.IPNetwork(s.cidr).ip), 'static']) + env_dict['netmask'] = str(netaddr.IPNetwork(s.cidr).netmask) + env_dict['gateway'] = s.gateway + env_dict['host_routes'] = s.host_routes + env_dict['mtu'] = CONF.local_mtu + env_list.append(env_dict) + except Exception as e: + msg = _('Invalid configuration data in subnet "{}". Double check ' + 'the settings for this subnet. Error: {}').format(subnet, + e) + LOG.error(msg) + raise exceptions.DeploymentError(msg) return env_list