From 43d0482cc697c89e5456fd8da6b77932c4ef4223 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Tue, 22 Oct 2019 19:09:11 -0700 Subject: [PATCH] Find tier0's tranzport_zone via advanced_config When finding the overlay transport zone of a tier0 router, if its advanced_config already has transport_zone_id defined, then return it directly. Otherwise search through the edge nodes in the corresponding edge_cluster. Change-Id: Idf1efd9d0cd2c2ef5af895d22fc156630d855488 --- vmware_nsxlib/tests/unit/v3/test_constants.py | 1 + vmware_nsxlib/tests/unit/v3/test_router.py | 7 +++++++ vmware_nsxlib/v3/router.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/vmware_nsxlib/tests/unit/v3/test_constants.py b/vmware_nsxlib/tests/unit/v3/test_constants.py index 337d89d1..049a112c 100644 --- a/vmware_nsxlib/tests/unit/v3/test_constants.py +++ b/vmware_nsxlib/tests/unit/v3/test_constants.py @@ -579,6 +579,7 @@ FAKE_TIERO_ROUTER = { "target_id": "c3d80576-e340-403d-a2d0-f4a72a1db6e3" }], "advanced_config": { + "transport_zone_id": FAKE_TZ_UUID, "external_transit_networks": ["100.64.0.0/16"], "internal_transit_network": "169.254.0.0/28" }, diff --git a/vmware_nsxlib/tests/unit/v3/test_router.py b/vmware_nsxlib/tests/unit/v3/test_router.py index 2fbd8372..238e6784 100644 --- a/vmware_nsxlib/tests/unit/v3/test_router.py +++ b/vmware_nsxlib/tests/unit/v3/test_router.py @@ -161,6 +161,13 @@ class TestRouter(nsxlib_testcase.NsxClientTestCase): tz = self.nsxlib.router.get_tier0_router_overlay_tz(tier0_uuid) self.assertEqual(tz, test_constants.FAKE_TZ_UUID) + def test_get_tier0_router_overlay_tz_via_advanced_config(self): + tier0_uuid = uuidutils.generate_uuid() + with mock.patch.object(self.nsxlib.router._router_client, 'get', + return_value=test_constants.FAKE_TIERO_ROUTER): + tz = self.nsxlib.router.get_tier0_router_overlay_tz(tier0_uuid) + self.assertEqual(tz, test_constants.FAKE_TZ_UUID) + def test_get_connected_t0_transit_net(self): t1_uuid = uuidutils.generate_uuid() transit_net = '1.1.1.0' diff --git a/vmware_nsxlib/v3/router.py b/vmware_nsxlib/v3/router.py index 08a12c8a..a5fc7b2e 100644 --- a/vmware_nsxlib/v3/router.py +++ b/vmware_nsxlib/v3/router.py @@ -293,6 +293,10 @@ class RouterLib(object): return tier0_tzs def get_tier0_router_overlay_tz(self, tier0_uuid): + lrouter = self._router_client.get(tier0_uuid) + tz_uuid = lrouter.get('advanced_config', {}).get('transport_zone_id') + if tz_uuid: + return tz_uuid tz_uuids = self.get_tier0_router_tz(tier0_uuid) for tz_uuid in tz_uuids: # look for the overlay tz