Browse Source

Check realization status when getting id by search

Change-Id: I912b51933f2ad1e9fa2b1750c42301b1a1a70c25
tags/15.1.0
asarfaty 3 months ago
committed by Adit Sarfaty
parent
commit
bb379f1f45
3 changed files with 55 additions and 2 deletions
  1. +3
    -1
      vmware_nsxlib/tests/unit/v3/nsxlib_testcase.py
  2. +48
    -0
      vmware_nsxlib/tests/unit/v3/policy/test_resources.py
  3. +4
    -1
      vmware_nsxlib/v3/policy/core_resources.py

+ 3
- 1
vmware_nsxlib/tests/unit/v3/nsxlib_testcase.py View File

@@ -113,7 +113,9 @@ def get_default_nsxlib_config(allow_passthrough=True):
plugin_ver=PLUGIN_VER,
dns_nameservers=DNS_NAMESERVERS,
dns_domain=DNS_DOMAIN,
allow_passthrough=allow_passthrough
allow_passthrough=allow_passthrough,
realization_max_attempts=3,
realization_wait_sec=0.2
)




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

@@ -2906,6 +2906,30 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
tier1_id, tenant=TEST_TENANT,
max_attempts=5, sleep=0.1)

def test_get_realized_id(self):
# Get realized ID using search
tier1_id = '111'
logical_router_id = 'realized_111'
info = {'results': [{'status': {'state': 'success'},
'id': logical_router_id}]}
with mock.patch.object(self.resourceApi.nsx_api, "search_by_tags",
return_value=info):
realized_id = self.resourceApi.get_realized_id(tier1_id)
self.assertEqual(logical_router_id, realized_id)

def test_get_realized_id_failed(self):
# Get realized ID using search
tier1_id = '111'
logical_router_id = 'realized_111'
info = {'results': [{'status': {'state': 'in_progress'},
'id': logical_router_id}]}
with mock.patch.object(self.resourceApi.nsx_api, "search_by_tags",
return_value=info),\
mock.patch.object(self.resourceApi.policy_api,
"get_realized_entities"):
self.assertRaises(nsxlib_exc.RealizationTimeoutError,
self.resourceApi.get_realized_id, tier1_id)

def test_get_realized_downlink_port(self):
tier1_id = '111'
segment_id = '222'
@@ -3271,6 +3295,30 @@ class TestPolicyTier1NoPassthrough(TestPolicyTier1):
self.resourceApi.set_dhcp_relay(tier1_id, segment_id, relay_id)
realization.assert_not_called()

def test_get_realized_id(self):
# Get realized ID using policy api
tier1_id = '111'
logical_router_id = 'realized_111'
result = [{'state': constants.STATE_REALIZED,
'entity_type': 'RealizedLogicalRouter',
'realization_specific_identifier': logical_router_id}]
with mock.patch.object(self.resourceApi.policy_api,
"get_realized_entities",
return_value=result):
realized_id = self.resourceApi.get_realized_id(tier1_id)
self.assertEqual(logical_router_id, realized_id)

def test_get_realized_id_failed(self):
# Get realized ID using policy api
tier1_id = '111'
result = [{'state': constants.STATE_UNREALIZED,
'entity_type': 'RealizedLogicalRouter'}]
with mock.patch.object(self.resourceApi.policy_api,
"get_realized_entities",
return_value=result):
realized_id = self.resourceApi.get_realized_id(tier1_id)
self.assertEqual(None, realized_id)


class TestPolicyTier0NatRule(NsxPolicyLibTestCase):



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

@@ -310,7 +310,10 @@ class NsxPolicyResourceBase(object):
resources = self.nsx_api.search_by_tags(
tags=tag, resource_type=mp_resource_type)['results']
if resources:
return resources[0]['id']
# If status exists, make sure the state is successful
if (not resources[0].get('status') or
resources[0]['status'].get('state') == 'success'):
return resources[0]['id']

# From time to time also check the Policy realization state,
# as if it is in ERROR waiting should be avoided.


Loading…
Cancel
Save