Remove the "Patch" function
The "Patch" function in the magnum/api/controllers/v1/container.py isn't called,so we should delete it. Change-Id: I6f7d041978fd5340d13747b11ebf8bb7b3d195f5 Closes-Bug: #1561401
This commit is contained in:
parent
f153d61c44
commit
df1bf7e25d
|
@ -410,40 +410,6 @@ class ContainersController(rest.RestController):
|
||||||
res_container.uuid)
|
res_container.uuid)
|
||||||
return Container.convert_with_links(res_container)
|
return Container.convert_with_links(res_container)
|
||||||
|
|
||||||
@wsme.validate(types.uuid, [ContainerPatchType])
|
|
||||||
@expose.expose(Container, types.uuid_or_name,
|
|
||||||
body=[ContainerPatchType])
|
|
||||||
def patch(self, container_ident, patch):
|
|
||||||
"""Update an existing container.
|
|
||||||
|
|
||||||
:param container_ident: UUID or name of a container.
|
|
||||||
:param patch: a json PATCH document to apply to this container.
|
|
||||||
"""
|
|
||||||
container = api_utils.get_resource('Container',
|
|
||||||
container_ident)
|
|
||||||
check_policy_on_container(container, "container:update")
|
|
||||||
try:
|
|
||||||
container_dict = container.as_dict()
|
|
||||||
new_container = Container(**api_utils.apply_jsonpatch(
|
|
||||||
container_dict, patch))
|
|
||||||
except api_utils.JSONPATCH_EXCEPTIONS as e:
|
|
||||||
raise exception.PatchError(patch=patch, reason=e)
|
|
||||||
|
|
||||||
# Update only the fields that have changed
|
|
||||||
for field in objects.Container.fields:
|
|
||||||
try:
|
|
||||||
patch_val = getattr(new_container, field)
|
|
||||||
except AttributeError:
|
|
||||||
# Ignore fields that aren't exposed in the API
|
|
||||||
continue
|
|
||||||
if patch_val == wtypes.Unset:
|
|
||||||
patch_val = None
|
|
||||||
if container[field] != patch_val:
|
|
||||||
container[field] = patch_val
|
|
||||||
|
|
||||||
container.save()
|
|
||||||
return Container.convert_with_links(container)
|
|
||||||
|
|
||||||
@expose.expose(None, types.uuid_or_name, status_code=204)
|
@expose.expose(None, types.uuid_or_name, status_code=204)
|
||||||
def delete(self, container_ident):
|
def delete(self, container_ident):
|
||||||
"""Delete a container.
|
"""Delete a container.
|
||||||
|
|
|
@ -392,44 +392,6 @@ class TestContainerController(api_base.FunctionalTest):
|
||||||
self.assertEqual(test_container['uuid'],
|
self.assertEqual(test_container['uuid'],
|
||||||
response.json['uuid'])
|
response.json['uuid'])
|
||||||
|
|
||||||
@patch('magnum.objects.Container.get_by_uuid')
|
|
||||||
def test_patch_by_uuid(self, mock_container_get_by_uuid):
|
|
||||||
test_container = utils.get_test_container()
|
|
||||||
test_container_obj = objects.Container(self.context, **test_container)
|
|
||||||
mock_container_get_by_uuid.return_value = test_container_obj
|
|
||||||
|
|
||||||
with patch.object(test_container_obj, 'save') as mock_save:
|
|
||||||
params = [{'path': '/name',
|
|
||||||
'value': 'new_name',
|
|
||||||
'op': 'replace'}]
|
|
||||||
container_uuid = test_container.get('uuid')
|
|
||||||
response = self.app.patch_json(
|
|
||||||
'/v1/containers/%s' % container_uuid,
|
|
||||||
params=params)
|
|
||||||
|
|
||||||
mock_save.assert_called_once_with()
|
|
||||||
self.assertEqual(200, response.status_int)
|
|
||||||
self.assertEqual('new_name', test_container_obj.name)
|
|
||||||
|
|
||||||
@patch('magnum.objects.Container.get_by_name')
|
|
||||||
def test_patch_by_name(self, mock_container_get_by_name):
|
|
||||||
test_container = utils.get_test_container()
|
|
||||||
test_container_obj = objects.Container(self.context, **test_container)
|
|
||||||
mock_container_get_by_name.return_value = test_container_obj
|
|
||||||
|
|
||||||
with patch.object(test_container_obj, 'save') as mock_save:
|
|
||||||
params = [{'path': '/name',
|
|
||||||
'value': 'new_name',
|
|
||||||
'op': 'replace'}]
|
|
||||||
container_name = test_container.get('name')
|
|
||||||
response = self.app.patch_json(
|
|
||||||
'/v1/containers/%s' % container_name,
|
|
||||||
params=params)
|
|
||||||
|
|
||||||
mock_save.assert_called_once_with()
|
|
||||||
self.assertEqual(200, response.status_int)
|
|
||||||
self.assertEqual('new_name', test_container_obj.name)
|
|
||||||
|
|
||||||
def _action_test(self, container, action, ident_field):
|
def _action_test(self, container, action, ident_field):
|
||||||
test_container_obj = objects.Container(self.context, **container)
|
test_container_obj = objects.Container(self.context, **container)
|
||||||
ident = container.get(ident_field)
|
ident = container.get(ident_field)
|
||||||
|
@ -665,18 +627,6 @@ class TestContainerEnforcement(api_base.FunctionalTest):
|
||||||
'/containers/%s/detail' % comm_utils.generate_uuid(),
|
'/containers/%s/detail' % comm_utils.generate_uuid(),
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
|
|
||||||
def test_policy_disallow_update(self):
|
|
||||||
bay = obj_utils.create_test_bay(self.context)
|
|
||||||
container = obj_utils.create_test_container(self.context,
|
|
||||||
bay_uuid=bay.uuid)
|
|
||||||
params = [{'path': '/name',
|
|
||||||
'value': 'new_name',
|
|
||||||
'op': 'replace'}]
|
|
||||||
self._common_policy_check(
|
|
||||||
'container:update', self.app.patch_json,
|
|
||||||
'/v1/containers/%s' % container.uuid, params,
|
|
||||||
expect_errors=True)
|
|
||||||
|
|
||||||
def test_policy_disallow_create(self):
|
def test_policy_disallow_create(self):
|
||||||
baymodel = obj_utils.create_test_baymodel(self.context)
|
baymodel = obj_utils.create_test_baymodel(self.context)
|
||||||
bay = obj_utils.create_test_bay(self.context,
|
bay = obj_utils.create_test_bay(self.context,
|
||||||
|
@ -715,15 +665,6 @@ class TestContainerEnforcement(api_base.FunctionalTest):
|
||||||
'/containers/%s' % container.uuid,
|
'/containers/%s' % container.uuid,
|
||||||
expect_errors=True)
|
expect_errors=True)
|
||||||
|
|
||||||
def test_policy_only_owner_update(self):
|
|
||||||
container = obj_utils.create_test_container(self.context,
|
|
||||||
user_id='another')
|
|
||||||
self._owner_check(
|
|
||||||
"container:update", self.patch_json,
|
|
||||||
'/containers/%s' % container.uuid,
|
|
||||||
[{'path': '/name', 'value': "new_name", 'op': 'replace'}],
|
|
||||||
expect_errors=True)
|
|
||||||
|
|
||||||
def test_policy_only_owner_delete(self):
|
def test_policy_only_owner_delete(self):
|
||||||
container = obj_utils.create_test_container(self.context,
|
container = obj_utils.create_test_container(self.context,
|
||||||
user_id='another')
|
user_id='another')
|
||||||
|
|
Loading…
Reference in New Issue