Merge "Get logs of creating container should return 409"

This commit is contained in:
Jenkins 2017-04-08 01:50:11 +00:00 committed by Gerrit Code Review
commit 257890f3bc
3 changed files with 11 additions and 0 deletions

View File

@ -396,6 +396,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

@ -52,6 +52,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')