コード例 #1
0
 def runner(self):
     if self.__runner__ is None:
         # device = self.device
         spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
         # FIXME: the prompts should not be needed here, only kvm uses these. Remove.
         # prompt_str = parameters['prompts']
         prompt_str_includes_rc = True  # FIXME - parameters['deployment_data']['TESTER_PS1_INCLUDES_RC']?
         #            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
         # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
         self.__runner__ = CommandRunner(spawned_shell, self.prompt_str,
                                         prompt_str_includes_rc)
     return self.__runner__
コード例 #2
0
 def test_connection(self):
     """
     Yields the actual connection which can be used to interact inside this shell.
     """
     if self.__runner__ is None:
         spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
         # prompt_str = parameters['prompts']
         prompt_str_includes_rc = True  # FIXME - do we need this?
         #            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
         # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
         self.__runner__ = CommandRunner(spawned_shell, self.prompt_str,
                                         prompt_str_includes_rc)
     yield self.__runner__.get_connection()
コード例 #3
0
ファイル: shell.py プロジェクト: x-deepin/lava-dispatcher
    def runner(self):
        if self.__runner__ is None:
            # device = self.device
            spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
            # FIXME: the prompts should not be needed here, only kvm uses these. Remove.
            # prompt_str = parameters['prompts']
            prompt_str_includes_rc = True  # FIXME - parameters['deployment_data']['TESTER_PS1_INCLUDES_RC']?
#            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
            # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
            self.__runner__ = CommandRunner(spawned_shell, self.prompt_str, prompt_str_includes_rc)
        return self.__runner__
コード例 #4
0
ファイル: shell.py プロジェクト: BayLibre/lava-dispatcher
 def test_connection(self):
     """
     Yields the actual connection which can be used to interact inside this shell.
     """
     if self.__runner__ is None:
         spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
         # prompt_str = parameters['prompts']
         prompt_str_includes_rc = True  # FIXME - do we need this?
         #            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
         # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
         self.__runner__ = CommandRunner(spawned_shell, self.prompt_str, prompt_str_includes_rc)
     yield self.__runner__.get_connection()
コード例 #5
0
ファイル: shell.py プロジェクト: x-deepin/lava-dispatcher
class ShellSession(Connection):

    def __init__(self, job, shell_command):
        """
        The connection takes over result handling for the TestAction, adding individual results to the
        logs every time a test_case is matched, so that if a test definition falls over or times out,
        the results so-far will be retained.
        Each result generates an item in the data context with an ID. This ID can be used later to
        look up each individial testcase result.
        TODO: ensure the stdout for each testcase result is captured and tagged with this ID.

        A ShellSession uses a CommandRunner. Other connections would need to add their own
        support.
        """
        super(ShellSession, self).__init__(job, shell_command)
        self.__runner__ = None
        self.name = "ShellSession"
        self.data = job.context
        # FIXME: rename __prompt_str__ to indicate it can be a list or str
        self.__prompt_str__ = None
        self.spawn = shell_command
        self.timeout = shell_command.lava_timeout

    def disconnect(self, reason):
        # FIXME
        pass

    # FIXME: rename prompt_str to indicate it can be a list or str
    @property
    def prompt_str(self):
        return self.__prompt_str__

    @prompt_str.setter
    def prompt_str(self, string):
        # FIXME: Debug logging should show whenever this property is changed
        self.__prompt_str__ = string
        if self.__runner__:
            self.__runner__.change_prompt(self.__prompt_str__)

    @property
    def runner(self):
        if self.__runner__ is None:
            # device = self.device
            spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
            # FIXME: the prompts should not be needed here, only kvm uses these. Remove.
            # prompt_str = parameters['prompts']
            prompt_str_includes_rc = True  # FIXME - parameters['deployment_data']['TESTER_PS1_INCLUDES_RC']?
#            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
            # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
            self.__runner__ = CommandRunner(spawned_shell, self.prompt_str, prompt_str_includes_rc)
        return self.__runner__

    def run_command(self, command):
        self.runner.run(command)

    @contextlib.contextmanager
    def test_connection(self):
        """
        Yields the actual connection which can be used to interact inside this shell.
        """
        if self.__runner__ is None:
            spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
            # prompt_str = parameters['prompts']
            prompt_str_includes_rc = True  # FIXME - do we need this?
#            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
            # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
            self.__runner__ = CommandRunner(spawned_shell, self.prompt_str,
                                            prompt_str_includes_rc)
        yield self.__runner__.get_connection()

    def wait(self):
        if not self.prompt_str:
            self.prompt_str = self.check_char
        try:
            self.runner.wait_for_prompt(self.timeout.duration, self.check_char)
        except pexpect.TIMEOUT:
            raise JobError("wait for prompt timed out")
コード例 #6
0
class ShellSession(Connection):
    def __init__(self, job, shell_command):
        """
        The connection takes over result handling for the TestAction, adding individual results to the
        logs every time a test_case is matched, so that if a test definition falls over or times out,
        the results so-far will be retained.
        Each result generates an item in the data context with an ID. This ID can be used later to
        look up each individial testcase result.
        TODO: ensure the stdout for each testcase result is captured and tagged with this ID.

        A ShellSession uses a CommandRunner. Other connections would need to add their own
        support.
        """
        super(ShellSession, self).__init__(job, shell_command)
        self.__runner__ = None
        self.name = "ShellSession"
        self.data = job.context
        # FIXME: rename __prompt_str__ to indicate it can be a list or str
        self.__prompt_str__ = None
        self.spawn = shell_command
        self.timeout = shell_command.lava_timeout

    def disconnect(self, reason):
        # FIXME
        pass

    # FIXME: rename prompt_str to indicate it can be a list or str
    @property
    def prompt_str(self):
        return self.__prompt_str__

    @prompt_str.setter
    def prompt_str(self, string):
        # FIXME: Debug logging should show whenever this property is changed
        self.__prompt_str__ = string
        if self.__runner__:
            self.__runner__.change_prompt(self.__prompt_str__)

    @property
    def runner(self):
        if self.__runner__ is None:
            # device = self.device
            spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
            # FIXME: the prompts should not be needed here, only kvm uses these. Remove.
            # prompt_str = parameters['prompts']
            prompt_str_includes_rc = True  # FIXME - parameters['deployment_data']['TESTER_PS1_INCLUDES_RC']?
            #            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
            # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
            self.__runner__ = CommandRunner(spawned_shell, self.prompt_str,
                                            prompt_str_includes_rc)
        return self.__runner__

    def run_command(self, command):
        self.runner.run(command)

    @contextlib.contextmanager
    def test_connection(self):
        """
        Yields the actual connection which can be used to interact inside this shell.
        """
        if self.__runner__ is None:
            spawned_shell = self.raw_connection  # ShellCommand(pexpect.spawn)
            # prompt_str = parameters['prompts']
            prompt_str_includes_rc = True  # FIXME - do we need this?
            #            prompt_str_includes_rc = device.config.tester_ps1_includes_rc
            # The Connection for a CommandRunner in the pipeline needs to be a ShellCommand, not logging_spawn
            self.__runner__ = CommandRunner(spawned_shell, self.prompt_str,
                                            prompt_str_includes_rc)
        yield self.__runner__.get_connection()

    def wait(self):
        if not self.prompt_str:
            self.prompt_str = self.check_char
        try:
            return self.runner.wait_for_prompt(self.timeout.duration,
                                               self.check_char)
        except pexpect.TIMEOUT:
            raise JobError("wait for prompt timed out")