From a43e0d056ff2ae7ced0ffe7f478b8c24f66445ff Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Thu, 6 Apr 2017 10:45:46 +0800 Subject: [PATCH] Get logs of creating container should return 409 Closes-Bug: #1680212 Change-Id: Id5936c000674a2584e1af53eb587ddf8df02373c --- zun/api/controllers/v1/containers.py | 1 + zun/common/utils.py | 1 + zun/tests/unit/api/controllers/v1/test_containers.py | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index a932dd509..53b85b2f4 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -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) diff --git a/zun/common/utils.py b/zun/common/utils.py index 821b13e57..24ca48964 100644 --- a/zun/common/utils.py +++ b/zun/common/utils.py @@ -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'], } diff --git a/zun/tests/unit/api/controllers/v1/test_containers.py b/zun/tests/unit/api/controllers/v1/test_containers.py index 74ec07f74..513519720 100644 --- a/zun/tests/unit/api/controllers/v1/test_containers.py +++ b/zun/tests/unit/api/controllers/v1/test_containers.py @@ -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')