Browse Source

Merge "Fixes get_realization_info, added API to get router port" into stable/victoria

changes/40/794440/2
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
ea97aa2ef5
2 changed files with 49 additions and 4 deletions
  1. +28
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  2. +21
    -4
      vmware_nsxlib/v3/policy/core_resources.py

+ 28
- 0
vmware_nsxlib/tests/unit/v3/policy/test_resources.py View File

@ -3145,6 +3145,34 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
tier1_id, segment_id)
self.assertEqual(lrp_id, actual_id)
def test_get_realization_info(self):
tier1_id = 'id-rtr'
with mock.patch.object(self.resourceApi, "_get_realization_info") as\
mock_call:
self.resourceApi.get_realization_info(
tier1_id, entity_type='RealizedLogicalRouterPort', tenant=None)
expected_def = core_defs.Tier1Def(tier1_id=tier1_id, tenant=None)
self.assert_called_with_def_and_kwargs(
mock_call,
expected_def,
entity_type='RealizedLogicalRouterPort',
silent=False)
def test_get_realized_router_port(self):
tier1_id = 'id-rtr'
with mock.patch.object(self.resourceApi, "_get_realization_info") as \
mock_call:
self.resourceApi.get_realized_router_port(
tier1_id, tenant=None)
expected_def = core_defs.Tier1Def(tier1_id=tier1_id, tenant=None)
self.assert_called_with_def_and_kwargs(
mock_call,
expected_def,
entity_type='RealizedLogicalRouterPort',
all_result=True,
silent=False
)
def test_set_dhcp_relay(self):
tier1_id = '111'
segment_id = '222'


+ 21
- 4
vmware_nsxlib/v3/policy/core_resources.py View File

@ -191,8 +191,9 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
return obj
def _get_realization_info(self, resource_def, entity_type=None,
silent=False):
silent=False, all_results=False):
entities = []
results = []
try:
path = resource_def.get_resource_full_path()
entities = self.policy_api.get_realized_entities(
@ -202,11 +203,18 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
# look for the entry with the right entity_type
for entity in entities:
if entity.get('entity_type') == entity_type:
return entity
if all_results:
results.append(entity)
else:
return entity
return results
else:
# return the first realization entry
# (Useful for resources with single realization entity)
return entities[0]
if not all_results:
return entities[0]
else:
return entities
except exceptions.ResourceNotFound:
pass
@ -1397,7 +1405,16 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
silent=False,
tenant=constants.POLICY_INFRA_TENANT):
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
return self._get_realization_info(tier1_def, silent=silent)
return self._get_realization_info(tier1_def, silent=silent,
entity_type=entity_type)
def get_realized_router_port(self, tier1_id, silent=False,
tenant=constants.POLICY_INFRA_TENANT):
tier1_def = self.entry_def(tier1_id=tier1_id, tenant=tenant)
ports = self._get_realization_info(
tier1_def, entity_type='RealizedLogicalRouterPort',
all_result=True, silent=silent)
return ports
def wait_until_realized(self, tier1_id, entity_type=None,
tenant=constants.POLICY_INFRA_TENANT,


Loading…
Cancel
Save