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
(cherry picked from commit e970ca3cdf
)
This commit is contained in:
parent
585fb2816c
commit
be999f122f
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue