[dts] [PATCH 4/6] framework/ssh: Add verify ability for command execution

Liu, Yong yong.liu at intel.com
Wed Jan 14 02:24:10 CET 2015


Thanks for this idea. DTS can check return status as it default behavior. And when command return error, the output is still valuable.
My suggestion is that function send_expect should return both output message and command executed return value.

> -----Original Message-----
> From: Qiu, Michael
> Sent: Tuesday, January 13, 2015 9:42 PM
> To: dts at dpdk.org
> Cc: Liu, Yong; Qiu, Michael
> Subject: [PATCH 4/6] framework/ssh: Add verify ability for command
> execution
> 
> ssh command exection never try to verify the failure or success,
> 
> It should be very dangerous when execute command both in dut and
> tester machine without check the status, maybe unexpected error
> happens.
> 
> This patch add this ability to verify the status.
> 
> Signed-off-by: Michael Qiu <michael.qiu at intel.com>
> ---
>  framework/ssh_connection.py |  4 ++--
>  framework/ssh_pexpect.py    | 13 ++++++++++++-
>  2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/framework/ssh_connection.py b/framework/ssh_connection.py
> index 4306162..1ff79b9 100644
> --- a/framework/ssh_connection.py
> +++ b/framework/ssh_connection.py
> @@ -49,9 +49,9 @@ class SSHConnection(object):
>          self.logger.config_execution(self.name)
>          self.session.init_log(logger, self.name)
> 
> -    def send_expect(self, cmds, expected, timeout=15):
> +    def send_expect(self, cmds, expected, timeout=15, verify=False):
>          self.logger.info(cmds)
> -        out = self.session.send_expect(cmds, expected, timeout)
> +        out = self.session.send_expect(cmds, expected, timeout, verify=False)
>          self.logger.debug(out)
>          return out
> 
> diff --git a/framework/ssh_pexpect.py b/framework/ssh_pexpect.py
> index 9c353e7..2fad899 100644
> --- a/framework/ssh_pexpect.py
> +++ b/framework/ssh_pexpect.py
> @@ -29,12 +29,23 @@ class SSHPexpect(object):
>          self.logger.config_execution(name)
>          self.logger.info("ssh %s@%s" % (self.username, self.host))
> 
> -    def send_expect(self, command, expected, timeout=15):
> +    def send_expect_base(self, command, expected, timeout=15):
>          self.session.PROMPT = expected
>          self.__sendline(command)
>          self.__prompt(command, timeout)
>          return self.get_output_before()
> 
> +    def send_expect(self, command, expected, timeout=15, verify=False):
> +        ret = self.send_expect_base(command, expected, timeout)
> +        if verify:
> +            ret_status = self.send_expect_base("echo $?", expected)
> +            if not int(ret_status):
> +                return ret
> +            else:
> +                return -1
> +        else:
> +            return ret
> +
>      def __prompt(self, command, timeout):
>          if not self.session.prompt(timeout):
>              raise TimeoutException(command, self.get_output_all())
> --
> 1.9.3



More information about the dts mailing list