コード例 #1
0
    def test_empty_schema(self, mock_notifier):
        non_populated_payload = self.TestNotificationPayloadEmptySchema(
            extra_field='test string')
        noti = self.TestNotificationEmptySchema(
            event_type=notification.EventType(
                object='test_object',
                action=fields.EventNotificationAction.SEGMENT_CREATE),
            publisher=self.publisher,
            priority=fields.EventNotificationPriority.INFO,
            payload=non_populated_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={
                                      'masakari_object.name':
                                      'TestNotificationPayloadEmptySchema',
                                      'masakari_object.data': {
                                          'extra_field': u'test string'
                                      },
                                      'masakari_object.version': '1.0',
                                      'masakari_object.namespace': 'masakari'
                                  })
コード例 #2
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)
コード例 #3
0
    def test_not_possible_to_emit_if_not_populated(self, mock_notifier):
        non_populated_payload = self.TestNotificationPayload(
            extra_field='test string')
        noti = self.TestNotification(
            event_type=notification.EventType(
                object='test_object',
                action=fields.EventNotificationAction.SEGMENT_CREATE),
            publisher=self.publisher,
            priority=fields.EventNotificationPriority.INFO,
            payload=non_populated_payload)

        mock_context = mock.Mock()
        self.assertRaises(AssertionError, noti.emit, mock_context)
        self.assertFalse(mock_notifier.called)
コード例 #4
0
    def test_emit_event_type_without_phase(self, mock_notifier):
        noti = self.TestNotification(
            event_type=notification.EventType(
                object='test_object',
                action=fields.EventNotificationAction.SEGMENT_CREATE),
            publisher=self.publisher,
            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)
コード例 #5
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)
コード例 #6
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)