Example #1
0
    def emit(self, context):
        """Send the notification."""
        if not self._should_notify():
            return
        if not self.payload.populated:
            raise exception.NotificationPayloadError(
                class_name=self.__class__.__name__)
        # NOTE(mariojv) By default, oslo_versionedobjects includes a list
        # of "changed fields" for the object in the output of
        # obj_to_primitive. This is unneeded since every field of the
        # object will look changed, since each payload is a newly created
        # object, so we drop the changes.
        self.payload.obj_reset_changes()
        event_type = self.event_type.to_event_type_field()
        publisher_id = '%s.%s' % (self.publisher.service, self.publisher.host)
        payload = self.payload.obj_to_primitive()

        notifier = rpc.get_versioned_notifier(publisher_id)
        notify = getattr(notifier, self.level)
        notify(context, event_type=event_type, payload=payload)
Example #2
0
 def test_get_versioned_notifier(self):
     rpc.VERSIONED_NOTIFIER = mock.Mock(autospec=True)
     rpc.get_versioned_notifier(publisher_id='a_great_publisher')
     rpc.VERSIONED_NOTIFIER.prepare.assert_called_once_with(
         publisher_id='a_great_publisher')