Ejemplo n.º 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
Ejemplo n.º 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:
Ejemplo n.º 3
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:
Ejemplo n.º 4
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