Catch exceptions when processing subnets

We should do a better job indicating that there is invalid data in the
extra subnets that can be defined. This change catches exceptions that
occur when generating the inspection subnet data.

Change-Id: I175ff32ba5e5a271741349794cf28f1e58c50d6a
Closes-Bug: #1857057
This commit is contained in:
Alex Schultz 2019-12-19 15:31:37 -07:00
parent 87c4c66f39
commit e970ca3cdf
2 changed files with 43 additions and 16 deletions

View File

@ -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):

View File

@ -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