Add 'X-Allow-Overwrite' in header for policy API force update

Change-Id: I8449bb9313b7f2e14484ca58b307e80419356246
This commit is contained in:
Danting Liu 2020-04-07 20:14:03 -07:00
parent 753ed629bb
commit 600d8562e5
4 changed files with 18 additions and 8 deletions

View File

@ -1115,7 +1115,8 @@ class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase):
virtual_server_id=obj_id, name=vs_name,
max_concurrent_connections=None,
tenant=TEST_TENANT)
update_call.assert_called_with(mock.ANY, partial_updates=False)
update_call.assert_called_with(mock.ANY, partial_updates=False,
force=False)
self.assert_called_with_def(update_call, expected_def)
def test_add_lb_rule(self):

View File

@ -5881,14 +5881,15 @@ class TestPolicyTier0RouteMap(NsxPolicyLibTestCase):
with self.mock_get(tier0_id, name), \
self.mock_create_update() as update_call:
self.resourceApi.update(name, tier0_id, route_map_id, entries,
tenant=TEST_TENANT)
tenant=TEST_TENANT, force=True)
expected_def = core_defs.Tier0RouteMapDef(
tier0_id=tier0_id,
route_map_id=route_map_id,
name=name,
entries=entries,
tenant=TEST_TENANT)
update_call.assert_called_with(mock.ANY, partial_updates=True,
force=True)
self.assert_called_with_def(update_call, expected_def)
def test_build_route_map_entry(self):

View File

@ -2365,7 +2365,8 @@ class NsxPolicyApi(object):
def partial_updates_supported(self):
return self.partial_updates
def create_or_update(self, resource_def, partial_updates=False):
def create_or_update(self, resource_def, partial_updates=False,
force=False):
"""Create or update a policy object.
This api will update an existing object, or create a new one if it
@ -2380,6 +2381,11 @@ class NsxPolicyApi(object):
headers = None
if partial_updates:
headers = {'nsx-enable-partial-patch': 'true'}
if force:
if headers:
headers['X-Allow-Overwrite'] = 'true'
else:
headers = {'X-Allow-Overwrite': 'true'}
self.client.patch(path, body, headers=headers)
def create_with_parent(self, parent_def, resource_def):

View File

@ -143,7 +143,7 @@ class NsxPolicyResourceBase(object):
return resource_def
def _update(self, allow_partial_updates=True, **kwargs):
def _update(self, allow_partial_updates=True, force=False, **kwargs):
"""Helper for update function - ignore attrs without explicit value"""
if (allow_partial_updates and
self.policy_api.partial_updates_supported()):
@ -157,7 +157,7 @@ class NsxPolicyResourceBase(object):
# Nothing to update - only keys provided in kwargs
return
self.policy_api.create_or_update(
policy_def, partial_updates=partial_updates)
policy_def, partial_updates=partial_updates, force=force)
@staticmethod
def _init_obj_uuid(obj_uuid):
@ -4480,14 +4480,16 @@ class NsxPolicyTier0RouteMapApi(NsxPolicyResourceBase):
entries,
description=IGNORE,
tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
tenant=constants.POLICY_INFRA_TENANT,
force=False):
self._update(tier0_id=tier0_id,
route_map_id=route_map_id,
name=name,
entries=entries,
description=description,
tags=tags,
tenant=tenant)
tenant=tenant,
force=force)
def build_route_map_entry(self, action, community_list_matches=None,
prefix_list_matches=None, entry_set=None):