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:
parent
a6d7619f11
commit
a1a2869fe0
@ -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'
|
||||
|
@ -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):
|
||||
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:
|
||||
# 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
|
||||
return http.HttpResponse(data.encode('utf-8'), content_type='text/plain')
|
||||
|
||||
|
||||
def vnc(request, instance_id):
|
||||
|
Loading…
Reference in New Issue
Block a user