Check realization status when getting id by search
Change-Id: I912b51933f2ad1e9fa2b1750c42301b1a1a70c25
This commit is contained in:
parent
22a76ec7af
commit
5ee7524cc5
|
@ -114,7 +114,9 @@ def get_default_nsxlib_config(allow_passthrough=True):
|
||||||
plugin_ver=PLUGIN_VER,
|
plugin_ver=PLUGIN_VER,
|
||||||
dns_nameservers=DNS_NAMESERVERS,
|
dns_nameservers=DNS_NAMESERVERS,
|
||||||
dns_domain=DNS_DOMAIN,
|
dns_domain=DNS_DOMAIN,
|
||||||
allow_passthrough=allow_passthrough
|
allow_passthrough=allow_passthrough,
|
||||||
|
realization_max_attempts=3,
|
||||||
|
realization_wait_sec=0.2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3089,6 +3089,30 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
|
||||||
tier1_id, tenant=TEST_TENANT,
|
tier1_id, tenant=TEST_TENANT,
|
||||||
max_attempts=5, sleep=0.1)
|
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):
|
def test_get_realized_downlink_port(self):
|
||||||
tier1_id = '111'
|
tier1_id = '111'
|
||||||
segment_id = '222'
|
segment_id = '222'
|
||||||
|
@ -3510,6 +3534,30 @@ class TestPolicyTier1NoPassthrough(TestPolicyTier1):
|
||||||
self.resourceApi.set_dhcp_relay(tier1_id, segment_id, relay_id)
|
self.resourceApi.set_dhcp_relay(tier1_id, segment_id, relay_id)
|
||||||
realization.assert_not_called()
|
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):
|
class TestPolicyTier0NatRule(NsxPolicyLibTestCase):
|
||||||
|
|
||||||
|
|
|
@ -316,7 +316,10 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta):
|
||||||
resources = self.nsx_api.search_by_tags(
|
resources = self.nsx_api.search_by_tags(
|
||||||
tags=tag, resource_type=mp_resource_type)['results']
|
tags=tag, resource_type=mp_resource_type)['results']
|
||||||
if resources:
|
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,
|
# From time to time also check the Policy realization state,
|
||||||
# as if it is in ERROR waiting should be avoided.
|
# as if it is in ERROR waiting should be avoided.
|
||||||
|
|
Loading…
Reference in New Issue