Fix get_connected_t0_transit_net ot return the IP we need
Change-Id: I10846d53a77647bf2147bae923484c5422faf896
This commit is contained in:
parent
99f7317575
commit
98ed976475
@ -139,20 +139,13 @@ class TestRouter(nsxlib_testcase.NsxClientTestCase):
|
||||
|
||||
def test_get_connected_t0_transit_net(self):
|
||||
t1_uuid = uuidutils.generate_uuid()
|
||||
link_port_uuid = uuidutils.generate_uuid()
|
||||
link_port = {
|
||||
'linked_logical_router_port_id': {
|
||||
'target_id': link_port_uuid}}
|
||||
transit_net = '1.1.1.0'
|
||||
transit_prefix = '31'
|
||||
t0_port = {'subnets': [{'ip_addresses': [transit_net],
|
||||
'prefix_length': transit_prefix}]}
|
||||
link_port = {
|
||||
'subnets': [{'ip_addresses': [transit_net],
|
||||
'prefix_length': '31'}]}
|
||||
with mock.patch.object(self.nsxlib.router._router_port_client,
|
||||
'get_tier1_link_port',
|
||||
return_value=link_port) as get_link,\
|
||||
mock.patch.object(self.nsxlib.router._router_port_client,
|
||||
'get', return_value=t0_port) as get_port:
|
||||
cidr = self.nsxlib.router.get_connected_t0_transit_net(t1_uuid)
|
||||
get_link.assert_called_with(t1_uuid)
|
||||
get_port.assert_called_with(link_port_uuid)
|
||||
self.assertEqual('%s/%s' % (transit_net, transit_prefix), cidr)
|
||||
return_value=link_port) as get_port:
|
||||
net = self.nsxlib.router.get_connected_t0_transit_net(t1_uuid)
|
||||
get_port.assert_called_with(t1_uuid)
|
||||
self.assertEqual('%s' % (transit_net), net)
|
||||
|
@ -279,7 +279,7 @@ class RouterLib(object):
|
||||
return tz_uuid
|
||||
|
||||
def get_connected_t0_transit_net(self, tier1_uuid):
|
||||
"""Return the cidr of the tier1->tier0 link port
|
||||
"""Return the IP of the tier1->tier0 link port
|
||||
|
||||
return None if the router is not connected to a tier0 router
|
||||
"""
|
||||
@ -289,12 +289,7 @@ class RouterLib(object):
|
||||
except exceptions.ResourceNotFound:
|
||||
# No GW
|
||||
return
|
||||
tier0_link_port_id = tier1_link_port.get(
|
||||
'linked_logical_router_port_id', {}).get('target_id')
|
||||
if not tier0_link_port_id:
|
||||
return
|
||||
tier0_link_port = self._router_port_client.get(tier0_link_port_id)
|
||||
for subnet in tier0_link_port.get('subnets', []):
|
||||
for subnet in tier1_link_port.get('subnets', []):
|
||||
for ip_address in subnet.get('ip_addresses'):
|
||||
# Expecting only 1 cidr here. Return it.
|
||||
return "%s/%s" % (ip_address, subnet.get('prefix_length', '0'))
|
||||
# Expecting only 1 ip here. Return it.
|
||||
return ip_address
|
||||
|
Loading…
x
Reference in New Issue
Block a user