Esempio n. 1
0
 def verify_run_result(self, cmd, result):
     rc, out, err = result.return_code, result.stdout, result.stderr
     log.debug('CMD %r RC %s OUT %s ERR %s', cmd, rc, out, err)
     if not result.success:
         message = 'CMD %r failed RC %s ERR %s' % (cmd, rc, err)
         log.error(message)
         raise errors.SolarError(result.output)
Esempio n. 2
0
 def verify_run_result(self, cmd, result):
     rc, out, err = result.return_code, result.stdout, result.stderr
     log.debug('CMD %r RC %s OUT %s ERR %s', cmd, rc, out, err)
     if not result.success:
         message = 'CMD %r failed RC %s ERR %s' % (cmd, rc, err)
         log.error(message)
         raise errors.SolarError(result.output)
Esempio n. 3
0
 def __call__(self, ctxt, *args, **kwargs):
     for sub in self._subscribers['before']:
         try:
             sub(ctxt)
         except Exception as exc:
             log.error('Subscriber before %r failed with %r', sub, exc)
     try:
         rst = self.func(self.instance, ctxt, *args, **kwargs)
         for sub in self._subscribers['on_success']:
             try:
                 sub(ctxt, rst, *args, **kwargs)
             except Exception as exc:
                 log.error('Subscriber on_success %r failed with %r', sub,
                           exc)
         return rst
     except Exception as exc:
         for sub in self._subscribers['on_error']:
             try:
                 sub(ctxt, repr(exc), *args, **kwargs)
             except Exception as exc:
                 log.error('Subscriber on_error %r failed with %r', sub,
                           exc)
         raise
     finally:
         for sub in self._subscribers['after']:
             try:
                 sub(ctxt)
             except Exception as exc:
                 log.error('Subscriber after %r failed with %r', sub, exc)
Esempio n. 4
0
 def __call__(self, ctxt, *args, **kwargs):
     for sub in self._subscribers['before']:
         try:
             sub(ctxt)
         except Exception as exc:
             log.error('Subscriber before %r failed with %r', sub, exc)
     try:
         rst = self.func(self.instance, ctxt, *args, **kwargs)
         for sub in self._subscribers['on_success']:
             try:
                 sub(ctxt, rst, *args, **kwargs)
             except Exception as exc:
                 log.error(
                     'Subscriber on_success %r failed with %r', sub, exc)
         return rst
     except Exception as exc:
         for sub in self._subscribers['on_error']:
             try:
                 sub(ctxt, repr(exc), *args, **kwargs)
             except Exception as exc:
                 log.error(
                     'Subscriber on_error %r failed with %r', sub, exc)
         raise
     finally:
         for sub in self._subscribers['after']:
             try:
                 sub(ctxt)
             except Exception as exc:
                 log.error('Subscriber after %r failed with %r', sub, exc)
Esempio n. 5
0
def validate_input(value, jsonschema=None, schema=None):
    """Validate single input according to schema.

    :param value: Value to be validated
    :param schema: Dict in jsonschema format
    :param schema: Our custom, simplified schema
    :return: list with errors
    """
    if jsonschema is None:
        jsonschema = construct_jsonschema(schema)
    try:
        validate(value, jsonschema)
    except ValidationError as e:
        return [e.message]
    except Exception as e:
        log.error('jsonschema: %s', jsonschema)
        log.error('value: %s', value)
        log.exception(e)
        raise
Esempio n. 6
0
    def subscribe(self, receiver):
        """
        :param receiver: Observer
        :return:
        """
        log.debug('Subscribe %s', receiver)
        # No multiple subscriptions
        if self.find_receiver(receiver):
            log.error('No multiple subscriptions from %s', receiver)
            return
        receiver.subscribed(self)

        signals.Connections.add(
            self.attached_to,
            self.name,
            receiver.attached_to,
            receiver.name
        )

        receiver.notify(self)