Check input for Log length

Check input for Log length to make sure the input is a nonnegative
integer.

Change-Id: Iae3dbf4236f1c7ceb8260540dd4f9086349bc13a
Closes-bug: 1331624
This commit is contained in:
liyingjun 2014-06-24 20:45:27 +08:00
parent a6d7619f11
commit a1a2869fe0
2 changed files with 28 additions and 13 deletions

View File

@ -983,6 +983,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):