Example #1
0
def notify_about_notification_api(context,
                                  notification,
                                  action,
                                  phase=None,
                                  binary='masakari-api',
                                  exception=None,
                                  tb=None):
    """Send versioned notification about a notification api.

    :param notification: Notification object
    :param action: the name of the action
    :param phase: the phase of the action
    :param binary: the binary emitting the notification
    :param exception: the thrown exception (used in error notifications)
    :param tb: the traceback (used in error notifications)
    """
    fault, priority = _get_fault_and_priority_from_exc_and_tb(exception, tb)
    payload = event_notification.NotificationApiPayload(
        notification=notification, fault=fault)
    api_notification = event_notification.NotificationApiNotification(
        context=context,
        priority=priority,
        publisher=notification_base.NotificationPublisher(
            context=context, host=socket.gethostname(), binary=binary),
        event_type=notification_base.EventType(action=action, phase=phase),
        payload=payload)
    api_notification.emit(context)
Example #2
0
    def test_emit_with_host_and_binary_as_publisher(self, mock_notifier):
        noti = self.TestNotification(
            event_type=notification.EventType(
                object='test_object',
                action=fields.EventNotificationAction.SEGMENT_CREATE),
            publisher=notification.NotificationPublisher(
                host='fake-host', binary='masakari-fake'),
            priority=fields.EventNotificationPriority.INFO,
            payload=self.payload)

        mock_context = mock.Mock()
        mock_context.to_dict.return_value = {}
        noti.emit(mock_context)

        self._verify_notification(mock_notifier,
                                  mock_context,
                                  expected_event_type='segment.create',
                                  expected_payload=self.expected_payload)
Example #3
0
    def setUp(self):
        super(TestNotificationBase, self).setUp()
        mock_context = mock.Mock()
        mock_context.to_dict.return_value = {}
        self.publisher = notification.NotificationPublisher(
            context=mock_context, host='fake-host', binary='masakari-fake')

        self.my_obj = self.TestObject(field_1='test1',
                                      field_2=42,
                                      not_important_field=13)

        self.payload = self.TestNotificationPayload(extra_field='test string')
        self.payload.populate_schema(source_field=self.my_obj)

        self.notification = self.TestNotification(
            event_type=notification.EventType(
                object='test_object',
                action=fields.EventNotificationAction.SEGMENT_CREATE,
                phase=fields.EventNotificationPhase.START),
            publisher=self.publisher,
            priority=fields.EventNotificationPriority.INFO,
            payload=self.payload)