def setUp(self): super(TestNotificationBase, self).setUp() self.ctx = utils.dummy_context() service_id = uuidutils.generate_uuid() self.service_obj = objects.Service.create(self.ctx, service_id, self.fake_service['host'], self.fake_service['binary'], self.fake_service['topic']) self.my_obj = TestObject(field_1='test1', field_2=42, not_important_field=13) self.payload = TestPayload(extra_field='test string') self.payload.populate_schema(source_field=self.my_obj) self.notification = TestNotification( event_type=notification.EventType( object='test_object', action=fields.NotificationAction.UPDATE, phase=fields.NotificationPhase.START), publisher=notification.NotificationPublisher.from_service_obj( self.service_obj), priority=fields.NotificationPriority.INFO, payload=self.payload)
def test_empty_schema(self, mock_notifier): # create a non-populated payload payload = TestPayloadEmptySchema(extra_field='test string') event_type = notification.EventType( object='test_object', action=fields.NotificationAction.UPDATE) publisher = notification.NotificationPublisher.from_service_obj( self.service_obj) noti = TestNotificationEmptySchema( event_type=event_type, publisher=publisher, priority=fields.NotificationPriority.INFO, payload=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='test_object.update', expected_payload={ 'versioned_object.name': 'TestPayloadEmptySchema', 'versioned_object.data': { 'extra_field': u'test string' }, 'versioned_object.version': '1.0', 'versioned_object.namespace': 'senlin' })
def test_not_possible_to_emit_if_not_populated(self, mock_notifier): # create a non-populated payload payload = TestPayload(extra_field='test string') event_type = notification.EventType( object='test_object', action=fields.NotificationAction.UPDATE) publisher = notification.NotificationPublisher.from_service_obj( self.service_obj) noti = TestNotification(event_type=event_type, publisher=publisher, priority=fields.NotificationPriority.INFO, payload=payload) mock_context = mock.Mock() self.assertRaises(AssertionError, noti.emit, mock_context) self.assertFalse(mock_notifier.called)
def _notify_node_action(cls, ctx, level, node, action, **kwargs): action_name = cls._get_action_name(action.action) priority = utils.level_from_number(level).lower() publisher = nobj.NotificationPublisher(host=cfg.CONF.host, binary='senlin-engine') publisher.obj_set_defaults() phase = kwargs.get('phase') event_type = nobj.EventType(object='node', action=action_name, phase=phase) payload = nobj.NodeActionPayload(node, action) notification = nobj.NodeActionNotification(context=ctx, priority=priority, publisher=publisher, event_type=event_type, payload=payload) notification.emit(ctx)
def test_emit_event_type_without_phase(self, mock_notifier): noti = TestNotification( event_type=notification.EventType( object='test_object', action=fields.NotificationAction.UPDATE), publisher=notification.NotificationPublisher.from_service_obj( self.service_obj), priority=fields.NotificationPriority.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='test_object.update', expected_payload=self.expected_payload)
def test_emit_with_host_and_binary_as_publisher(self, mock_notifier): event_type = notification.EventType( object='test_object', action=fields.NotificationAction.UPDATE) publisher = notification.NotificationPublisher(host='fake-host', binary='senlin-fake') noti = TestNotification(event_type=event_type, publisher=publisher, priority=fields.NotificationPriority.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='test_object.update', expected_payload=self.expected_payload)
def setUp(self): super(TestNotificationBase, self).setUp() self.ctx = utils.dummy_context() self.service_obj = objects.Service(**self.fake_service) self.my_obj = TestObject(field_1='test1', field_2=42, not_important_field=13) self.payload = TestPayload(field_1='test1', field_2=42, extra_field='test string') self.notification = TestNotification( event_type=base.EventType( object='test_object', action='update', phase=consts.PHASE_START), publisher=base.NotificationPublisher.from_service( self.service_obj), priority=consts.PRIO_INFO, payload=self.payload)