diff options
author | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2014-04-10 20:46:13 +0900 |
---|---|---|
committer | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2014-04-14 20:25:04 +0900 |
commit | 8e5577f52f660960738f1fc0384dff77fa30fc8a (patch) | |
tree | d6ab6aa24138d9a7acfe61303e93bc2f85c22e33 | |
parent | 601b55f8f18ceb88f99254596d835fd60e067268 (diff) | |
download | nova-8e5577f52f660960738f1fc0384dff77fa30fc8a.tar.gz |
Allow -1 as the length of "get console output" API
Current "get console output" API does not allow -1 as the length and
returns a BadRequest response if receiving it. The other APIs(quota)
considers -1 as an unlimited value.
This patch allows -1 as the length for API consistency.
DocImpact
Change-Id: Idf88a238d1b0e545ebab5be872269b1b1030cc56
Related-Bug: #1295426
3 files changed, 23 insertions, 4 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/console_output.py b/nova/api/openstack/compute/plugins/v3/console_output.py index 843fe76220..8e118d4d7c 100644 --- a/nova/api/openstack/compute/plugins/v3/console_output.py +++ b/nova/api/openstack/compute/plugins/v3/console_output.py @@ -44,6 +44,10 @@ class ConsoleOutputController(wsgi.Controller): instance = common.get_instance(self.compute_api, context, id) length = body['get_console_output'].get('length') + if length is not None and int(length) == -1: + # NOTE: -1 means an unlimited length. So here translates it to None + # which also means an unlimited in the internal implementation. + length = None try: output = self.compute_api.get_console_output(context, diff --git a/nova/api/openstack/compute/schemas/v3/console_output.py b/nova/api/openstack/compute/schemas/v3/console_output.py index d3f58977eb..c3e70401a1 100644 --- a/nova/api/openstack/compute/schemas/v3/console_output.py +++ b/nova/api/openstack/compute/schemas/v3/console_output.py @@ -20,8 +20,9 @@ get_console_output = { 'properties': { 'length': { 'type': ['integer', 'string'], - 'minimum': 0, - 'pattern': '^[0-9]+$', + 'pattern': '^-?[0-9]+$', + # NOTE: -1 means an unlimited length. + 'minimum': -1, }, }, 'additionalProperties': False, diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_console_output.py b/nova/tests/api/openstack/compute/plugins/v3/test_console_output.py index 00c4ad5b03..312ce15646 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_console_output.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_console_output.py @@ -92,6 +92,20 @@ class ConsoleOutputExtensionTest(test.NoDBTestCase): self.assertEqual(res.status_int, 200) self.assertEqual(output, {'output': '2\n3\n4'}) + def test_get_console_output_with_unlimited_length(self): + req = self._create_request(length_dict={'length': -1}) + res = req.get_response(self.app) + output = jsonutils.loads(res.body) + self.assertEqual(res.status_int, 200) + self.assertEqual(output, {'output': '0\n1\n2\n3\n4'}) + + def test_get_console_output_with_unlimited_length_as_str(self): + req = self._create_request(length_dict={'length': '-1'}) + res = req.get_response(self.app) + output = jsonutils.loads(res.body) + self.assertEqual(res.status_int, 200) + self.assertEqual(output, {'output': '0\n1\n2\n3\n4'}) + def test_get_console_output_with_non_integer_length(self): req = self._create_request(length_dict={'length': 'NaN'}) res = req.get_response(self.app) @@ -132,8 +146,8 @@ class ConsoleOutputExtensionTest(test.NoDBTestCase): res = req.get_response(self.app) self.assertEqual(res.status_int, 501) - def test_get_console_output_with_negative_length(self): - req = self._create_request(length_dict={'length': -1}) + def test_get_console_output_with_small_length(self): + req = self._create_request(length_dict={'length': -2}) res = req.get_response(self.app) self.assertEqual(res.status_int, 400) |