Add sequence number to the creation of SecurityPolicy
Expose the sequence number property of security policy resource. Change-Id: Iab0e7f38628b81641a77012a402bd5bb25d460e5
This commit is contained in:
@@ -1046,6 +1046,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
source_group = 'g1'
|
source_group = 'g1'
|
||||||
dest_group = 'g2'
|
dest_group = 'g2'
|
||||||
seq_num = 7
|
seq_num = 7
|
||||||
|
map_seq_num = 10
|
||||||
service_id = 'c1'
|
service_id = 'c1'
|
||||||
direction = nsx_constants.IN_OUT
|
direction = nsx_constants.IN_OUT
|
||||||
get_return_value = {'rules': [{'sequence_number': 1}]}
|
get_return_value = {'rules': [{'sequence_number': 1}]}
|
||||||
@@ -1063,6 +1064,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
dest_groups=[dest_group],
|
dest_groups=[dest_group],
|
||||||
direction=direction,
|
direction=direction,
|
||||||
logged=True,
|
logged=True,
|
||||||
|
map_sequence_number=map_seq_num,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
map_def = self.mapDef(
|
map_def = self.mapDef(
|
||||||
domain_id=domain_id,
|
domain_id=domain_id,
|
||||||
@@ -1070,6 +1072,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
name=name,
|
name=name,
|
||||||
description=description,
|
description=description,
|
||||||
category=constants.CATEGORY_APPLICATION,
|
category=constants.CATEGORY_APPLICATION,
|
||||||
|
map_sequence_number=map_seq_num,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
|
||||||
entry_def = self.entryDef(
|
entry_def = self.entryDef(
|
||||||
@@ -1188,11 +1191,12 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
domain_id = '111'
|
domain_id = '111'
|
||||||
name = 'cm1'
|
name = 'cm1'
|
||||||
description = 'desc'
|
description = 'desc'
|
||||||
|
map_seq_num = 10
|
||||||
with mock.patch.object(self.policy_api,
|
with mock.patch.object(self.policy_api,
|
||||||
"create_or_update") as api_call:
|
"create_or_update") as api_call:
|
||||||
result = self.resourceApi.create_or_overwrite_map_only(
|
result = self.resourceApi.create_or_overwrite_map_only(
|
||||||
name, domain_id, description=description,
|
name, domain_id, description=description,
|
||||||
tenant=TEST_TENANT)
|
map_sequence_number=map_seq_num, tenant=TEST_TENANT)
|
||||||
|
|
||||||
expected_map_def = self.mapDef(
|
expected_map_def = self.mapDef(
|
||||||
domain_id=domain_id,
|
domain_id=domain_id,
|
||||||
@@ -1200,6 +1204,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
name=name,
|
name=name,
|
||||||
description=description,
|
description=description,
|
||||||
category=constants.CATEGORY_APPLICATION,
|
category=constants.CATEGORY_APPLICATION,
|
||||||
|
map_sequence_number=map_seq_num,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
|
||||||
self.assert_called_with_def(api_call, expected_map_def)
|
self.assert_called_with_def(api_call, expected_map_def)
|
||||||
@@ -1340,6 +1345,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
service_id = 'c1'
|
service_id = 'c1'
|
||||||
category = 'Emergency'
|
category = 'Emergency'
|
||||||
ip_protocol = nsx_constants.IPV4
|
ip_protocol = nsx_constants.IPV4
|
||||||
|
map_seq_num = 10
|
||||||
|
|
||||||
rule_id = 1
|
rule_id = 1
|
||||||
entry1 = self.resourceApi.build_entry(
|
entry1 = self.resourceApi.build_entry(
|
||||||
@@ -1367,6 +1373,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
description=description,
|
description=description,
|
||||||
entries=[entry1, entry2],
|
entries=[entry1, entry2],
|
||||||
category=category,
|
category=category,
|
||||||
|
map_sequence_number=map_seq_num,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
|
||||||
expected_def = self.mapDef(
|
expected_def = self.mapDef(
|
||||||
@@ -1375,6 +1382,7 @@ class TestPolicyCommunicationMap(NsxPolicyLibTestCase):
|
|||||||
name=name,
|
name=name,
|
||||||
description=description,
|
description=description,
|
||||||
category=category,
|
category=category,
|
||||||
|
map_sequence_number=map_seq_num,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
|
||||||
self.assert_called_with_defs(api_call,
|
self.assert_called_with_defs(api_call,
|
||||||
|
|||||||
@@ -1158,7 +1158,11 @@ class SecurityPolicyBaseDef(ResourceDef):
|
|||||||
def get_obj_dict(self):
|
def get_obj_dict(self):
|
||||||
body = super(SecurityPolicyBaseDef, self).get_obj_dict()
|
body = super(SecurityPolicyBaseDef, self).get_obj_dict()
|
||||||
self._set_attr_if_specified(body, 'category')
|
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
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2397,6 +2397,7 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
source_groups=IGNORE, dest_groups=IGNORE,
|
source_groups=IGNORE, dest_groups=IGNORE,
|
||||||
direction=nsx_constants.IN_OUT,
|
direction=nsx_constants.IN_OUT,
|
||||||
logged=IGNORE, tags=IGNORE,
|
logged=IGNORE, tags=IGNORE,
|
||||||
|
map_sequence_number=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
"""Create CommunicationMap & Entry.
|
"""Create CommunicationMap & Entry.
|
||||||
|
|
||||||
@@ -2439,7 +2440,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
map_def = self._init_parent_def(
|
map_def = self._init_parent_def(
|
||||||
domain_id=domain_id, map_id=map_id,
|
domain_id=domain_id, map_id=map_id,
|
||||||
tenant=tenant, name=name, description=description,
|
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)
|
self._create_or_store(map_def, entry_def)
|
||||||
return map_id
|
return map_id
|
||||||
@@ -2447,7 +2449,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
def create_or_overwrite_map_only(
|
def create_or_overwrite_map_only(
|
||||||
self, name, domain_id, map_id=None, description=IGNORE,
|
self, name, domain_id, map_id=None, description=IGNORE,
|
||||||
category=constants.CATEGORY_APPLICATION,
|
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 or update a CommunicationMap
|
||||||
|
|
||||||
Create a communication map without any entries, or update the
|
Create a communication map without any entries, or update the
|
||||||
@@ -2457,7 +2460,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
map_def = self._init_parent_def(
|
map_def = self._init_parent_def(
|
||||||
domain_id=domain_id, map_id=map_id,
|
domain_id=domain_id, map_id=map_id,
|
||||||
tenant=tenant, name=name, description=description,
|
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)
|
self._create_or_store(map_def)
|
||||||
return map_id
|
return map_id
|
||||||
@@ -2492,7 +2496,7 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
self, name, domain_id, map_id=None,
|
self, name, domain_id, map_id=None,
|
||||||
description=IGNORE,
|
description=IGNORE,
|
||||||
category=constants.CATEGORY_APPLICATION,
|
category=constants.CATEGORY_APPLICATION,
|
||||||
entries=None, tags=IGNORE,
|
entries=None, tags=IGNORE, map_sequence_number=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT):
|
||||||
"""Create CommunicationMap with entries"""
|
"""Create CommunicationMap with entries"""
|
||||||
|
|
||||||
@@ -2501,7 +2505,8 @@ class NsxPolicySecurityPolicyBaseApi(NsxPolicyResourceBase):
|
|||||||
map_def = self._init_parent_def(
|
map_def = self._init_parent_def(
|
||||||
domain_id=domain_id, map_id=map_id,
|
domain_id=domain_id, map_id=map_id,
|
||||||
tenant=tenant, name=name, description=description,
|
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)
|
self.policy_api.create_with_parent(map_def, entries)
|
||||||
return map_id
|
return map_id
|
||||||
|
|||||||
Reference in New Issue
Block a user