Example #1
0
 def vm_execwait(self, cmd, env=None):
     """As above, a function to encapsulate command execution via Popen.
     vm_execwait executes the given cmd list, waits for the process to finish,
     and returns the return code of the process. STDOUT and STDERR are stored
     in given parameters.
     Parameters:
     (cmd as above)
     Returns:
     ret - The return value of the executed command
     out - The STDOUT of the executed command
     err - The STDERR of the executed command
     The return of this function is a 3-tuple
     """
     out = ""
     err = ""
     try:
         sp = Popen(cmd, shell=False,
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
         if not utilities.check_popen_timeout(sp):
             (out, err) = sp.communicate(input=None)
         else:
             log.warning("Process %s timed out! cmd was %" % (sp.pid, " ".join(cmd)))
         return (sp.returncode, out, err)
     except OSError, e:
         try:
             log.error("Problem running %s, got errno %d \"%s\"" % (string.join(cmd, " "), e.errno, e.strerror))
         except:
             log.error("Problem running command, OSError.")
         return (-1, "", "")
Example #2
0
 def vm_execwait(self, cmd, env=None):
     """As above, a function to encapsulate command execution via Popen.
     vm_execwait executes the given cmd list, waits for the process to finish,
     and returns the return code of the process. STDOUT and STDERR are stored
     in given parameters.
     Parameters:
     (cmd as above)
     Returns:
         ret   - The return value of the executed command
         out   - The STDOUT of the executed command
         err   - The STDERR of the executed command
     The return of this function is a 3-tuple
     """
     out = ""
     err = ""
     try:
         sp = Popen(cmd,
                    executable=config.workspace_path,
                    shell=False,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    env=env)
         if not utilities.check_popen_timeout(sp):
             (out, err) = sp.communicate(input=None)
         else:
             log.warning("Process %s timed out! cmd was %" %
                         (sp.pid, " ".join(cmd)))
         return (sp.returncode, out, err)
     except OSError, e:
         log.error("Problem running %s, got errno %d \"%s\"" %
                   (string.join(cmd, " "), e.errno, e.strerror))
         return (-1, "", "")
Example #3
0
    def vm_exec_silent(self, cmd, env=None):
        """
        vm_exec_silent executes a given command list, and discards the output

        parameter: cmd -- a list of a command and arguments

        returns: the return value of the command that was run
        """
        out = ""
        err = ""
        try:
            sp = Popen(cmd,
                       executable=config.workspace_path,
                       shell=False,
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE,
                       env=env)
            if not utilities.check_popen_timeout(sp):
                (out, err) = sp.communicate(input=None)
            else:
                log.warning("Process %s timed out! cmd was %" %
                            (sp.pid, " ".join(cmd)))
            return sp.returncode
        except OSError, e:
            log.error("Problem running %s, got errno %d \"%s\"" %
                      (string.join(cmd, " "), e.errno, e.strerror))
            return -1
Example #4
0
    def vm_exec_silent(self, cmd, env=None):
        """
        vm_exec_silent executes a given command list, and discards the output

        parameter: cmd -- a list of a command and arguments

        returns: the return value of the command that was run
        """
        out = ""
        err = ""
        try:
            sp = Popen(cmd, executable=config.workspace_path, shell=False,
                       stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
            if not utilities.check_popen_timeout(sp):
                (out, err) = sp.communicate(input=None)
            else:
                log.warning("Process %s timed out! cmd was %" % (sp.pid, " ".join(cmd)))
            return sp.returncode
        except OSError, e:
            log.error("Problem running %s, got errno %d \"%s\"" % (string.join(cmd, " "), e.errno, e.strerror))
            return -1