def _notify_loop(self, resource, event, trigger, **kwargs): """The notification loop.""" errors = [] callbacks = list(self._callbacks[resource].get(event, {}).items()) LOG.debug("Notify callbacks %s for %s, %s", [c[0] for c in callbacks], resource, event) # TODO(armax): consider using a GreenPile for callback_id, callback in callbacks: try: callback(resource, event, trigger, **kwargs) except Exception as e: abortable_event = (event.startswith(events.BEFORE) or event.startswith(events.PRECOMMIT)) if not abortable_event: LOG.exception( _LE("Error during notification for " "%(callback)s %(resource)s, %(event)s"), { 'callback': callback_id, 'resource': resource, 'event': event }) else: LOG.debug("Callback %(callback)s raised %(error)s", { 'callback': callback_id, 'error': e }) errors.append(exceptions.NotificationError(callback_id, e)) return errors
def _notify_loop(resource, event, trigger, **kwargs): """The notification loop.""" errors = [] callbacks = kwargs.pop('callbacks', None) if not callbacks: callbacks = list( registry._get_callback_manager()._callbacks[resource].get( event, {}).items()) LOG.debug("Notify callbacks %s for %s, %s", callbacks, resource, event) for callback_id, callback in callbacks: try: callback(resource, event, trigger, **kwargs) except Exception as e: abortable_event = (event.startswith(events.BEFORE) or event.startswith(events.PRECOMMIT)) if not abortable_event: LOG.exception( "Error during notification for " "%(callback)s %(resource)s, %(event)s", { 'callback': callback_id, 'resource': resource, 'event': event }) else: LOG.error("Callback %(callback)s raised %(error)s", { 'callback': callback_id, 'error': e }) errors.append(exceptions.NotificationError(callback_id, e)) return errors
def _notify_loop(self, resource, event, trigger, **kwargs): """The notification loop.""" errors = [] # NOTE(yamahata): Since callback may unsubscribe it, # convert iterator to list to avoid runtime error. callbacks = list(itertools.chain( *[pri_callbacks.items() for (priority, pri_callbacks) in self._callbacks[resource].get(event, [])])) LOG.debug("Notify callbacks %s for %s, %s", [c[0] for c in callbacks], resource, event) # TODO(armax): consider using a GreenPile for callback_id, callback in callbacks: try: callback(resource, event, trigger, **kwargs) except Exception as e: abortable_event = ( event.startswith(events.BEFORE) or event.startswith(events.PRECOMMIT) ) if not abortable_event: LOG.exception("Error during notification for " "%(callback)s %(resource)s, %(event)s", {'callback': callback_id, 'resource': resource, 'event': event}) else: LOG.debug("Callback %(callback)s raised %(error)s", {'callback': callback_id, 'error': e}) errors.append(exceptions.NotificationError(callback_id, e)) return errors
def test_inner_exceptions(self): key_err = KeyError() n_key_err = ex.NotificationError('cb1', key_err) err = ex.CallbackFailure([key_err, n_key_err]) self.assertEqual([key_err, n_key_err.error], err.inner_exceptions)
def test_notification_error(self): '''Test that correct message is created for this error class.''' error = ex.NotificationError('abc', 'boom') self.assertEqual('Callback abc failed with "boom"', str(error))