diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index 84ddd3c99..1904efbba 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -428,36 +428,6 @@ class ContainersController(base.Controller): container.save(context) return view.format_container(pecan.request.host_url, container) - @base.Controller.api_version("1.1", "1.6") - @pecan.expose('json') - @exception.wrap_pecan_controller_exception - @validation.validate_query_param(pecan.request, schema.query_param_delete) - def delete(self, container_ident, force=False, **kwargs): - """Delete a container. - - :param container_ident: UUID or Name of a container. - """ - context = pecan.request.context - if utils.is_all_tenants(kwargs): - policy.enforce(context, "container:delete_all_tenants", - action="container:delete_all_tenants") - context.all_tenants = True - container = utils.get_container(container_ident) - check_policy_on_container(container.as_dict(), "container:delete") - try: - force = strutils.bool_from_string(force, strict=True) - except ValueError: - msg = _('Valid force values are true, false, 0, 1, yes and no') - raise exception.InvalidValue(msg) - if not force: - utils.validate_container_state(container, 'delete') - else: - utils.validate_container_state(container, 'delete_force') - compute_api = pecan.request.compute_api - compute_api.container_delete(context, container, force) - pecan.response.status = 204 - - @base.Controller.api_version("1.7") # noqa @pecan.expose('json') @exception.wrap_pecan_controller_exception @validation.validate_query_param(pecan.request, schema.query_param_delete) @@ -482,9 +452,12 @@ class ContainersController(base.Controller): if not force: utils.validate_container_state(container, 'delete') else: + req_version = pecan.request.version + min_version = versions.Version('', '', '', '1.7') + if req_version >= min_version: + policy.enforce(context, "container:delete_force", + action="container:delete_force") utils.validate_container_state(container, 'delete_force') - policy.enforce(context, "container:delete_force", - action="container:delete_force") compute_api = pecan.request.compute_api container.status = consts.DELETING compute_api.container_delete(context, container, force) diff --git a/zun/tests/unit/api/controllers/v1/test_containers.py b/zun/tests/unit/api/controllers/v1/test_containers.py index 85e4955fa..4fb11d3e7 100644 --- a/zun/tests/unit/api/controllers/v1/test_containers.py +++ b/zun/tests/unit/api/controllers/v1/test_containers.py @@ -1285,7 +1285,9 @@ class TestContainerController(api_base.FunctionalTest): "Cannot delete container %s in Running state" % uuid): self.delete('/v1/containers/%s' % (test_object.uuid)) - def test_delete_force_by_uuid_invalid_state(self): + @patch('zun.common.policy.enforce') + def test_delete_force_by_uuid_invalid_state(self, mock_policy): + mock_policy.return_value = True uuid = uuidutils.generate_uuid() test_object = utils.create_test_container(context=self.context, uuid=uuid, status='Paused')