Add force update of Policy T1 Adv Rules
In certain cases, caller would need to add route advertisment rules on
Policy Tier1 owned by other accounts. This change adds the support by
propagating the "force" param to include X-Allow-Overwrite header in the
final API call. The same operation is already allowed in MP counterpart.
Change-Id: Ic09fb16dd2403f33323c179d68fd2f1f3ce4bb42
(cherry picked from commit cfe4ed8e27
)
This commit is contained in:
parent
a52f9e0c6e
commit
4a469023af
|
@ -3435,30 +3435,33 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
|
|||
rule_pfx_operator = 'GE'
|
||||
rule_adv_types = ['A']
|
||||
rule_subnets = ['x', 'y', 'z']
|
||||
with mock.patch.object(self.policy_api,
|
||||
"get",
|
||||
return_value={'id': tier1_id,
|
||||
'resource_type': 'Tier1'}),\
|
||||
mock.patch.object(self.policy_api,
|
||||
'create_or_update') as api_call:
|
||||
self.resourceApi.add_advertisement_rule(
|
||||
tier1_id, rule_name, action=rule_action,
|
||||
prefix_operator=rule_pfx_operator,
|
||||
route_advertisement_types=rule_adv_types, subnets=rule_subnets,
|
||||
tenant=TEST_TENANT)
|
||||
for force in [True, False]:
|
||||
with mock.patch.object(self.policy_api,
|
||||
"get",
|
||||
return_value={'id': tier1_id,
|
||||
'resource_type': 'Tier1'}),\
|
||||
mock.patch.object(self.policy_api,
|
||||
'create_or_update') as api_call:
|
||||
self.resourceApi.add_advertisement_rule(
|
||||
tier1_id, rule_name, action=rule_action,
|
||||
prefix_operator=rule_pfx_operator,
|
||||
route_advertisement_types=rule_adv_types,
|
||||
subnets=rule_subnets, force=force, tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.Tier1Def(
|
||||
tier1_id=tier1_id,
|
||||
route_advertisement_rules=[
|
||||
core_defs.RouteAdvertisementRule(
|
||||
rule_name,
|
||||
action=rule_action,
|
||||
prefix_operator=rule_pfx_operator,
|
||||
route_advertisement_types=rule_adv_types,
|
||||
subnets=rule_subnets)],
|
||||
tenant=TEST_TENANT)
|
||||
expected_def = core_defs.Tier1Def(
|
||||
tier1_id=tier1_id,
|
||||
route_advertisement_rules=[
|
||||
core_defs.RouteAdvertisementRule(
|
||||
rule_name,
|
||||
action=rule_action,
|
||||
prefix_operator=rule_pfx_operator,
|
||||
route_advertisement_types=rule_adv_types,
|
||||
subnets=rule_subnets)],
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assert_called_with_def_and_kwargs(
|
||||
api_call, expected_def, force=force,
|
||||
partial_updates=self.partial_updates)
|
||||
|
||||
def test_remove_advertisement_rule(self):
|
||||
tier1_id = '111'
|
||||
|
@ -3472,14 +3475,16 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
|
|||
mock.patch.object(self.policy_api,
|
||||
'create_or_update') as api_call:
|
||||
self.resourceApi.remove_advertisement_rule(
|
||||
tier1_id, rule_name, tenant=TEST_TENANT)
|
||||
tier1_id, rule_name, force=True, tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.Tier1Def(
|
||||
tier1_id=tier1_id,
|
||||
route_advertisement_rules=[],
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
self.assert_called_with_def_and_kwargs(
|
||||
api_call, expected_def, force=True,
|
||||
partial_updates=self.partial_updates)
|
||||
|
||||
def test_update_advertisement_rules(self):
|
||||
tier1_id = '111'
|
||||
|
@ -3489,19 +3494,23 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
|
|||
'id': tier1_id,
|
||||
'route_advertisement_rules': [{'name': old_rule}]}
|
||||
rules = [{'name': new_rule}]
|
||||
with mock.patch.object(self.policy_api,
|
||||
"get",
|
||||
return_value=get_retval),\
|
||||
mock.patch.object(self.policy_api,
|
||||
'create_or_update') as api_call:
|
||||
self.resourceApi.update_advertisement_rules(
|
||||
tier1_id, rules, name_prefix=None, tenant=TEST_TENANT)
|
||||
for force in [True, False]:
|
||||
with mock.patch.object(self.policy_api,
|
||||
"get",
|
||||
return_value=get_retval),\
|
||||
mock.patch.object(self.policy_api,
|
||||
'create_or_update') as api_call:
|
||||
self.resourceApi.update_advertisement_rules(
|
||||
tier1_id, rules, name_prefix=None, force=force,
|
||||
tenant=TEST_TENANT)
|
||||
|
||||
expected_def = core_defs.Tier1Def(
|
||||
tier1_id=tier1_id,
|
||||
route_advertisement_rules=rules,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(api_call, expected_def)
|
||||
expected_def = core_defs.Tier1Def(
|
||||
tier1_id=tier1_id,
|
||||
route_advertisement_rules=rules,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def_and_kwargs(
|
||||
api_call, expected_def, force=force,
|
||||
partial_updates=self.partial_updates)
|
||||
|
||||
def test_update_advertisement_rules_with_replace(self):
|
||||
tier1_id = '111'
|
||||
|
|
|
@ -1155,6 +1155,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
route_advertisement=IGNORE,
|
||||
route_advertisement_rules=IGNORE,
|
||||
pool_allocation=IGNORE,
|
||||
force=False,
|
||||
tenant=constants.POLICY_INFRA_TENANT,
|
||||
current_body=None):
|
||||
|
||||
|
@ -1171,6 +1172,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
route_advertisement=route_advertisement,
|
||||
route_advertisement_rules=route_advertisement_rules,
|
||||
pool_allocation=pool_allocation,
|
||||
force=force,
|
||||
tags=tags,
|
||||
tenant=tenant)
|
||||
|
||||
|
@ -1201,7 +1203,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
|
||||
def add_advertisement_rule(
|
||||
self, tier1_id, name, action=None, prefix_operator=None,
|
||||
route_advertisement_types=None, subnets=None,
|
||||
route_advertisement_types=None, subnets=None, force=False,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
tier1_dict = self.get(tier1_id, tenant)
|
||||
adv_rules = tier1_dict.get('route_advertisement_rules', [])
|
||||
|
@ -1214,10 +1216,10 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
adv_rules.append(adv_rule)
|
||||
self.update(tier1_id,
|
||||
route_advertisement_rules=adv_rules,
|
||||
tenant=tenant,
|
||||
force=force, tenant=tenant,
|
||||
current_body=tier1_dict)
|
||||
|
||||
def remove_advertisement_rule(self, tier1_id, name,
|
||||
def remove_advertisement_rule(self, tier1_id, name, force=False,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
tier1_dict = self.get(tier1_id, tenant)
|
||||
adv_rules = tier1_dict.get('route_advertisement_rules', [])
|
||||
|
@ -1225,7 +1227,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
if updated_adv_rules != adv_rules:
|
||||
self.update(tier1_id,
|
||||
route_advertisement_rules=updated_adv_rules,
|
||||
tenant=tenant,
|
||||
force=force, tenant=tenant,
|
||||
current_body=tier1_dict)
|
||||
|
||||
def build_advertisement_rule(self, name, action=None, prefix_operator=None,
|
||||
|
@ -1236,7 +1238,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
subnets=subnets)
|
||||
|
||||
def update_advertisement_rules(self, tier1_id, rules=None,
|
||||
name_prefix=None,
|
||||
name_prefix=None, force=False,
|
||||
tenant=constants.POLICY_INFRA_TENANT):
|
||||
"""Update the router advertisement rules
|
||||
|
||||
|
@ -1262,7 +1264,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
|
|||
|
||||
self.update(tier1_id,
|
||||
route_advertisement_rules=new_rules,
|
||||
tenant=tenant,
|
||||
force=force, tenant=tenant,
|
||||
current_body=tier1_dict)
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue