Fix traceback when running nova-console

Recently utils.last_bytes has moved to libvirt/utils.py in nova.
(2341a41eaee5152e95379e5ed38012270af82ef5). Duplicate the function
that was in nova/utils.py.

Also includes a fix for nova-lxd's gate:
Update test-requirements with wsgi-intercept

Closes-Bug: #1707096

Change-Id: Ie77c8e67e29e8a01bbf58ab9277c5110cd7c112e
Signed-off-by: Chuck Short <charles.short@ericsson.com>>
This commit is contained in:
Chuck Short 2017-07-27 21:49:31 -04:00 committed by Chris MacNaughton
parent 78b6c14f2c
commit af15cd09d4
3 changed files with 28 additions and 2 deletions

View File

@ -36,7 +36,7 @@ r="$r|(?:tempest\.scenario\.test_minimum_basic\.TestMinimumBasicScenario\.test_m
# XXX: zulcss (18 Oct 2016) nova-lxd does not support booting from ebs volumes
r="$r|(?:tempest\.scenario\.test_volume_boot_pattern.*)"
r="$r|(?:tempest\.api\.compute\.servers\.test_create_server\.ServersTestBootFromVolume)"
# XXX: zulcss (18 Oct 2016) tempest test only passes when there is more than 10 lines in the
# console output, and cirros LXD consoles have only a single line of output
r="$r|(?:tempest\.api\.compute\.servers\.test_server_actions\.ServerActionsTestJSON\.test_get_console_output_with_unlimited_size)"

View File

@ -15,6 +15,7 @@
from __future__ import absolute_import
import errno
import io
import json
import os
@ -95,6 +96,30 @@ BASE_DIR = os.path.join(
CONF.instances_path, CONF.image_cache_subdirectory_name)
def _last_bytes(file_like_object, num):
"""Return num bytes from the end of the file, and remaning byte count.
:param file_like_object: The file to read
:param num: The number of bytes to return
:returns: (data, remaining)
"""
try:
file_like_object.seek(-num, os.SEEK_END)
except IOError as e:
# seek() fails with EINVAL when trying to go before the start of
# the file. It means that num is larger than the file size, so
# just go to the start.
if e.errno == errno.EINVAL:
file_like_object.seek(0, os.SEEK_SET)
else:
raise
remaining = file_like_object.tell()
return (file_like_object.read(), remaining)
def _neutron_failed_callback(event_name, instance):
LOG.error('Neutron Reported failure on event '
'%(event)s for instance %(uuid)s',
@ -591,7 +616,7 @@ class LXDDriver(driver.ComputeDriver):
utils.execute(
'chmod', '755', instance_attrs.container_path, run_as_root=True)
with open(console_path, 'rb') as f:
log_data, _ = utils.last_bytes(f, MAX_CONSOLE_BYTES)
log_data, _ = _last_bytes(f, MAX_CONSOLE_BYTES)
return log_data
def get_host_ip_addr(self):

View File

@ -15,3 +15,4 @@ testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT
os-testr>=0.8.0 # Apache-2.0
nosexcover # BSD
wsgi-intercept>=1.4.1 # MIT License