Find OverlayTransportZone from host switch

Use host switch to get overlay transport zone from 3.0.0.
Get from tn['host_switch_spec']['host_switches'][0]
['transport_zone_endpoints'] since 3.0.0.
Get from tn['transport_zone_endpoints'] before 3.0.0.

Change-Id: I26b5756fe28fcaff7541002623dc982eb2dbee70
This commit is contained in:
ranp 2019-10-24 19:19:42 -07:00
parent 43d0482cc6
commit bb5ffb0cc8
6 changed files with 51 additions and 4 deletions

View File

@ -363,12 +363,32 @@ FAKE_TZ = {
}
FAKE_TN_UUID = uuidutils.generate_uuid()
FAKE_TZ_EP_UUID = uuidutils.generate_uuid()
FAKE_TZ_EP_UUID2 = uuidutils.generate_uuid()
FAKE_TN = {
"resource_type": "TransportNode",
"revision": 0,
"id": FAKE_TZ_UUID,
"display_name": FAKE_NAME,
"transport_zone_endpoints": [{"transport_zone_id": FAKE_TZ_UUID}]
"transport_zone_endpoints": [{"transport_zone_id": FAKE_TZ_UUID}],
"host_switch_spec": {
"host_switches": [
{
'transport_zone_endpoints': [
{
'transport_zone_id': FAKE_TZ_EP_UUID
}
]
},
{
'transport_zone_endpoints': [
{
'transport_zone_id': FAKE_TZ_EP_UUID2
}
]
}
]
}
}
FAKE_MD_UUID = uuidutils.generate_uuid()

View File

@ -1877,9 +1877,13 @@ class TransportNode(BaseTestResource):
def test_get_transport_zones(self):
fake_tn = test_constants.FAKE_TN.copy()
tn = self.get_mocked_resource()
self.nsxlib.feature_supported = mock.MagicMock()
with mock.patch.object(tn.client, 'url_get', return_value=fake_tn):
self.nsxlib.feature_supported.side_effect = [False, True]
tzs = tn.get_transport_zones(fake_tn['id'])
self.assertEqual([test_constants.FAKE_TZ_UUID], tzs)
tzs = tn.get_transport_zones(fake_tn['id'])
self.assertEqual([test_constants.FAKE_TZ_EP_UUID], tzs)
class MetadataProxy(BaseTestResource):

View File

@ -139,6 +139,8 @@ class TestRouter(nsxlib_testcase.NsxClientTestCase):
def test_get_tier0_router_tz(self):
tier0_uuid = uuidutils.generate_uuid()
self.nsxlib.feature_supported = mock.MagicMock()
self.nsxlib.feature_supported.return_value = False
with mock.patch.object(self.nsxlib.router._router_client, 'get',
return_value=test_constants.FAKE_TIERO_ROUTER),\
mock.patch.object(self.nsxlib.edge_cluster, 'get',
@ -150,6 +152,8 @@ class TestRouter(nsxlib_testcase.NsxClientTestCase):
def test_get_tier0_router_overlay_tz(self):
tier0_uuid = uuidutils.generate_uuid()
self.nsxlib.feature_supported = mock.MagicMock()
self.nsxlib.feature_supported.return_value = False
with mock.patch.object(self.nsxlib.router._router_client, 'get',
return_value=test_constants.FAKE_TIERO_ROUTER),\
mock.patch.object(self.nsxlib.edge_cluster, 'get',

View File

@ -167,6 +167,12 @@ class NsxLib(lib.NsxLibBase):
return node.get('export_type') is 'RESTRICTED'
def feature_supported(self, feature):
if (version.LooseVersion(self.get_version()) >=
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
# features available since 3.0.0
if (feature == nsx_constants.FEATURE_GET_TZ_FROM_SWITCH):
return True
if (version.LooseVersion(self.get_version()) >=
version.LooseVersion(nsx_constants.NSX_VERSION_2_5_1)):
# features available since 2.5.1

View File

@ -907,9 +907,21 @@ class NsxLibTransportNode(utils.NsxLibApiBase):
return True
def get_transport_zones(self, uuid):
tz = self.get(uuid)
return [ep.get('transport_zone_id') for ep in
tz.get('transport_zone_endpoints', [])]
tn = self.get(uuid)
if (self.nsxlib and self.nsxlib.feature_supported(
nsx_constants.FEATURE_GET_TZ_FROM_SWITCH)):
if (not tn.get('host_switch_spec') or not
tn['host_switch_spec'].get('host_switches')):
return []
host_switches = tn.get('host_switch_spec').get('host_switches', [])
return [ep.get('transport_zone_id') for ep in
host_switches[0].get('transport_zone_endpoints', [])]
else:
return [ep.get('transport_zone_id') for ep in
tn.get('transport_zone_endpoints', [])]
class NsxLibDhcpProfile(utils.NsxLibApiBase):

View File

@ -172,6 +172,7 @@ FEATURE_ENABLE_STANDBY_RELOCATION = 'Router Enable standby relocation'
FEATURE_PARTIAL_UPDATES = 'Partial Update with PATCH'
FEATURE_RELAX_SCALE_VALIDATION = 'Relax Scale Validation for LbService'
FEATURE_SWITCH_HYPERBUS_MODE = 'Switch hyperbus mode with policy API'
FEATURE_GET_TZ_FROM_SWITCH = 'Get TZ endpoints from host switch'
# Features available depending on the Policy Manager backend version
FEATURE_NSX_POLICY = 'NSX Policy'