Get logs of creating container should return 409

Closes-Bug: #1680212

Change-Id: Id5936c000674a2584e1af53eb587ddf8df02373c
This commit is contained in:
Feng Shengqin 2017-04-06 10:45:46 +08:00 committed by feng.shengqin
parent 9289330373
commit a43e0d056f
3 changed files with 11 additions and 0 deletions

View File

@ -394,6 +394,7 @@ class ContainersController(rest.RestController):
timestamps=False, tail='all', since=None):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:logs")
utils.validate_container_state(container, 'logs')
try:
stdout = strutils.bool_from_string(stdout, strict=True)
stderr = strutils.bool_from_string(stderr, strict=True)

View File

@ -50,6 +50,7 @@ VALID_STATES = {
'top': ['Running'],
'get_archive': ['Running', 'Stopped', 'Paused', 'Created'],
'put_archive': ['Running', 'Stopped', 'Paused', 'Created'],
'logs': ['Running', 'Stopped', 'Paused', 'Created', 'Error', 'Unknown'],
}

View File

@ -791,6 +791,15 @@ class TestContainerController(api_base.FunctionalTest):
container_uuid, params)
self.assertFalse(mock_container_logs.called)
def test_get_logs_with_invalid_state(self):
uuid = uuidutils.generate_uuid()
test_object = utils.create_test_container(context=self.context,
uuid=uuid, status='Creating')
with self.assertRaisesRegexp(
AppError,
"Cannot logs container %s in Creating state" % uuid):
self.app.get('/v1/containers/%s/logs/' % test_object.uuid)
@patch('zun.common.utils.validate_container_state')
@patch('zun.compute.api.API.container_exec')
@patch('zun.objects.Container.get_by_uuid')