Merge "Check input for Log length"

This commit is contained in:
Jenkins 2014-12-18 09:51:59 +00:00 committed by Gerrit Code Review
commit e4a4eec40d
2 changed files with 28 additions and 13 deletions

View File

@ -986,6 +986,20 @@ class InstanceTests(helpers.TestCase):
self.assertContains(res, "Unable to get log for")
def test_instance_log_invalid_input(self):
server = self.servers.first()
url = reverse('horizon:project:instances:console',
args=[server.id])
tg = tabs.InstanceDetailTabs(self.request, instance=server)
for length in ["-5", "x"]:
qs = "?%s=%s&length=%s" % (tg.param_name,
tg.get_tab("log").get_id(),
length)
res = self.client.get(url + qs)
self.assertContains(res, "Unable to get log for")
def test_instance_vnc(self):
server = self.servers.first()
CONSOLE_OUTPUT = '/vncserver'

View File

@ -28,6 +28,7 @@ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from horizon import tables
from horizon import tabs
from horizon.utils import memoized
@ -142,19 +143,19 @@ class LaunchInstanceView(workflows.WorkflowView):
def console(request, instance_id):
try:
# TODO(jakedahn): clean this up once the api supports tailing.
tail = request.GET.get('length', None)
data = api.nova.server_console_output(request,
instance_id,
tail_length=tail)
except Exception:
data = _('Unable to get log for instance "%s".') % instance_id
exceptions.handle(request, ignore=True)
response = http.HttpResponse(content_type='text/plain')
response.write(data)
response.flush()
return response
data = _('Unable to get log for instance "%s".') % instance_id
tail = request.GET.get('length')
if tail and not tail.isdigit():
msg = _('Log length must be a nonnegative integer.')
messages.warning(request, msg)
else:
try:
data = api.nova.server_console_output(request,
instance_id,
tail_length=tail)
except Exception:
exceptions.handle(request, ignore=True)
return http.HttpResponse(data.encode('utf-8'), content_type='text/plain')
def vnc(request, instance_id):