Merge "Force delete a paused container return 500"

This commit is contained in:
Jenkins 2017-04-06 03:25:24 +00:00 committed by Gerrit Code Review
commit 40543cd49c
3 changed files with 13 additions and 0 deletions

View File

@ -314,6 +314,8 @@ class ContainersController(rest.RestController):
raise exception.InvalidValue(msg)
if not force:
utils.validate_container_state(container, 'delete')
else:
utils.validate_container_state(container, 'delete_force')
context = pecan.request.context
compute_api = pecan.request.compute_api
compute_api.container_delete(context, container, force)

View File

@ -36,6 +36,8 @@ LOG = logging.getLogger(__name__)
VALID_STATES = {
'delete': ['Stopped', 'Error', 'Created'],
'delete_force': ['Running', 'Stopped', 'Error', 'Created',
'Unknown', 'Creating'],
'start': ['Stopped', 'Created'],
'stop': ['Running'],
'reboot': ['Running', 'Stopped', 'Created'],

View File

@ -847,6 +847,15 @@ class TestContainerController(api_base.FunctionalTest):
"Cannot delete container %s in Running state" % uuid):
self.app.delete('/v1/containers/%s' % (test_object.uuid))
def test_delete_force_by_uuid_invalid_state(self):
uuid = uuidutils.generate_uuid()
test_object = utils.create_test_container(context=self.context,
uuid=uuid, status='Paused')
with self.assertRaisesRegexp(
AppError,
"Cannot delete_force container %s in Paused state" % uuid):
self.app.delete('/v1/containers/%s?force=True' % test_object.uuid)
@patch('zun.compute.api.API.container_delete')
def test_delete_by_uuid_invalid_state_force_true(self, mock_delete):
uuid = uuidutils.generate_uuid()