Fix transport zones extraction from the transport node

Support the case of NSX3 with multiple host_switches

Change-Id: Iba17fa861212906f613f866a383841bf7e683474
This commit is contained in:
asarfaty 2020-02-20 09:59:22 +02:00 committed by Adit Sarfaty
parent 1bb8e3836f
commit 2a16f624b1
2 changed files with 8 additions and 4 deletions

View File

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

View File

@ -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', [])]