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
This commit is contained in:
Harald Jensas 2018-01-13 17:04:16 +01:00 committed by Emilien Macchi
parent a1d5484a18
commit 5353915e2c
3 changed files with 40 additions and 1 deletions

View File

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

View File

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

View File

@ -19,6 +19,7 @@
"ip_netmask": "{{PUBLIC_INTERFACE_IP}}"
}
],
"routes": {{SUBNETS_STATIC_ROUTES}},
"mtu": {{LOCAL_MTU}}
}
]