コード例 #1
0
    def untar(self, packagePath, untarPath, nicelevel):
        ''' do real untar '''
        cmd = ['tar', '-C', untarPath, '-x', '-f', packagePath]
        # timeout 60 minute
        execThread = ExecThread(None, cmd, None, self.getUuid())
        execThread.setTimeout(3600)
        execThread.run()

        status = execThread.getStatus()
        if (status['error'] != None):
            msg = 'untar cmd (%s) failed (%s - %s)' % (' '.join(cmd), status['error'], status['errorMsg'])
            LOG.error(msg)
            raise AgentException(Errors.PACKAGE_UNTAR_FAILURE, msg)
コード例 #2
0
ファイル: monitor.py プロジェクト: anzarafaq/cronusagent
    def _executeCommand(self, cmd, timeout = 2, service = None):
        ''' execute command '''
        execThread = ExecThread(None, cmd)
        execThread.setLogLevel('debug')
        execThread.run()

        # now wait for the threads to complete and update progress
        status = execThread.getStatus()
        if (status['error'] != None):
            return None
#             raise AgentException(status['error'], status['errorMsg'])

        return status['result']
コード例 #3
0
    def untar(self, packagePath, untarPath, nicelevel):
        ''' do real untar '''
        cmd = ['tar', '-C', untarPath, '-x', '-f', packagePath]
        # timeout 60 minute
        execThread = ExecThread(None, cmd, None)
        execThread.setTimeout(3600)
        execThread.run()

        status = execThread.getStatus()
        if (status['error'] != None):
            msg = 'untar cmd (%s) failed (%s - %s)' % (' '.join(cmd), status['error'], status['errorMsg'])
            LOG.error(msg)
            raise AgentException(Errors.PACKAGE_UNTAR_FAILURE, msg)
コード例 #4
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def _test_progress(self):
        cmd = os.path.join(self.scriptDir, 'test.sh')
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(30)
        testExec.setProgressTimeout(10)

        testExec.start()

        # make sure the script is running
        tm = time.time()
        while (testExec.getCmdPid() == None and tm + 10 > time.time()):
            time.sleep(0.1)

        assert testExec.getCmdPid() != None
        print '****** cmd pid = %d' % testExec.getCmdPid()

        progress = 10
        # check that we increment the progress to 100
        tm = time.time()
        while (progress < 101 and tm + 5 > time.time()):
            LOG.debug('progress == %s: %s' %
                      (str(testExec.getStatus()['progress']), str(progress)))
            if (int(testExec.getStatus()['progress']) == int(progress)):
                LOG.debug('sending sigint')
                try:
                    #The script itself traps the signal in increments its progress.
                    os.kill(testExec.getCmdPid(), signal.SIGINT)
                except OSError:
                    pass

                progress += 10
            time.sleep(0.05)

        self.printStatus(testExec.getStatus())
        if (not os.name == 'nt'):
            assert int(testExec.getStatus()['progress']) == 100
コード例 #5
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def test_nonending_script(self):
        cmd = os.path.join(self.scriptDir, 'test.sh')
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(1)
        testExec.setProgressTimeout(10)
        testExec.start()

        # make sure the script is running
        tm = time.time()
        while (testExec.getCmdPid() == None and tm + 15 > time.time()):
            pass
        assert testExec.getCmdPid() != None

        tm = time.time()
        while (int(testExec.getStatus()['httpStatus']) != 500 and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 500
        assert testExec.getStatus()['error'] == Errors.AGENT_THREAD_TIMEDOUT
コード例 #6
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def _test_progress(self):
        cmd = os.path.join(self.scriptDir, 'test.sh')
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(30)
        testExec.setProgressTimeout(10)

        testExec.start()

        # make sure the script is running
        tm = time.time()
        while (testExec.getCmdPid() == None and tm + 10 > time.time()):
            time.sleep(0.1)

        assert testExec.getCmdPid() != None
        print '****** cmd pid = %d' % testExec.getCmdPid()

        progress = 10
        # check that we increment the progress to 100
        tm = time.time()
        while (progress < 101 and tm + 5 > time.time()):
            LOG.debug('progress == %s: %s' % (str(testExec.getStatus()['progress']), str(progress)))
            if (int(testExec.getStatus()['progress']) == int(progress)):
                LOG.debug('sending sigint')
                try:
                    #The script itself traps the signal in increments its progress.
                    os.kill(testExec.getCmdPid(), signal.SIGINT)
                except OSError:
                    pass

                progress += 10
            time.sleep(0.05)

        self.printStatus(testExec.getStatus())
        if (not os.name == 'nt'):
            assert int(testExec.getStatus()['progress']) == 100
コード例 #7
0
    def __stopProcesses(self):
        """ stop all processes that run as app_user_account
            refers to http://stackoverflow.com/questions/4669754/python-kill-all-processes-owned-by-user
        """
        self._updateStatus(progress=10)
        uname = pylons.config['app_user_account']
        import pwd
        uid = pwd.getpwnam(uname).pw_uid
        pids = filter(lambda pid: pid.isdigit(), os.listdir('/proc'))
        execThreads = []

        # test if PID is owned by user
        for pid in pids:
            # check if PID still exist
            if not os.path.exists(os.path.join('/proc', pid)):
                LOG.debug("pid doesn't exist any more: %s" % pid)
                continue

            puid = os.stat(os.path.join('/proc', pid)).st_uid
            if puid == uid:
                cmd = utils.sudoCmd(['kill', '-9', pid], uname)
                execThread = ExecThread(self._threadMgr, cmd)
                execThread.setTimeout(self.__killTimeout)
                execThread.start()
                execThreads.append(execThread)

        while (True):
            self._checkStop()

            running = False
            for execThread in execThreads:
                status = execThread.getStatus()
                if (status['error'] != None):
                    raise AgentException(status['error'], status['errorMsg'])

                if (execThread.isAlive()):
                    LOG.debug("process is still alive: %s" %
                              execThread.getCmd())
                    running = True

            if (not running):
                LOG.debug(
                    "stop processes finished: %s" %
                    [execThread.getCmd()[-1] for execThread in execThreads])
                break

            time.sleep(0.1)

        self._updateStatus(progress=50)
コード例 #8
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def test_nonending_script(self):
        cmd = os.path.join(self.scriptDir, 'test.sh')
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(1)
        testExec.setProgressTimeout(10)
        testExec.start()

        # make sure the script is running
        tm = time.time()
        while (testExec.getCmdPid() == None and tm + 15 > time.time()):
            pass
        assert testExec.getCmdPid() != None

        tm = time.time()
        while (int(testExec.getStatus()['httpStatus']) != 500
               and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 500
        assert testExec.getStatus()['error'] == Errors.AGENT_THREAD_TIMEDOUT
コード例 #9
0
    def __stopProcesses(self):
        """ stop all processes that run as app_user_account
            refers to http://stackoverflow.com/questions/4669754/python-kill-all-processes-owned-by-user
        """
        self._updateStatus(progress = 10)
        uname = configutil.getAppUser()
        uid, _ = utils.getUidGid(uname)
        pids = filter(lambda pid: pid.isdigit(), os.listdir('/proc'))
        execThreads = []

        # test if PID is owned by user
        for pid in pids:
            # check if PID still exist
            if not os.path.exists(os.path.join('/proc', pid)):
                LOG.debug("pid doesn't exist any more: %s" % pid)
                continue

            puid = os.stat(os.path.join('/proc', pid)).st_uid
            if puid == uid:
                cmd = utils.sudoCmd(['kill', '-9', pid], uname)
                execThread = ExecThread(self._threadMgr, cmd)
                execThread.setTimeout(self.__killTimeout)
                execThread.start()
                execThreads.append(execThread)
                self._addChildExeThreadId(execThread.getUuid())

        while(True):
            self._checkStop()

            running = False
            for execThread in execThreads:
                status = execThread.getStatus()
                if (status['error'] != None):
                    raise AgentException(status['error'], status['errorMsg'])

                if (execThread.isAlive()):
                    LOG.debug("process is still alive: %s" % execThread.getCmd())
                    running = True

            if (not running):
                LOG.debug("stop processes finished: %s" % [execThread.getCmd()[-1] for execThread in execThreads])
                break

            time.sleep(0.1)

        self._updateStatus(progress = 50)
コード例 #10
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def test_good_code_invalid_msg_script(self):
        cmd = [os.path.join(self.scriptDir, 'test2.sh'), 'good_code_invalid_msg']
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(10)
        testExec.setProgressTimeout(10)
        testExec.start()

        tm = time.time()
        while (int(testExec.getStatus()['progress']) != 100 and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 200
        assert testExec.getStatus()['result'] == None
        assert testExec.getStatus()['error'] == None
        assert testExec.getStatus()['errorMsg'] == None
コード例 #11
0
ファイル: test_exec.py プロジェクト: cronuspaas/cronusagent
    def test_random_script(self):
        cmd = ['ls', '/tmp']
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(10)
        testExec.setProgressTimeout(10)
        testExec.start()

        tm = time.time()
        while (int(testExec.getStatus()['progress']) != 100 and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 200
        assert testExec.getStatus()['result'] == None
        assert testExec.getStatus()['error'] == None
        assert testExec.getStatus()['errorMsg'] == None
コード例 #12
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def test_good_code_no_msg_script(self):
        cmd = [os.path.join(self.scriptDir, 'test2.sh'), 'good_code_no_msg']
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(10)
        testExec.setProgressTimeout(10)
        testExec.start()

        tm = time.time()
        while (int(testExec.getStatus()['progress']) != 100
               and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 200
        assert testExec.getStatus()['result'] == None
        assert testExec.getStatus()['error'] == None
        assert testExec.getStatus()['errorMsg'] == None
コード例 #13
0
ファイル: test_exec.py プロジェクト: anzarafaq/cronusagent
    def test_random_script(self):
        if (os.name == 'nt'):
            #ls.exe as a part of cygwin
            cmd = ['ls.exe', '/tmp']
        else:
            cmd = ['ls', '/tmp']
        LOG.debug('cmd = %s' % cmd)

        testExec = ExecThread(self.threadMgr, cmd)
        testExec.setTimeout(10)
        testExec.setProgressTimeout(10)
        testExec.start()

        tm = time.time()
        while (int(testExec.getStatus()['progress']) != 100
               and tm + 20 > time.time()):
            pass

        self.printStatus(testExec.getStatus())

        assert int(testExec.getStatus()['httpStatus']) == 200
        assert testExec.getStatus()['result'] == None
        assert testExec.getStatus()['error'] == None
        assert testExec.getStatus()['errorMsg'] == None