From f946a81e9803fd9727afa94b5946a2351c29e145 Mon Sep 17 00:00:00 2001 From: Erica Liu Date: Mon, 24 Jun 2019 15:17:23 -0700 Subject: [PATCH] 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 --- .../tests/unit/v3/policy/test_lb_resources.py | 46 +++++++++++++++++++ .../tests/unit/v3/policy/test_resources.py | 22 +++++++++ vmware_nsxlib/v3/policy/core_resources.py | 9 ++++ vmware_nsxlib/v3/policy/lb_resources.py | 19 ++++++++ 4 files changed, 96 insertions(+) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py index d0e689e2..80c46044 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_lb_resources.py @@ -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): diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 1461be51..98618cc0 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -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): diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 36c20bcf..6adaba47 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -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.""" diff --git a/vmware_nsxlib/v3/policy/lb_resources.py b/vmware_nsxlib/v3/policy/lb_resources.py index a175e1fe..de6d1c28 100644 --- a/vmware_nsxlib/v3/policy/lb_resources.py +++ b/vmware_nsxlib/v3/policy/lb_resources.py @@ -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."""