def _execLocallyOrThroughTxs(self, sExec, asArgs, sInput, cMsTimeout):
     """
     Executes the given program locally or through TXS based on the
     current config.
     """
     fRc = False;
     sOutput = None;
     if self.oTxsSession is not None:
         reporter.log('Executing [remote]: %s %s %s' % (sExec, asArgs, sInput));
         reporter.flushall();
         oStdOut = StdInOutBuffer();
         oStdErr = StdInOutBuffer();
         oStdIn = None;
         if sInput is not None:
             oStdIn = StdInOutBuffer(sInput);
         else:
             oStdIn = '/dev/null'; # pylint: disable=R0204
         fRc = self.oTxsSession.syncExecEx(sExec, (sExec,) + asArgs,
                                           oStdIn = oStdIn, oStdOut = oStdOut,
                                           oStdErr = oStdErr, cMsTimeout = cMsTimeout);
         sOutput = oStdOut.getOutput();
         sError = oStdErr.getOutput();
         if fRc is False:
             reporter.log('Exit code [remote]: %s (stdout: %s stderr: %s)' % (fRc, sOutput, sError));
         else:
             reporter.log('Exit code [remote]: %s' % (fRc,));
     else:
         fRc, sOutput, sError = self._sudoExecuteSync([sExec, ] + list(asArgs), sInput);
     return (fRc, sOutput, sError);
    def _sudoExecuteSync(self, asArgs, sInput):
        """
        Executes a sudo child process synchronously.
        Returns a tuple [True, 0] if the process executed successfully
        and returned 0, otherwise [False, rc] is returned.
        """
        reporter.log('Executing [sudo]: %s' % (asArgs, ));
        reporter.flushall();
        fRc = True;
        sOutput = '';
        sError = '';
        try:
            oProcess = utils.sudoProcessPopen(asArgs, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
                                              stderr=subprocess.PIPE, shell = False, close_fds = False);

            sOutput, sError = oProcess.communicate(sInput);
            iExitCode  = oProcess.poll();

            if iExitCode is not 0:
                fRc = False;
        except:
            reporter.errorXcpt();
            fRc = False;
        reporter.log('Exit code [sudo]: %s (%s)' % (fRc, asArgs));
        return (fRc, str(sOutput), str(sError));
 def _uninstallVBoxOnSolaris(self):
     """ Uninstalls VBox on Solaris."""
     reporter.flushall();
     if utils.processCall(['pkginfo', '-q', 'SUNWvbox']) != 0:
         return True;
     sRsp = self._generateAutoResponseOnSolaris();
     fRc, _ = self._sudoExecuteSync(['pkgrm', '-n', '-a', sRsp, 'SUNWvbox']);
     return fRc;
Beispiel #4
0
 def _uninstallVBoxOnSolaris(self):
     """ Uninstalls VBox on Solaris."""
     reporter.flushall()
     if utils.processCall(['pkginfo', '-q', 'SUNWvbox']) != 0:
         return True
     sRsp = self._generateAutoResponseOnSolaris()
     fRc, _ = self._sudoExecuteSync(['pkgrm', '-n', '-a', sRsp, 'SUNWvbox'])
     return fRc
 def _executeSync(self, asArgs):
     """
     Executes a child process synchronously.
     Returns True if the process executed successfully and returned 0,
     otherwise False is returned.
     """
     reporter.log('Executing: %s' % (asArgs, ));
     reporter.flushall();
     try:
         iRc = utils.processCall(asArgs, shell = False, close_fds = False);
     except:
         reporter.errorXcpt();
         return False;
     reporter.log('Exit code: %s (%s)' % (iRc, asArgs));
     return iRc is 0;
 def _executeSync(self, asArgs):
     """
     Executes a child process synchronously.
     Returns True if the process executed successfully and returned 0,
     otherwise False is returned.
     """
     reporter.log('Executing: %s' % (asArgs, ))
     reporter.flushall()
     try:
         iRc = utils.processCall(asArgs, shell=False, close_fds=False)
     except:
         reporter.errorXcpt()
         return False
     reporter.log('Exit code: %s (%s)' % (iRc, asArgs))
     return iRc is 0
 def _sudoExecuteSync(self, asArgs):
     """
     Executes a sudo child process synchronously.
     Returns a tuple [True, 0] if the process executed successfully
     and returned 0, otherwise [False, rc] is returned.
     """
     reporter.log('Executing [sudo]: %s' % (asArgs, ));
     reporter.flushall();
     iRc = 0;
     try:
         iRc = utils.sudoProcessCall(asArgs, shell = False, close_fds = False);
     except:
         reporter.errorXcpt();
         return (False, 0);
     reporter.log('Exit code [sudo]: %s (%s)' % (iRc, asArgs));
     return (iRc is 0, iRc);
Beispiel #8
0
 def _sudoExecuteSync(self, asArgs):
     """
     Executes a sudo child process synchronously.
     Returns a tuple [True, 0] if the process executed successfully
     and returned 0, otherwise [False, rc] is returned.
     """
     reporter.log('Executing [sudo]: %s' % (asArgs, ))
     reporter.flushall()
     iRc = 0
     try:
         iRc = utils.sudoProcessCall(asArgs, shell=False, close_fds=False)
     except:
         reporter.errorXcpt()
         return (False, 0)
     reporter.log('Exit code [sudo]: %s (%s)' % (iRc, asArgs))
     return (iRc is 0, iRc)
    def _executeSync(self, asArgs, fMaySkip = False):
        """
        Executes a child process synchronously.

        Returns True if the process executed successfully and returned 0.
        Returns None if fMaySkip is true and the child exits with RTEXITCODE_SKIPPED.
        Returns False for all other cases.
        """
        reporter.log('Executing: %s' % (asArgs, ));
        reporter.flushall();
        try:
            iRc = utils.processCall(asArgs, shell = False, close_fds = False);
        except:
            reporter.errorXcpt();
            return False;
        reporter.log('Exit code: %s (%s)' % (iRc, asArgs));
        if fMaySkip and iRc == rtexitcode.RTEXITCODE_SKIPPED:
            return None;
        return iRc is 0;
Beispiel #10
0
    def _executeSync(self, asArgs, fMaySkip=False):
        """
        Executes a child process synchronously.

        Returns True if the process executed successfully and returned 0.
        Returns None if fMaySkip is true and the child exits with RTEXITCODE_SKIPPED.
        Returns False for all other cases.
        """
        reporter.log('Executing: %s' % (asArgs, ))
        reporter.flushall()
        try:
            iRc = utils.processCall(asArgs, shell=False, close_fds=False)
        except:
            reporter.errorXcpt()
            return False
        reporter.log('Exit code: %s (%s)' % (iRc, asArgs))
        if fMaySkip and iRc == rtexitcode.RTEXITCODE_SKIPPED:
            return None
        return iRc is 0
Beispiel #11
0
    def _uninstallVBoxOnSolaris(self, fRestartSvcConfigD):
        """ Uninstalls VBox on Solaris."""
        reporter.flushall();
        if utils.processCall(['pkginfo', '-q', 'SUNWvbox']) != 0:
            return True;
        sRsp = self._generateAutoResponseOnSolaris();
        fRc, _ = self._sudoExecuteSync(['pkgrm', '-n', '-a', sRsp, 'SUNWvbox']);

        #
        # Restart the svc.configd as it has a tendency to clog up with time and
        # become  unresponsive.  It will handle SIGHUP by exiting the sigwait()
        # look in the main function and shut down the service nicely (backend_fini).
        # The restarter will then start a new instance of it.
        #
        if fRestartSvcConfigD:
            time.sleep(1); # Give it a chance to flush pkgrm stuff.
            self._sudoExecuteSync(['pkill', '-HUP', 'svc.configd']);
            time.sleep(5); # Spare a few cpu cycles it to shutdown and restart.

        return fRc;
    def _uninstallVBoxOnSolaris(self, fRestartSvcConfigD):
        """ Uninstalls VBox on Solaris."""
        reporter.flushall();
        if utils.processCall(['pkginfo', '-q', 'SUNWvbox']) != 0:
            return True;
        sRsp = self._generateAutoResponseOnSolaris();
        fRc, _ = self._sudoExecuteSync(['pkgrm', '-n', '-a', sRsp, 'SUNWvbox']);

        #
        # Restart the svc.configd as it has a tendency to clog up with time and
        # become  unresponsive.  It will handle SIGHUP by exiting the sigwait()
        # look in the main function and shut down the service nicely (backend_fini).
        # The restarter will then start a new instance of it.
        #
        if fRestartSvcConfigD:
            time.sleep(1); # Give it a chance to flush pkgrm stuff.
            self._sudoExecuteSync(['pkill', '-HUP', 'svc.configd']);
            time.sleep(5); # Spare a few cpu cycles it to shutdown and restart.

        return fRc;
Beispiel #13
0
 def _execLocallyOrThroughTxs(self, sExec, asArgs, sInput, cMsTimeout):
     """
     Executes the given program locally or through TXS based on the
     current config.
     """
     fRc = False
     sOutput = None
     if self.oTxsSession is not None:
         reporter.log('Executing [remote]: %s %s %s' %
                      (sExec, asArgs, sInput))
         reporter.flushall()
         oStdOut = StdInOutBuffer()
         oStdErr = StdInOutBuffer()
         oTestPipe = reporter.FileWrapperTestPipe()
         oStdIn = None
         if sInput is not None:
             oStdIn = StdInOutBuffer(sInput)
         else:
             oStdIn = '/dev/null'
             # pylint: disable=redefined-variable-type
         fRc = self.oTxsSession.syncExecEx(sExec, (sExec, ) + asArgs,
                                           oStdIn=oStdIn,
                                           oStdOut=oStdOut,
                                           oStdErr=oStdErr,
                                           oTestPipe=oTestPipe,
                                           cMsTimeout=cMsTimeout)
         sOutput = oStdOut.getOutput()
         sError = oStdErr.getOutput()
         if fRc is False:
             reporter.log('Exit code [remote]: %s (stdout: %s stderr: %s)' %
                          (fRc, sOutput, sError))
         else:
             reporter.log('Exit code [remote]: %s' % (fRc, ))
     else:
         fRc, sOutput, sError = self._sudoExecuteSync([
             sExec,
         ] + list(asArgs), sInput)
     return (fRc, sOutput, sError)
    def _sudoExecuteSync(self, asArgs, sInput):
        """
        Executes a sudo child process synchronously.
        Returns a tuple [True, 0] if the process executed successfully
        and returned 0, otherwise [False, rc] is returned.
        """
        reporter.log('Executing [sudo]: %s' % (asArgs, ));
        reporter.flushall();
        try:
            oProcess = utils.sudoProcessPopen(asArgs, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
                                              shell = False, close_fds = False);

            sOutput, _ = oProcess.communicate(sInput);
            iExitCode  = oProcess.poll();

            if iExitCode is not 0:
                print(sOutput);
                raise subprocess.CalledProcessError(iExitCode, asArgs);
        except:
            reporter.errorXcpt();
            return (False, None);
        reporter.log('Exit code [sudo]: %s (%s)' % (True, asArgs));
        return (True, str(sOutput));