Policy: Delete communication profile entries

When deleting a communication profile, we should first delete its entries.

Change-Id: Id20d683dfcc8c159a5a1f8bdb5ae77b40f76f9a2
This commit is contained in:
Adit Sarfaty
2017-08-17 09:58:53 +03:00
parent 0d5da8224c
commit 38f6cde5f6
2 changed files with 13 additions and 1 deletions

View File

@@ -711,10 +711,12 @@ class TestPolicyCommunicationProfile(NsxPolicyLibTestCase):
def test_delete(self):
id = '111'
with mock.patch.object(self.policy_api, "delete") as api_call:
with mock.patch.object(self.policy_api, "delete") as api_call,\
mock.patch.object(self.policy_api, "get") as get_call:
self.resourceApi.delete(id, tenant=TEST_TENANT)
expected_def = policy_defs.CommunicationProfileDef(
profile_id=id, tenant=TEST_TENANT)
self.assert_called_with_def(get_call, expected_def)
self.assert_called_with_def(api_call, expected_def)
def test_get(self):

View File

@@ -456,8 +456,18 @@ class NsxPolicyCommunicationProfileApi(NsxPolicyResourceBase):
def delete(self, profile_id,
tenant=policy_constants.POLICY_INFRA_TENANT):
"""Delete the Communication profile with all the entries"""
# first delete the entries, or else the profile deletion will fail
profile_def = policy_defs.CommunicationProfileDef(
profile_id=profile_id, tenant=tenant)
prof = self.policy_api.get(profile_def)
if 'communication_profile_entries' in prof:
for entry in prof['communication_profile_entries']:
entry_def = policy_defs.CommunicationProfileEntryDef(
profile_id=profile_id,
profile_entry_id=entry['id'],
tenant=tenant)
self.policy_api.delete(entry_def)
self.policy_api.delete(profile_def)
def get(self, profile_id,