Add support for wait_until_realized for policy LB resources

This patch add support for wait_until_realized for the
following policy API
1. LbPool
2. LbPersistenceProfile
3. Certificate

Change-Id: I4f8ec85330b18592ab489adf3fd628a15dac9142
This commit is contained in:
Erica Liu 2019-06-24 15:17:23 -07:00 committed by root
parent f4731dd9a5
commit f946a81e98
4 changed files with 96 additions and 0 deletions

View File

@ -178,6 +178,29 @@ class TestPolicyLBPersistenceProfile(
self.assert_called_with_def(api_call, expected_def)
self.assertEqual([], result)
def test_wait_until_realized_fail(self):
pers_id = 'test_pers'
info = {'state': constants.STATE_UNREALIZED,
'realization_specific_identifier': pers_id}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
self.assertRaises(nsxlib_exc.RealizationTimeoutError,
self.resourceApi.wait_until_realized,
pers_id, max_attempts=5, sleep=0.1,
tenant=TEST_TENANT)
def test_wait_until_realized_succeed(self):
pers_id = 'test_pers'
info = {'state': constants.STATE_REALIZED,
'realization_specific_identifier': pers_id,
'entity_type': 'LbPersistenceProfileDto'}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
actual_info = self.resourceApi.wait_until_realized(
pers_id, entity_type='LbPersistenceProfileDto', max_attempts=5,
sleep=0.1, tenant=TEST_TENANT)
self.assertEqual(info, actual_info)
class TestPolicyLBCookiePersistenceProfile(
test_resources.NsxPolicyLibTestCase):
@ -1290,6 +1313,29 @@ class TestPolicyLBPoolApi(test_resources.NsxPolicyLibTestCase):
tenant=TEST_TENANT)
self.assert_called_with_def(update_call, expected_def)
def test_wait_until_realized_fail(self):
pool_id = 'test_pool'
info = {'state': constants.STATE_UNREALIZED,
'realization_specific_identifier': pool_id}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
self.assertRaises(nsxlib_exc.RealizationTimeoutError,
self.resourceApi.wait_until_realized,
pool_id, max_attempts=5, sleep=0.1,
tenant=TEST_TENANT)
def test_wait_until_realized_succeed(self):
pool_id = 'test_pool'
info = {'state': constants.STATE_REALIZED,
'realization_specific_identifier': pool_id,
'entity_type': 'LbPoolDto'}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
actual_info = self.resourceApi.wait_until_realized(
pool_id, entity_type='LbPoolDto', max_attempts=5,
sleep=0.1, tenant=TEST_TENANT)
self.assertEqual(info, actual_info)
class TestPolicyLBMonitorProfileHttpApi(test_resources.NsxPolicyLibTestCase):

View File

@ -4691,6 +4691,28 @@ class TestPolicyCertificate(NsxPolicyLibTestCase):
)
self.assert_called_with_def(update_call, expected_def)
def test_wait_until_realized_fail(self):
cert_id = 'test_cert'
info = {'state': constants.STATE_UNREALIZED,
'realization_specific_identifier': cert_id}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
self.assertRaises(nsxlib_exc.RealizationTimeoutError,
self.resourceApi.wait_until_realized,
cert_id, max_attempts=5, sleep=0.1,
tenant=TEST_TENANT)
def test_wait_until_realized_succeed(self):
cert_id = 'test_cert'
info = {'state': constants.STATE_REALIZED,
'realization_specific_identifier': cert_id}
with mock.patch.object(self.resourceApi, "_get_realization_info",
return_value=info):
actual_info = self.resourceApi.wait_until_realized(
cert_id, max_attempts=5,
sleep=0.1, tenant=TEST_TENANT)
self.assertEqual(info, actual_info)
class TestPolicyExcludeList(NsxPolicyLibTestCase):

View File

@ -3777,6 +3777,15 @@ class NsxPolicyCertApi(NsxPolicyResourceBase):
c_def = self.entry_def(certificate_id=certificate_id, tenant=tenant)
return c_def.get_resource_full_path()
def wait_until_realized(self, certificate_id, entity_type=None,
tenant=constants.POLICY_INFRA_TENANT,
sleep=None, max_attempts=None):
cert_def = self.entry_def(
certificate_id=certificate_id, tenant=tenant)
return self._wait_until_realized(
cert_def, entity_type=entity_type,
sleep=sleep, max_attempts=max_attempts)
class NsxPolicyExcludeListApi(NsxPolicyResourceBase):
"""NSX Policy Exclude list."""

View File

@ -276,6 +276,16 @@ class NsxPolicyLoadBalancerPersistenceProfileApi(
tenant=tenant)
return profile_def.get_resource_full_path()
def wait_until_realized(self, pers_id,
entity_type='LbPersistenceProfileDto',
tenant=constants.POLICY_INFRA_TENANT,
sleep=None, max_attempts=None):
pers_def = self.entry_def(
persistence_profile_id=pers_id, tenant=tenant)
return self._wait_until_realized(
pers_def, entity_type=entity_type,
sleep=sleep, max_attempts=max_attempts)
class NsxPolicyLoadBalancerCookiePersistenceProfileApi(
NsxPolicyLoadBalancerPersistenceProfileApi):
@ -555,6 +565,15 @@ class NsxPolicyLoadBalancerPoolApi(NsxPolicyResourceBase):
tenant=tenant)
return profile_def.get_resource_full_path()
def wait_until_realized(self, lb_pool_id, entity_type='LbPoolDto',
tenant=constants.POLICY_INFRA_TENANT,
sleep=None, max_attempts=None):
lb_pool_def = self.entry_def(
lb_pool_id=lb_pool_id, tenant=tenant)
return self._wait_until_realized(
lb_pool_def, entity_type=entity_type,
sleep=sleep, max_attempts=max_attempts)
class NsxPolicyLoadBalancerServiceApi(NsxPolicyResourceBase):
"""NSX Policy LBService."""