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
This commit is contained in:
parent
601b55f8f1
commit
8e5577f52f
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user