Exemplo n.º 1
0
Arquivo: Fsck.py Projeto: thiell/shine
    def ev_close(self, worker):
        """
        Check process termination status and generate appropriate events.

        Note that if fsck has correctly fixed some errors, actions will be
        considered as successful.
        """

        if worker.did_timeout():
            return FSAction.ev_close(self, worker)

        # We want to skip FSAction.ev_close(), just call the upper layer.
        Action.ev_close(self, worker)

        self.comp.lustre_check()

        # fsck returns 0=NOERROR, 1=OK_BUT_CORRECTION, 2=OK_BUT_REBOOT.
        # see man fsck.
        if worker.retcode() in (0, 1, 2, 4):
            # action succeeded
            result = Result(duration=self.duration, retcode=worker.retcode())
            if worker.retcode() in (1, 2):
                result.message = "Errors corrected"
            if worker.retcode() == 4:  # -n
                result.message = "Errors found but NOT corrected"
            self.comp.action_event(self, 'done', result)
            self.set_status(ACT_OK)
        else:
            # action failed
            msg = "\n".join(self._output)
            result = ErrorResult(msg, self.duration, worker.retcode())
            self.comp.action_event(self, 'failed', result)
            self.set_status(ACT_ERROR)
Exemplo n.º 2
0
    def ev_close(self, worker):
        """
        Check process termination status and set action status.
        """
        Action.ev_close(self, worker)

        self.server.lustre_check()

        # Action timed out
        if worker.did_timeout():
            self.server.action_event(self, 'timeout')
            self.set_status(ACT_ERROR)

        # Action succeeded
        elif worker.retcode() == 0:
            result = Result(duration=self.duration, retcode=worker.retcode())
            self.server.action_event(self, 'done', result)
            self.set_status(ACT_OK)

        # Action failed
        else:
            result = ErrorResult(worker.read(), self.duration,
                                 worker.retcode())
            self.server.action_event(self, 'failed', result)
            self.set_status(ACT_ERROR)
Exemplo n.º 3
0
    def set_status(self, status):
        """
        Update action status.

        If this is a final state, raise corresponding events.
        """
        # Do not raise events if start event was not raised.
        # Start event is raised when init is set.
        if self._init:
            if status == ACT_OK:
                self._server.action_event(self, 'done')
            elif status == ACT_ERROR:
                # Build an error string
                errors = []
                for act in self:
                    if act.status() == ACT_ERROR:
                        errors.append("'%s' failed" % act._command)
                result = ErrorResult("\n".join(errors))
                self._server.action_event(self, 'failed', result)

        ActionGroup.set_status(self, status)
Exemplo n.º 4
0
def shine_msg_unpack_v2(msg):
    """
    Compatibility function to unpack old-style v2 messages.

    v2-style messages were used up to v0.910, becoming useless when
    v3-style messages were introduced in v0.911, released 14-02-12.
    """
    # v2 message looks like:
    # SHINE:2:ev_starttarget_done:{node:, comp:, rc:, message:}

    event, msg = msg.split(':', 1)
    data = pickle.loads(binascii.a2b_base64(msg))
    dummy, actioncomp, data['status'] = event.split('_', 3)
    for name in ('router', 'client', 'target', 'journal'):
        if actioncomp.endswith(name):
            data['action'] = actioncomp[:-len(name)]
            data['compname'] = name
            break

    # Result is only possible for 'failed' event in v2.
    if data['status'] == 'failed':
        data['result'] = ErrorResult(message=data.get('message'),
                                     retcode=data.get('rc'))
    return data