示例#1
0
    def _action(self, session, m_jobs):
        ret = True
        for m_job in m_jobs: # job(N) execute
            job_update(session, m_job, ACTION_STATUS['RUN']) # Job UPDATE
            proc = None
            proc_info = []
            try:
                cmd = m_job.action_command
                self.logger.info('action command running!!- jobgroup_id=%d : cmd=%s'
                                  % (m_job.id, cmd))

                lcmd = split_shell_command(cmd)
                if self.chk_whitelist(lcmd[0]):
                    try:
                        (proc, proc_info) = popen(cmd=lcmd,
                                                  timeout=self._cf['job.popen.timeout'],
                                                  waittime=self._cf['job.popen.waittime'],
                                                  lang=self._cf['job.popen.env.lang'],
                                                  limit=self._cf['job.popen.output.limit'],
                                                  job_id=m_job.id,
                                                  )

                        self.logger.debug('Of commands executed stdout=%s' % proc_info['stdout'])
                        self.logger.debug('Of commands executed stderr=%s' % proc_info['stderr'])

                        if self._cf['job.popen.output.limit'] < len(proc_info['stdout']):
                            self.logger.info("There was a limit beyond stdout output. Information-processing is truncated beyond the limit. - limit=%d, stdout=%d" \
                                             % (self._cf['job.popen.output.limit'], len(proc_info['stdout'])))

                        if self._cf['job.popen.output.limit'] < len(proc_info['stderr']):
                            self.logger.info("There was a limit beyond stderr output. Information-processing is truncated beyond the limit. - limit=%d, stderr=%d" \
                                             % (self._cf['job.popen.output.limit'], len(proc_info['stderr'])))
                            

                    except OSError, oe:
                        self.logger.info('action command system failed!! job_id=%d : cmd=%s'
                                          % (m_job.id, cmd))
                        raise oe

                    job_result_action(session, m_job, proc_info) # Job result UPDATE

                    if proc_info['r_code'] == 0: # Normal end
                        self.logger.info('action command was successful!! job_id=%d : cmd=%s'
                                          % (m_job.id, cmd))
                        job_update(session, m_job, ACTION_STATUS['OK']) # Job UPDATE
                    else: # Abnormal termination
                        self.logger.info('action command failed!! job_id=%d : cmd=%s'
                                          % (m_job.id, cmd))
                        job_update(session, m_job, ACTION_STATUS['NG']) # Job UPDATE
                        ret = False
                        break
                else:
                    # whitelist error
                    self.logger.info('Tried to run the action command that is not registered in the whitelist. job_id=%d : cmd=%s'
                                      % (m_job.id, cmd))
                    m_job.action_stderr = "Command is not registered to run the whitelist."
                    job_update(session, m_job, ACTION_STATUS['WHITELIST']) # Job UPDATE
                    ret = False
                    break
示例#2
0
    def _rollback(self, session, m_jobs):
        for m_job in m_jobs:

            if m_job.is_rollback() and m_job.status in (ACTION_STATUS['RUN'],
                                                        ACTION_STATUS['OK'],
                                                        ACTION_STATUS['NG']):
                # rollback exec
                proc = None
                proc_info = []
                try:
                    cmd = m_job.rollback_command
                    self.logger.info('rollback command running!!- jobgroup_id=%d : cmd=%s'
                                      % (m_job.id, cmd))

                    lcmd = split_shell_command(cmd)
                    
                    if self.chk_whitelist(lcmd[0]):
                        try:
                            (proc, proc_info) = popen(cmd=lcmd,
                                                      timeout=self._cf['job.popen.timeout'],
                                                      waittime=self._cf['job.popen.waittime'],
                                                      lang=self._cf['job.popen.env.lang'],
                                                      limit=self._cf['job.popen.output.limit'],
                                                      )

                            self.logger.debug('Of commands executed stdout=%s' % proc_info['stdout'])
                            self.logger.debug('Of commands executed stderr=%s' % proc_info['stderr'])

                        except OSError, oe:
                            self.logger.info('rollback command system failed!! job_id=%d : cmd=%s'
                                          % (m_job.id, cmd))
                            raise oe
                    
                        job_result_rollback(session, m_job, proc_info) # Job result UPDATE
                        if proc_info['r_code'] == 0: # Normal end
                            self.logger.info('rollback command was successful!! job_id=%d : cmd=%s'
                                              % (m_job.id, cmd))
                            job_update(session, m_job, ROLLBACK_STATUS['OK']) # Job UPDATE
                        else: # Abnormal termination
                            self.logger.info('rollback command failed!! job_id=%d : cmd=%s'
                                              % (m_job.id, cmd))
                            job_update(session, m_job, ROLLBACK_STATUS['NG']) # Job UPDATE

                    else:
                        # whitelist error
                        self.logger.info('Tried to run the rollback command that is not registered in the whitelist. job_id=%d : cmd=%s'
                                          % (m_job.id, cmd))
                        m_job.rollback_stderr = "Command is not registered to run the whitelist."
                        job_update(session, m_job, ROLLBACK_STATUS['WHITELIST']) # Job UPDATE

                finally:
示例#3
0
    def _finish(self):
        proc = None
        proc_info = []
        cmd = self._m_jg.finish_command

        if is_empty(cmd):
            self.logger.debug('finish command not running!!- jobgroup_id=%d' %
                              (self._m_jg.id))
            return False  # No finish Command
        else:
            try:
                self.logger.info(
                    'finish command running!! - jobgroup_id=%d : cmd=%s' %
                    (self._m_jg.id, cmd))

                lcmd = split_shell_command(cmd)

                if self.chk_whitelist(lcmd[0]):
                    try:
                        (proc, proc_info) = popen(
                            lcmd,
                            self._cf['job.popen.timeout'],
                            self._cf['job.popen.waittime'],
                            self._cf['job.popen.env.lang'],
                        )
                        self.logger.debug('Of commands executed stdout=%s' %
                                          proc_info['stdout'])
                        self.logger.debug('Of commands executed stderr=%s' %
                                          proc_info['stderr'])

                    except OSError, oe:
                        self.logger.info(
                            'finish command system failed!! jobgroup_id=%d : cmd=%s'
                            % (self._m_jg.id, cmd))
                        raise oe

                    if proc_info['r_code'] == 0:
                        self.logger.info(
                            'finish command successful!! - jobgroup_id=%d : cmd=%s'
                            % (self._m_jg.id, cmd))
                    else:
                        self.logger.info(
                            'finish command failed!! - jobgroup_id=%d : cmd=%s'
                            % (self._m_jg.id, cmd))
                    return True

                else:
示例#4
0
    def _finish(self):
        proc = None
        proc_info = []
        cmd = self._m_jg.finish_command

        if is_empty(cmd):
            self.logger.debug('finish command not running!!- jobgroup_id=%d' % (self._m_jg.id))
            return False # No finish Command
        else:
            try:
                self.logger.info('finish command running!! - jobgroup_id=%d : cmd=%s'
                                  % (self._m_jg.id, cmd))

                lcmd = split_shell_command(cmd)

                if self.chk_whitelist(lcmd[0]):
                    try:
                        (proc, proc_info) = popen(lcmd,
                                                  self._cf['job.popen.timeout'],
                                                  self._cf['job.popen.waittime'],
                                                  self._cf['job.popen.env.lang'],
                                                  )
                        self.logger.debug('Of commands executed stdout=%s' % proc_info['stdout'])
                        self.logger.debug('Of commands executed stderr=%s' % proc_info['stderr'])
                        
                    except OSError, oe:
                        self.logger.info('finish command system failed!! jobgroup_id=%d : cmd=%s'
                                          % (self._m_jg.id, cmd))
                        raise oe

                    if proc_info['r_code'] == 0:
                        self.logger.info('finish command successful!! - jobgroup_id=%d : cmd=%s'
                                          % (self._m_jg.id, cmd))
                    else:
                        self.logger.info('finish command failed!! - jobgroup_id=%d : cmd=%s'
                                      % (self._m_jg.id, cmd))
                    return True

                else:
示例#5
0
    def _rollback(self, session, m_jobs):
        for m_job in m_jobs:

            if m_job.is_rollback() and m_job.status in (ACTION_STATUS['RUN'],
                                                        ACTION_STATUS['OK'],
                                                        ACTION_STATUS['NG']):
                # rollback exec
                proc = None
                proc_info = []
                try:
                    cmd = m_job.rollback_command
                    self.logger.info(
                        'rollback command running!!- jobgroup_id=%d : cmd=%s' %
                        (m_job.id, cmd))

                    lcmd = split_shell_command(cmd)

                    if self.chk_whitelist(lcmd[0]):
                        try:
                            (proc, proc_info) = popen(
                                cmd=lcmd,
                                timeout=self._cf['job.popen.timeout'],
                                waittime=self._cf['job.popen.waittime'],
                                lang=self._cf['job.popen.env.lang'],
                                limit=self._cf['job.popen.output.limit'],
                            )

                            self.logger.debug(
                                'Of commands executed stdout=%s' %
                                proc_info['stdout'])
                            self.logger.debug(
                                'Of commands executed stderr=%s' %
                                proc_info['stderr'])

                        except OSError, oe:
                            self.logger.info(
                                'rollback command system failed!! job_id=%d : cmd=%s'
                                % (m_job.id, cmd))
                            raise oe

                        job_result_rollback(session, m_job,
                                            proc_info)  # Job result UPDATE
                        if proc_info['r_code'] == 0:  # Normal end
                            self.logger.info(
                                'rollback command was successful!! job_id=%d : cmd=%s'
                                % (m_job.id, cmd))
                            job_update(session, m_job,
                                       ROLLBACK_STATUS['OK'])  # Job UPDATE
                        else:  # Abnormal termination
                            self.logger.info(
                                'rollback command failed!! job_id=%d : cmd=%s'
                                % (m_job.id, cmd))
                            job_update(session, m_job,
                                       ROLLBACK_STATUS['NG'])  # Job UPDATE

                    else:
                        # whitelist error
                        self.logger.info(
                            'Tried to run the rollback command that is not registered in the whitelist. job_id=%d : cmd=%s'
                            % (m_job.id, cmd))
                        m_job.rollback_stderr = "Command is not registered to run the whitelist."
                        job_update(session, m_job,
                                   ROLLBACK_STATUS['WHITELIST'])  # Job UPDATE

                finally:
示例#6
0
    def _action(self, session, m_jobs):
        ret = True
        for m_job in m_jobs:  # job(N) execute
            job_update(session, m_job, ACTION_STATUS['RUN'])  # Job UPDATE
            proc = None
            proc_info = []
            try:
                cmd = m_job.action_command
                self.logger.info(
                    'action command running!!- jobgroup_id=%d : cmd=%s' %
                    (m_job.id, cmd))

                lcmd = split_shell_command(cmd)
                if self.chk_whitelist(lcmd[0]):
                    try:
                        (proc, proc_info) = popen(
                            cmd=lcmd,
                            timeout=self._cf['job.popen.timeout'],
                            waittime=self._cf['job.popen.waittime'],
                            lang=self._cf['job.popen.env.lang'],
                            limit=self._cf['job.popen.output.limit'],
                            job_id=m_job.id,
                        )

                        self.logger.debug('Of commands executed stdout=%s' %
                                          proc_info['stdout'])
                        self.logger.debug('Of commands executed stderr=%s' %
                                          proc_info['stderr'])

                        if self._cf['job.popen.output.limit'] < len(
                                proc_info['stdout']):
                            self.logger.info("There was a limit beyond stdout output. Information-processing is truncated beyond the limit. - limit=%d, stdout=%d" \
                                             % (self._cf['job.popen.output.limit'], len(proc_info['stdout'])))

                        if self._cf['job.popen.output.limit'] < len(
                                proc_info['stderr']):
                            self.logger.info("There was a limit beyond stderr output. Information-processing is truncated beyond the limit. - limit=%d, stderr=%d" \
                                             % (self._cf['job.popen.output.limit'], len(proc_info['stderr'])))

                    except OSError, oe:
                        self.logger.info(
                            'action command system failed!! job_id=%d : cmd=%s'
                            % (m_job.id, cmd))
                        raise oe

                    job_result_action(session, m_job,
                                      proc_info)  # Job result UPDATE

                    if proc_info['r_code'] == 0:  # Normal end
                        self.logger.info(
                            'action command was successful!! job_id=%d : cmd=%s'
                            % (m_job.id, cmd))
                        job_update(session, m_job,
                                   ACTION_STATUS['OK'])  # Job UPDATE
                    else:  # Abnormal termination
                        self.logger.info(
                            'action command failed!! job_id=%d : cmd=%s' %
                            (m_job.id, cmd))
                        job_update(session, m_job,
                                   ACTION_STATUS['NG'])  # Job UPDATE
                        ret = False
                        break
                else:
                    # whitelist error
                    self.logger.info(
                        'Tried to run the action command that is not registered in the whitelist. job_id=%d : cmd=%s'
                        % (m_job.id, cmd))
                    m_job.action_stderr = "Command is not registered to run the whitelist."
                    job_update(session, m_job,
                               ACTION_STATUS['WHITELIST'])  # Job UPDATE
                    ret = False
                    break
示例#7
0
 def test_popen_1(self):
     cmd = target.split_shell_command('cat *')
     (proc, proc_info) = target.popen(cmd)
     self.assertTrue(proc_info['r_code'] == 1)