Add 'X-Allow-Overwrite' in header for policy API force update
Change-Id: I8449bb9313b7f2e14484ca58b307e80419356246
This commit is contained in:
parent
753ed629bb
commit
600d8562e5
@ -1115,7 +1115,8 @@ class TestPolicyLBVirtualServer(test_resources.NsxPolicyLibTestCase):
|
|||||||
virtual_server_id=obj_id, name=vs_name,
|
virtual_server_id=obj_id, name=vs_name,
|
||||||
max_concurrent_connections=None,
|
max_concurrent_connections=None,
|
||||||
tenant=TEST_TENANT)
|
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)
|
self.assert_called_with_def(update_call, expected_def)
|
||||||
|
|
||||||
def test_add_lb_rule(self):
|
def test_add_lb_rule(self):
|
||||||
|
@ -5881,14 +5881,15 @@ class TestPolicyTier0RouteMap(NsxPolicyLibTestCase):
|
|||||||
with self.mock_get(tier0_id, name), \
|
with self.mock_get(tier0_id, name), \
|
||||||
self.mock_create_update() as update_call:
|
self.mock_create_update() as update_call:
|
||||||
self.resourceApi.update(name, tier0_id, route_map_id, entries,
|
self.resourceApi.update(name, tier0_id, route_map_id, entries,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT, force=True)
|
||||||
expected_def = core_defs.Tier0RouteMapDef(
|
expected_def = core_defs.Tier0RouteMapDef(
|
||||||
tier0_id=tier0_id,
|
tier0_id=tier0_id,
|
||||||
route_map_id=route_map_id,
|
route_map_id=route_map_id,
|
||||||
name=name,
|
name=name,
|
||||||
entries=entries,
|
entries=entries,
|
||||||
tenant=TEST_TENANT)
|
tenant=TEST_TENANT)
|
||||||
|
update_call.assert_called_with(mock.ANY, partial_updates=True,
|
||||||
|
force=True)
|
||||||
self.assert_called_with_def(update_call, expected_def)
|
self.assert_called_with_def(update_call, expected_def)
|
||||||
|
|
||||||
def test_build_route_map_entry(self):
|
def test_build_route_map_entry(self):
|
||||||
|
@ -2365,7 +2365,8 @@ class NsxPolicyApi(object):
|
|||||||
def partial_updates_supported(self):
|
def partial_updates_supported(self):
|
||||||
return self.partial_updates
|
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.
|
"""Create or update a policy object.
|
||||||
|
|
||||||
This api will update an existing object, or create a new one if it
|
This api will update an existing object, or create a new one if it
|
||||||
@ -2380,6 +2381,11 @@ class NsxPolicyApi(object):
|
|||||||
headers = None
|
headers = None
|
||||||
if partial_updates:
|
if partial_updates:
|
||||||
headers = {'nsx-enable-partial-patch': 'true'}
|
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)
|
self.client.patch(path, body, headers=headers)
|
||||||
|
|
||||||
def create_with_parent(self, parent_def, resource_def):
|
def create_with_parent(self, parent_def, resource_def):
|
||||||
|
@ -143,7 +143,7 @@ class NsxPolicyResourceBase(object):
|
|||||||
|
|
||||||
return resource_def
|
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"""
|
"""Helper for update function - ignore attrs without explicit value"""
|
||||||
if (allow_partial_updates and
|
if (allow_partial_updates and
|
||||||
self.policy_api.partial_updates_supported()):
|
self.policy_api.partial_updates_supported()):
|
||||||
@ -157,7 +157,7 @@ class NsxPolicyResourceBase(object):
|
|||||||
# Nothing to update - only keys provided in kwargs
|
# Nothing to update - only keys provided in kwargs
|
||||||
return
|
return
|
||||||
self.policy_api.create_or_update(
|
self.policy_api.create_or_update(
|
||||||
policy_def, partial_updates=partial_updates)
|
policy_def, partial_updates=partial_updates, force=force)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _init_obj_uuid(obj_uuid):
|
def _init_obj_uuid(obj_uuid):
|
||||||
@ -4480,14 +4480,16 @@ class NsxPolicyTier0RouteMapApi(NsxPolicyResourceBase):
|
|||||||
entries,
|
entries,
|
||||||
description=IGNORE,
|
description=IGNORE,
|
||||||
tags=IGNORE,
|
tags=IGNORE,
|
||||||
tenant=constants.POLICY_INFRA_TENANT):
|
tenant=constants.POLICY_INFRA_TENANT,
|
||||||
|
force=False):
|
||||||
self._update(tier0_id=tier0_id,
|
self._update(tier0_id=tier0_id,
|
||||||
route_map_id=route_map_id,
|
route_map_id=route_map_id,
|
||||||
name=name,
|
name=name,
|
||||||
entries=entries,
|
entries=entries,
|
||||||
description=description,
|
description=description,
|
||||||
tags=tags,
|
tags=tags,
|
||||||
tenant=tenant)
|
tenant=tenant,
|
||||||
|
force=force)
|
||||||
|
|
||||||
def build_route_map_entry(self, action, community_list_matches=None,
|
def build_route_map_entry(self, action, community_list_matches=None,
|
||||||
prefix_list_matches=None, entry_set=None):
|
prefix_list_matches=None, entry_set=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user