コード例 #1
0
    def _run(self, command, timeout, ignore_status, stdout, stderr,
             connect_timeout, env, options, stdin, args):
        """Helper function for run()."""
        ssh_cmd = self.ssh_command(connect_timeout, options)
        if not env.strip():
            env = ""
        else:
            env = "export %s;" % env
        for arg in args:
            command += ' "%s"' % utils.sh_escape(arg)
        full_cmd = '%s "%s %s"' % (ssh_cmd, env, utils.sh_escape(command))
        result = utils.run(full_cmd, timeout, True, stdout, stderr,
                           verbose=False, stdin=stdin,
                           stderr_is_expected=ignore_status)

        # The error messages will show up in band (indistinguishable
        # from stuff sent through the SSH connection), so we have the
        # remote computer echo the message "Connected." before running
        # any command.  Since the following 2 errors have to do with
        # connecting, it's safe to do these checks.
        if result.exit_status == 255:
            if re.search(r'^ssh: connect to host .* port .*: '
                         r'Connection timed out\r$', result.stderr):
                raise error.AutoservSSHTimeout("ssh timed out", result)
            if "Permission denied." in result.stderr:
                msg = "ssh permission denied"
                raise error.AutoservSshPermissionDeniedError(msg, result)

        if not ignore_status and result.exit_status > 0:
            raise error.AutoservRunError("command execution error", result)

        return result
コード例 #2
0
 def _init_transport(self):
     for path, key in self.keys.iteritems():
         try:
             logging.debug("Connecting with %s", path)
             transport = self._connect_transport(key)
             transport.set_keepalive(self.KEEPALIVE_TIMEOUT_SECONDS)
             self.transport = transport
             self.pid = os.getpid()
             return
         except paramiko.AuthenticationException:
             logging.debug("Authentication failure")
     else:
         raise error.AutoservSshPermissionDeniedError(
             "Permission denied using all keys available to ParamikoHost",
             utils.CmdResult())