Esempio n. 1
0
    def __init__(self,
                 cmd,
                 user=None,
                 host="localhost",
                 workdir=os.curdir,
                 timeout=MAX_TIMEOUT):
        """
        :param cmd: Command string
        :param user: User to run command
        :param host: Host to run command
        :param workdir: Working directory in which command runs
        :param timeout: Time out in seconds
        """
        assert _is_valid_timeout(timeout), "Invalid timeout: " + str(timeout)

        self.user = E.get_username() if user is None else user
        self.host = host
        self.timeout = timeout

        if U.is_local(host):
            if "~" in workdir:
                workdir = os.path.expanduser(workdir)
        else:
            cmd = "ssh -o ConnectTimeout=%d %s@%s 'cd %s && %s'" % \
                (MIN_TIMEOUT, user, host, workdir, cmd)
            logging.debug("Remote host. Rewrote cmd to " + cmd)
            workdir = os.curdir

        self.cmd = cmd
        self.workdir = workdir
        self.cmd_str = "%s [%s]" % (cmd, workdir)
        self.proc = None
        self.returncode = None
Esempio n. 2
0
    def __init__(self, cmd, user=None, host="localhost", workdir=os.curdir,
                 timeout=MAX_TIMEOUT):
        """
        :param cmd: Command string
        :param user: User to run command
        :param host: Host to run command
        :param workdir: Working directory in which command runs
        :param timeout: Time out in seconds
        """
        assert _is_valid_timeout(timeout), "Invalid timeout: " + str(timeout)

        self.user = E.get_username() if user is None else user
        self.host = host
        self.timeout = timeout

        if U.is_local(host):
            if "~" in workdir:
                workdir = os.path.expanduser(workdir)
        else:
            cmd = "ssh -o ConnectTimeout=%d %s@%s 'cd %s && %s'" % \
                (MIN_TIMEOUT, user, host, workdir, cmd)
            logging.debug("Remote host. Rewrote cmd to " + cmd)
            workdir = os.curdir

        self.cmd = cmd
        self.workdir = workdir
        self.cmd_str = "%s [%s]" % (cmd, workdir)
        self.proc = None
        self.returncode = None
Esempio n. 3
0
    def __init__(self, name, user=None, altname=None, topdir=G._SERVER_TOPDIR,
                 baseurl=G._SERVER_BASEURL, timeout=G._CONN_TIMEOUT):
        """
        :param name: FQDN or hostname of the server provides yum repos
        :param user: User name on the server to provide yum repos
        :param altname: Alternative hostname (FQDN) for client access
        :param topdir: Top dir or its format string of yum repos to serve RPMs.
        :param baseurl: Base url or its format string of yum repos
        :param timeout: SSH connection timeout to this server
        """
        self.name = name
        self.user = E.get_username() if user is None else user
        self.altname = name if altname is None else altname
        self.timeout = timeout  # It will be ignored if this host is localhost.

        self.shortname = self._mk_shortname(self.name)
        self.shortaltname = self._mk_shortname(self.altname)

        ctx = dict(name=name, user=self.user, altname=self.altname,
                   timeout=timeout, shortname=self.shortname,
                   shortaltname=self.shortaltname)

        # The followings may be format strings.
        self.topdir = _format(topdir, ctx)
        self.baseurl = _format(baseurl, ctx)

        self.is_local = SH.is_local(self.name)
Esempio n. 4
0
    def test_02___init__homedir(self):
        (cmd, user, host, workdir, timeout) = ("true", E.get_username(), "localhost", "~/", 1)
        task = SH.Task(cmd, user, host, workdir, timeout)

        U.typecheck(task, SH.Task)

        self.assertEquals(task.cmd, cmd)
        self.assertEquals(task.user, user)
        self.assertEquals(task.host, host)
        self.assertNotEquals(task.workdir, workdir)
        self.assertEquals(task.workdir, os.path.expanduser(workdir))
        self.assertEquals(task.timeout, timeout)
Esempio n. 5
0
    def test_02___init__homedir(self):
        (cmd, user, host, workdir, timeout) = \
            ("true", E.get_username(), "localhost", "~/", 1)
        task = SH.Task(cmd, user, host, workdir, timeout)

        U.typecheck(task, SH.Task)

        self.assertEquals(task.cmd, cmd)
        self.assertEquals(task.user, user)
        self.assertEquals(task.host, host)
        self.assertNotEquals(task.workdir, workdir)
        self.assertEquals(task.workdir, os.path.expanduser(workdir))
        self.assertEquals(task.timeout, timeout)