From ae242232b3e80d04b74a835c5c0aba2209e6e28a Mon Sep 17 00:00:00 2001 From: Abhishek Raut Date: Thu, 7 Mar 2019 17:08:24 -0800 Subject: [PATCH] Add sequence number to the creation of SecurityPolicy Expose the sequence number property of security policy resource. Change-Id: Iab0e7f38628b81641a77012a402bd5bb25d460e5 --- .../tests/unit/v3/policy/test_resources.py | 10 +++++++++- vmware_nsxlib/v3/policy/core_defs.py | 6 +++++- vmware_nsxlib/v3/policy/core_resources.py | 15 ++++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index 74a3d04c..b095fe58 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -1046,6 +1046,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): source_group = 'g1' dest_group = 'g2' seq_num = 7 + map_seq_num = 10 service_id = 'c1' direction = nsx_constants.IN_OUT get_return_value = {'rules': [{'sequence_number': 1}]} @@ -1063,6 +1064,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): dest_groups=[dest_group], direction=direction, logged=True, + map_sequence_number=map_seq_num, tenant=TEST_TENANT) map_def = self.mapDef( domain_id=domain_id, @@ -1070,6 +1072,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): name=name, description=description, category=constants.CATEGORY_APPLICATION, + map_sequence_number=map_seq_num, tenant=TEST_TENANT) entry_def = self.entryDef( @@ -1188,11 +1191,12 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): domain_id = '111' name = 'cm1' description = 'desc' + map_seq_num = 10 with mock.patch.object(self.policy_api, "create_or_update") as api_call: result = self.resourceApi.create_or_overwrite_map_only( name, domain_id, description=description, - tenant=TEST_TENANT) + map_sequence_number=map_seq_num, tenant=TEST_TENANT) expected_map_def = self.mapDef( domain_id=domain_id, @@ -1200,6 +1204,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): name=name, description=description, category=constants.CATEGORY_APPLICATION, + map_sequence_number=map_seq_num, tenant=TEST_TENANT) self.assert_called_with_def(api_call, expected_map_def) @@ -1340,6 +1345,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): service_id = 'c1' category = 'Emergency' ip_protocol = nsx_constants.IPV4 + map_seq_num = 10 rule_id = 1 entry1 = self.resourceApi.build_entry( @@ -1367,6 +1373,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): description=description, entries=[entry1, entry2], category=category, + map_sequence_number=map_seq_num, tenant=TEST_TENANT) expected_def = self.mapDef( @@ -1375,6 +1382,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase): name=name, description=description, category=category, + map_sequence_number=map_seq_num, tenant=TEST_TENANT) self.assert_called_with_defs(api_call, diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 2fde9bca..413659a1 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -1158,7 +1158,11 @@ class SecurityPolicyBaseDef(ResourceDef): def get_obj_dict(self): body = super(SecurityPolicyBaseDef, self).get_obj_dict() self._set_attr_if_specified(body, 'category') - + if self.has_attr('map_sequence_number'): + seq_number = self.get_attr('map_sequence_number') + self._set_attr_if_specified(body, 'map_sequence_number', + body_attr='sequence_number', + value=seq_number) return body diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 6cb189f3..cc096a99 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -2397,6 +2397,7 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): source_groups=IGNORE, dest_groups=IGNORE, direction=nsx_constants.IN_OUT, logged=IGNORE, tags=IGNORE, + map_sequence_number=IGNORE, tenant=constants.POLICY_INFRA_TENANT): """Create CommunicationMap & Entry. @@ -2439,7 +2440,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): map_def = self._init_parent_def( domain_id=domain_id, map_id=map_id, tenant=tenant, name=name, description=description, - category=category, tags=tags) + category=category, tags=tags, + map_sequence_number=map_sequence_number) self._create_or_store(map_def, entry_def) return map_id @@ -2447,7 +2449,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): def create_or_overwrite_map_only( self, name, domain_id, map_id=None, description=IGNORE, category=constants.CATEGORY_APPLICATION, - tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT): + tags=IGNORE, map_sequence_number=IGNORE, + tenant=constants.POLICY_INFRA_TENANT): """Create or update a CommunicationMap Create a communication map without any entries, or update the @@ -2457,7 +2460,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): map_def = self._init_parent_def( domain_id=domain_id, map_id=map_id, tenant=tenant, name=name, description=description, - category=category, tags=tags) + category=category, tags=tags, + map_sequence_number=map_sequence_number) self._create_or_store(map_def) return map_id @@ -2492,7 +2496,7 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): self, name, domain_id, map_id=None, description=IGNORE, category=constants.CATEGORY_APPLICATION, - entries=None, tags=IGNORE, + entries=None, tags=IGNORE, map_sequence_number=IGNORE, tenant=constants.POLICY_INFRA_TENANT): """Create CommunicationMap with entries""" @@ -2501,7 +2505,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase): map_def = self._init_parent_def( domain_id=domain_id, map_id=map_id, tenant=tenant, name=name, description=description, - category=category, tags=tags) + category=category, tags=tags, + map_sequence_number=map_sequence_number) self.policy_api.create_with_parent(map_def, entries) return map_id