From ddfb144dbb5d57d5cc74e7ff7d7092ba48e63a19 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Wed, 6 Feb 2019 08:55:29 +0200 Subject: [PATCH] Add category to policy communication map update calls The NSX does not support communication maps update calls without category field for now. Adding a temporary fix to get the current category from the NSX before updating the entry. Change-Id: Ibf15facfeea1e93aa656b8a959814b587fce478f --- vmware_nsxlib/tests/unit/v3/policy/test_resources.py | 10 +++++++++- vmware_nsxlib/v3/policy/core_resources.py | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 26f9c0b1..e2bcf77d 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -1376,8 +1376,11 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): dest_group = 'ng2' service1_id = 'nc1' service2_id = 'nc2' + category = constants.CATEGORY_EMERGENCY with mock.patch.object(self.policy_api, "get", return_value={}),\ + mock.patch.object(self.resourceApi, "get", + return_value={'category': category}),\ mock.patch.object(self.policy_api, "create_with_parent") as update_call: self.resourceApi.update(domain_id, map_id, @@ -1392,6 +1395,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): map_id=map_id, name=name, description=description, + category=category, tenant=TEST_TENANT) entry_def = core_defs.CommunicationMapEntryDef( @@ -1410,6 +1414,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): domain_id = 'test' map_id = '111' dest_groups = ['/infra/stuff'] + category = constants.CATEGORY_EMERGENCY # Until policy PATCH is fixed to accept partial update, we # call get on child entry @@ -1417,7 +1422,9 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): self.policy_api, "get", return_value={'display_name': name, 'source_groups': ['/infra/other/stuff'], - 'destination_groups': dest_groups}): + 'destination_groups': dest_groups}),\ + mock.patch.object(self.resourceApi, "get", + return_value={'category': category}): self.resourceApi.update(domain_id, map_id, description=None, source_groups=None, @@ -1426,6 +1433,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): expected_body = {'id': map_id, 'description': None, + 'category': category, 'resource_type': 'SecurityPolicy', 'rules': [{ 'display_name': name, diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index d1083f84..479fb4a4 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2514,12 +2514,16 @@ class NsxPolicyCommunicationMapApi(NsxPolicyResourceBase): source_groups=IGNORE, dest_groups=IGNORE, direction=IGNORE, logged=IGNORE, tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): - + # Note(asarfaty): Category is mandatory in update calls for now + # although it cannot change. Getting it from the NSX + orig_entry = self.get(domain_id, map_id, tenant=tenant) + category = orig_entry.get('category') parent_def = self._init_parent_def( domain_id=domain_id, map_id=map_id, name=name, description=description, + category=category, tags=tags, tenant=tenant)