From 16171471f6d73f234c023f538eb135b7c1514340 Mon Sep 17 00:00:00 2001 From: Shawn Wang Date: Tue, 30 Mar 2021 12:15:07 -0700 Subject: [PATCH] Allow Transaction for Policy IP Pool Deletion This patch allows IP Pool to be deleted with transaction, so that the IP pool can be removed with its child resources (i.e. pool subnets, ip allocations) in one API call. Change-Id: I873f7b714a313ff5b512a3898aedab9bd805163b (cherry picked from commit cf25fb09236d97baa47831c5df4d6eaaa9e5ba4d) --- .../tests/unit/v3/policy/test_transaction.py | 15 +++++++++++++++ vmware_nsxlib/v3/policy/core_resources.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_transaction.py b/vmware_nsxlib/tests/unit/v3/policy/test_transaction.py index 259549c2..21c2e9c0 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_transaction.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_transaction.py @@ -164,6 +164,21 @@ class TestPolicyTransaction(policy_testcase.TestPolicyApi): self.assert_infra_patch_call(expected_body) + def test_ip_address_pool_delete(self): + + pool = {'id': 'pool1', + 'resource_type': 'IpAddressPool'} + + with trans.NsxPolicyTransaction(): + self.policy_lib.ip_pool.delete(ip_pool_id=pool['id']) + + expected_body = {'resource_type': 'Infra', + 'children': [{'resource_type': 'ChildIpAddressPool', + 'IpAddressPool': pool, + 'marked_for_delete': True}]} + + self.assert_infra_patch_call(expected_body) + def test_groups_only(self): g1 = {'resource_type': 'Group', 'id': 'group1', diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 37f44672..2a34689c 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -3222,7 +3222,7 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase): def delete(self, ip_pool_id, tenant=constants.POLICY_INFRA_TENANT): ip_pool_def = self.entry_def(ip_pool_id=ip_pool_id, tenant=tenant) - self._delete_with_retry(ip_pool_def) + self._delete_or_store(ip_pool_def) def get(self, ip_pool_id, tenant=constants.POLICY_INFRA_TENANT, silent=False):