From 2a16f624b1c18041196061de59eaa498b2648709 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Thu, 20 Feb 2020 09:59:22 +0200 Subject: [PATCH] Fix transport zones extraction from the transport node Support the case of NSX3 with multiple host_switches Change-Id: Iba17fa861212906f613f866a383841bf7e683474 --- vmware_nsxlib/tests/unit/v3/test_resources.py | 4 +++- vmware_nsxlib/v3/core_resources.py | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/test_resources.py b/vmware_nsxlib/tests/unit/v3/test_resources.py index 02bbccc3..d457ad46 100644 --- a/vmware_nsxlib/tests/unit/v3/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/test_resources.py @@ -1908,11 +1908,13 @@ class TransportNode(BaseTestResource): tn = self.get_mocked_resource() self.nsxlib.feature_supported = mock.MagicMock() with mock.patch.object(tn.client, 'url_get', return_value=fake_tn): + # Test the api with its 2 versions 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) + self.assertEqual([test_constants.FAKE_TZ_EP_UUID, + test_constants.FAKE_TZ_EP_UUID2], tzs) class MetadataProxy(BaseTestResource): diff --git a/vmware_nsxlib/v3/core_resources.py b/vmware_nsxlib/v3/core_resources.py index 8074e85e..1490fd00 100644 --- a/vmware_nsxlib/v3/core_resources.py +++ b/vmware_nsxlib/v3/core_resources.py @@ -916,9 +916,11 @@ class NsxLibTransportNode(utils.NsxLibApiBase): 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', [])] + tzs = [] + for host_switch in host_switches: + tzs.extend([ep.get('transport_zone_id') for ep in + host_switch.get('transport_zone_endpoints', [])]) + return tzs else: return [ep.get('transport_zone_id') for ep in tn.get('transport_zone_endpoints', [])]