Skip to content

Commit

Permalink
Fix one last bug in os-console-output extension
Browse files Browse the repository at this point in the history
Actually fixes bug 907083

Change-Id: Ia57d316db0c79d7e78ef3225e77cd95589ac68de
  • Loading branch information
Brian Waldon committed Dec 20, 2011
1 parent 47c4c49 commit b1bd80b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions nova/api/openstack/v2/contrib/console_output.py
Expand Up @@ -54,14 +54,16 @@ def get_console_output(self, input_dict, req, server_id):
raise webob.exc.HTTPBadRequest(_('Malformed request body'))

try:
return self.compute_api.get_console_output(context,
instance,
length)
output = self.compute_api.get_console_output(context,
instance,
length)
except exception.ApiError, e:
raise webob.exc.HTTPBadRequest(explanation=e.message)
except exception.NotAuthorized, e:
raise webob.exc.HTTPUnauthorized()

return {'output': output}

def get_actions(self):
"""Return the actions the extension adds, as required by contract."""
actions = [extensions.ActionExtension("servers", "os-getConsoleOutput",
Expand Down
6 changes: 5 additions & 1 deletion nova/tests/api/openstack/v2/contrib/test_console_output.py
Expand Up @@ -24,7 +24,7 @@


def fake_get_console_output(self, _context, _instance, tail_length):
fixture = [str(i) for i in range(10)]
fixture = [str(i) for i in range(5)]

if tail_length is None:
pass
Expand Down Expand Up @@ -60,7 +60,9 @@ def test_get_text_console_instance_action(self):
req.headers["content-type"] = "application/json"

res = req.get_response(fakes.wsgi_app())
output = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(output, {'output': '0\n1\n2\n3\n4'})

def test_get_console_output_with_tail(self):
body = {'os-getConsoleOutput': {'length': 3}}
Expand All @@ -69,7 +71,9 @@ def test_get_console_output_with_tail(self):
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
res = req.get_response(fakes.wsgi_app())
output = json.loads(res.body)
self.assertEqual(res.status_int, 200)
self.assertEqual(output, {'output': '2\n3\n4'})

def test_get_text_console_no_instance(self):
self.stubs.Set(compute.API, 'get', fake_get_not_found)
Expand Down

0 comments on commit b1bd80b

Please sign in to comment.