Generate routes for undercloud ctlplane network attrs

In https://review.opendev.org/753195 we set up ctlplane
network attributes and later use those in THT when setting
group_vars for os_net_config templates in ansible.

The change missed to add 'host_routes' for peer-subnets in
a spine-and-leaf set-up. This caused introspection and
provisioning to fail in spine-and-leaf set-ups because the
undercloud did'nt know how to reach the remote subnets.

This change updates the code to include calculated routes
to the remote subnets.

Change-Id: I265b2b586ceaeaa98bbf6073bb79cde6a91627da
Closes-Bug: #1899008
This commit is contained in:
Harald Jensås 2020-10-08 13:41:42 +02:00
parent 0aded9ecb1
commit 6ac7c08257
2 changed files with 59 additions and 13 deletions

View File

@ -558,8 +558,8 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_config._process_network_args(env) undercloud_config._process_network_args(env)
expected = { expected = {
'ControlPlaneStaticRoutes': [ 'ControlPlaneStaticRoutes': [
{'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'},
{'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}], {'destination': '192.168.20.0/24', 'nexthop': '192.168.24.1'}],
'IronicInspectorSubnets': [ 'IronicInspectorSubnets': [
{'gateway': '192.168.24.1', {'gateway': '192.168.24.1',
'host_routes': [], 'host_routes': [],
@ -647,8 +647,8 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_config._process_network_args(env) undercloud_config._process_network_args(env)
expected = { expected = {
'ControlPlaneStaticRoutes': [ 'ControlPlaneStaticRoutes': [
{'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'},
{'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}], {'destination': '192.168.20.0/24', 'nexthop': '192.168.24.1'}],
'IronicInspectorSubnets': [ 'IronicInspectorSubnets': [
{'gateway': '192.168.24.1', {'gateway': '192.168.24.1',
'host_routes': [], 'host_routes': [],
@ -716,7 +716,7 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_config._process_network_args(env) undercloud_config._process_network_args(env)
expected = { expected = {
'ControlPlaneStaticRoutes': [ 'ControlPlaneStaticRoutes': [
{'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}], {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'}],
'IronicInspectorSubnets': [ 'IronicInspectorSubnets': [
{'gateway': '192.168.24.1', {'gateway': '192.168.24.1',
'host_routes': [], 'host_routes': [],
@ -770,7 +770,7 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_config._process_network_args(env) undercloud_config._process_network_args(env)
expected = { expected = {
'ControlPlaneStaticRoutes': [ 'ControlPlaneStaticRoutes': [
{'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}], {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'}],
'IronicInspectorSubnets': [ 'IronicInspectorSubnets': [
{'gateway': '192.168.24.1', {'gateway': '192.168.24.1',
'host_routes': [], 'host_routes': [],
@ -842,9 +842,9 @@ class TestNetworkSettings(TestBaseNetworkSettings):
undercloud_config._process_network_args(env) undercloud_config._process_network_args(env)
expected = { expected = {
'ControlPlaneStaticRoutes': [ 'ControlPlaneStaticRoutes': [
{'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'},
{'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}, {'destination': '192.168.20.0/24', 'nexthop': '192.168.24.1'},
{'ip_netmask': '10.10.10.254/32', 'next_hop': '192.168.24.1'}], {'destination': '10.10.10.254/32', 'nexthop': '192.168.24.1'}],
'IronicInspectorSubnets': [ 'IronicInspectorSubnets': [
{'gateway': '192.168.24.1', {'gateway': '192.168.24.1',
'host_routes': [{'destination': '10.10.10.254/32', 'host_routes': [{'destination': '10.10.10.254/32',
@ -949,6 +949,52 @@ class TestNetworkSettings(TestBaseNetworkSettings):
'tags': []}}}} 'tags': []}}}}
self.assertEqual(expected, env) self.assertEqual(expected, env)
def test__env_set_undercloud_ctlplane_networks_attribues_routed(self):
self.conf.config(subnets=['ctlplane-subnet', 'subnet1', 'subnet2'])
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.register_opts(self.opts, group=self.grp2)
self.conf.config(cidr='192.168.10.0/24',
dhcp_start='192.168.10.10',
dhcp_end='192.168.10.99',
dhcp_exclude=[],
inspection_iprange='192.168.10.100,192.168.10.189',
gateway='192.168.10.254',
dns_nameservers=[],
host_routes=[{'destination': '10.10.10.254/32',
'nexthop': '192.168.10.254'}],
group='subnet1')
self.conf.config(cidr='192.168.20.0/24',
dhcp_start='192.168.20.10',
dhcp_end='192.168.20.99',
dhcp_exclude=[],
inspection_iprange='192.168.20.100,192.168.20.189',
gateway='192.168.20.254',
dns_nameservers=[],
host_routes=[{'destination': '10.10.10.254/32',
'nexthop': '192.168.20.254'}],
group='subnet2')
env = {}
undercloud_config._env_set_undercloud_ctlplane_networks_attribues(env)
expected = {
'CtlplaneNetworkAttributes': {
'network': {'mtu': 1500},
'subnets': {
'ctlplane-subnet': {
'cidr': '192.168.24.0/24',
'dns_nameservers': ['10.10.10.10', '10.10.10.11'],
'gateway_ip': '192.168.24.1',
'host_routes': [{'destination': '192.168.10.0/24',
'nexthop': '192.168.24.1'},
{'destination': '192.168.20.0/24',
'nexthop': '192.168.24.1'},
{'destination': '10.10.10.254/32',
'nexthop': '192.168.24.1'}],
'tags': []}}}}
self.assertEqual(expected, env)
class TestChronySettings(TestBaseNetworkSettings): class TestChronySettings(TestBaseNetworkSettings):
def test_default(self): def test_default(self):

View File

@ -264,10 +264,10 @@ def _generate_subnets_static_routes():
if subnet == str(CONF.local_subnet): if subnet == str(CONF.local_subnet):
continue continue
s = CONF.get(subnet) s = CONF.get(subnet)
env_list.append({'ip_netmask': s.cidr, 'next_hop': local_router}) env_list.append({'destination': s.cidr, 'nexthop': local_router})
for route in CONF.get(CONF.local_subnet).host_routes: for route in CONF.get(CONF.local_subnet).host_routes:
env_list.append({'ip_netmask': route['destination'], env_list.append({'destination': route['destination'],
'next_hop': route['nexthop']}) 'nexthop': route['nexthop']})
return env_list return env_list
@ -421,7 +421,7 @@ def _env_set_undercloud_ctlplane_networks_attribues(env):
'cidr': CONF.get(CONF.local_subnet).cidr, 'cidr': CONF.get(CONF.local_subnet).cidr,
'gateway_ip': CONF.get(CONF.local_subnet).gateway, 'gateway_ip': CONF.get(CONF.local_subnet).gateway,
'dns_nameservers': CONF.undercloud_nameservers, 'dns_nameservers': CONF.undercloud_nameservers,
'host_routes': CONF.get(CONF.local_subnet).host_routes, 'host_routes': _generate_subnets_static_routes(),
'tags': [], 'tags': [],
} }