From 5353915e2c107435a5cd70846b04baff8b868b07 Mon Sep 17 00:00:00 2001 From: Harald Jensas Date: Sat, 13 Jan 2018 17:04:16 +0100 Subject: [PATCH] Create static routes for remote subnets Add static routes to reach remote subnets via router connected to locale ctlplane segment. Implements: blueprint tripleo-routed-networks-ironic-inspector Implements: blueprint tripleo-routed-networks-deployment Change-Id: Ibfc4c1492377ea4c3966ffadfd440bd705c45d19 --- instack_undercloud/tests/test_undercloud.py | 25 +++++++++++++++++++++ instack_undercloud/undercloud.py | 15 ++++++++++++- templates/net-config.json.template | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/instack_undercloud/tests/test_undercloud.py b/instack_undercloud/tests/test_undercloud.py index 4bb27e80c..a73c9a75c 100644 --- a/instack_undercloud/tests/test_undercloud.py +++ b/instack_undercloud/tests/test_undercloud.py @@ -689,6 +689,31 @@ class TestGenerateEnvironment(BaseTestCase): actual = json.loads(env['INSPECTION_SUBNETS']) self.assertEqual(reference, actual) + def test_subnets_static_routes(self): + self.conf.config(subnets=['ctlplane-subnet', 'subnet1', 'subnet2']) + self.conf.register_opts(self.opts, group=self.grp1) + self.conf.register_opts(self.opts, group=self.gtp2) + self.conf.config(cidr='192.168.24.0/24', + dhcp_start='192.168.24.5', dhcp_end='192.168.24.24', + inspection_iprange='192.168.24.100,192.168.24.120', + gateway='192.168.24.1', group='ctlplane-subnet') + self.conf.config(cidr='192.168.10.0/24', dhcp_start='192.168.10.10', + dhcp_end='192.168.10.99', + inspection_iprange='192.168.10.100,192.168.10.189', + gateway='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', + inspection_iprange='192.168.20.100,192.168.20.189', + gateway='192.168.20.254', group='subnet2') + + env = undercloud._generate_environment('.') + reference = [{"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"}] + actual = json.loads(env['SUBNETS_STATIC_ROUTES']) + self.assertEqual(reference, actual) + class TestWritePasswordFile(BaseTestCase): def test_normal(self): diff --git a/instack_undercloud/undercloud.py b/instack_undercloud/undercloud.py index d5bb0783f..01a13efd8 100644 --- a/instack_undercloud/undercloud.py +++ b/instack_undercloud/undercloud.py @@ -1157,7 +1157,7 @@ class InstackEnvironment(dict): 'ENABLED_RAID_INTERFACES', 'ENABLED_VENDOR_INTERFACES', 'ENABLED_MANAGEMENT_INTERFACES', 'SYSCTL_SETTINGS', 'LOCAL_IP_WRAPPED', 'ENABLE_ARCHITECTURE_PPC64LE', - 'INSPECTION_SUBNETS', + 'INSPECTION_SUBNETS', 'SUBNETS_STATIC_ROUTES', } """The variables we calculate in _generate_environment call.""" @@ -1274,6 +1274,18 @@ def _generate_inspection_subnets(): return json.dumps(env_list) +def _generate_subnets_static_routes(): + env_list = [] + local_router = CONF.get(CONF.local_subnet).gateway + for subnet in CONF.subnets: + if subnet == str(CONF.local_subnet): + continue + s = CONF.get(subnet) + env_list.append({'ip_netmask': s.cidr, + 'next_hop': local_router}) + return json.dumps(env_list) + + def _generate_environment(instack_root): """Generate an environment dict for instack @@ -1363,6 +1375,7 @@ def _generate_environment(instack_root): _process_drivers_and_hardware_types(instack_env) instack_env['INSPECTION_SUBNETS'] = _generate_inspection_subnets() + instack_env['SUBNETS_STATIC_ROUTES'] = _generate_subnets_static_routes() instack_env['SYSCTL_SETTINGS'] = _generate_sysctl_settings() diff --git a/templates/net-config.json.template b/templates/net-config.json.template index e2026b343..ffc04d548 100644 --- a/templates/net-config.json.template +++ b/templates/net-config.json.template @@ -19,6 +19,7 @@ "ip_netmask": "{{PUBLIC_INTERFACE_IP}}" } ], + "routes": {{SUBNETS_STATIC_ROUTES}}, "mtu": {{LOCAL_MTU}} } ]