Commit 84d78a08 authored by Senthil Kumaran S's avatar Senthil Kumaran S Committed by Neil Williams

LAVA-1229 - read-feedback: failed on DUTs without telnet or ssh

 * Add LxcSession connection that will support disconnect and finalise
 * Disconnect LxcSession connections using an 'exit'
 * Close raw_connection that cannot be killed

Change-Id: I9d7df6e82f19cb91c9cabba2cae8dccd3336d500
parent 1621ea5b
......@@ -168,6 +168,10 @@ class Connection(object):
logger.info("Disconnecting from ssh: %s", reason)
self.sendline('', disconnecting=True)
self.sendline('~.', disconnecting=True)
elif self.name == "LxcSession":
logger.info("Disconnecting from lxc: %s", reason)
self.sendline('', disconnecting=True)
self.sendline('exit', disconnecting=True)
else:
raise LAVABug("'disconnect' not supported for %s" % self.tags)
except ValueError: # protection against file descriptor == -1
......@@ -179,7 +183,7 @@ class Connection(object):
def finalise(self):
logger = logging.getLogger('dispatcher')
if self.raw_connection:
if self.tags:
if self.tags or self.name == "LxcSession":
self.disconnect(reason='Finalise')
if self.raw_connection:
try:
......@@ -188,7 +192,10 @@ class Connection(object):
except OSError:
self.raw_connection.kill(9)
# self.logger.debug("Finalizing child process with PID %d" % self.raw_connection.pid)
self.raw_connection.close()
else:
self.connected = False
self.raw_connection.close(force=True)
self.raw_connection = None
class Protocol(object):
......
......@@ -28,6 +28,23 @@ from lava_dispatcher.shell import ShellCommand, ShellSession
# pylint: disable=too-many-public-methods
class LxcSession(ShellSession):
"""Extends a ShellSession to include the ability to disconnect and finalise
cleanly.
"""
def __init__(self, job, shell_command):
super(LxcSession, self).__init__(job, shell_command)
self.name = "LxcSession"
def finalise(self):
self.disconnect("closing")
super(LxcSession, self).finalise()
def disconnect(self, reason=''):
self.sendline('exit', disconnecting=True)
self.connected = False
class ConnectLxc(Action):
"""
Class to make a lxc shell connection to the container.
......@@ -37,7 +54,7 @@ class ConnectLxc(Action):
self.name = "connect-lxc"
self.summary = "run connection command"
self.description = "connect to the lxc container"
self.session_class = ShellSession
self.session_class = LxcSession
self.shell_class = ShellCommand
def validate(self):
......@@ -69,7 +86,7 @@ class ConnectLxc(Action):
raise JobError("%s command exited %d: %s" % (cmd,
shell.exitstatus,
shell.readlines()))
# ShellSession monitors the pexpect
# LxcSession monitors the pexpect
connection = self.session_class(self.job, shell)
connection.connected = True
connection = super(ConnectLxc, self).run(connection, max_end_time, args)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment