From 6ac7c08257e37ecf9801936480e9b56a5c8f7343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Thu, 8 Oct 2020 13:41:42 +0200 Subject: [PATCH] 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 --- .../tests/v1/undercloud/test_config.py | 64 ++++++++++++++++--- tripleoclient/v1/undercloud_config.py | 8 +-- 2 files changed, 59 insertions(+), 13 deletions(-) diff --git a/tripleoclient/tests/v1/undercloud/test_config.py b/tripleoclient/tests/v1/undercloud/test_config.py index b243e0158..b285e973e 100644 --- a/tripleoclient/tests/v1/undercloud/test_config.py +++ b/tripleoclient/tests/v1/undercloud/test_config.py @@ -558,8 +558,8 @@ class TestNetworkSettings(TestBaseNetworkSettings): undercloud_config._process_network_args(env) expected = { 'ControlPlaneStaticRoutes': [ - {'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, - {'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}], + {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'}, + {'destination': '192.168.20.0/24', 'nexthop': '192.168.24.1'}], 'IronicInspectorSubnets': [ {'gateway': '192.168.24.1', 'host_routes': [], @@ -647,8 +647,8 @@ class TestNetworkSettings(TestBaseNetworkSettings): undercloud_config._process_network_args(env) expected = { 'ControlPlaneStaticRoutes': [ - {'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, - {'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}], + {'destination': '192.168.10.0/24', 'nexthop': '192.168.24.1'}, + {'destination': '192.168.20.0/24', 'nexthop': '192.168.24.1'}], 'IronicInspectorSubnets': [ {'gateway': '192.168.24.1', 'host_routes': [], @@ -716,7 +716,7 @@ class TestNetworkSettings(TestBaseNetworkSettings): undercloud_config._process_network_args(env) expected = { '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': [ {'gateway': '192.168.24.1', 'host_routes': [], @@ -770,7 +770,7 @@ class TestNetworkSettings(TestBaseNetworkSettings): undercloud_config._process_network_args(env) expected = { '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': [ {'gateway': '192.168.24.1', 'host_routes': [], @@ -842,9 +842,9 @@ class TestNetworkSettings(TestBaseNetworkSettings): undercloud_config._process_network_args(env) expected = { 'ControlPlaneStaticRoutes': [ - {'ip_netmask': '192.168.10.0/24', 'next_hop': '192.168.24.1'}, - {'ip_netmask': '192.168.20.0/24', 'next_hop': '192.168.24.1'}, - {'ip_netmask': '10.10.10.254/32', 'next_hop': '192.168.24.1'}], + {'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'}], 'IronicInspectorSubnets': [ {'gateway': '192.168.24.1', 'host_routes': [{'destination': '10.10.10.254/32', @@ -949,6 +949,52 @@ class TestNetworkSettings(TestBaseNetworkSettings): 'tags': []}}}} 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): def test_default(self): diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index 9e15562d0..365b27b6f 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -264,10 +264,10 @@ def _generate_subnets_static_routes(): if subnet == str(CONF.local_subnet): continue 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: - env_list.append({'ip_netmask': route['destination'], - 'next_hop': route['nexthop']}) + env_list.append({'destination': route['destination'], + 'nexthop': route['nexthop']}) return env_list @@ -421,7 +421,7 @@ def _env_set_undercloud_ctlplane_networks_attribues(env): 'cidr': CONF.get(CONF.local_subnet).cidr, 'gateway_ip': CONF.get(CONF.local_subnet).gateway, 'dns_nameservers': CONF.undercloud_nameservers, - 'host_routes': CONF.get(CONF.local_subnet).host_routes, + 'host_routes': _generate_subnets_static_routes(), 'tags': [], }