Exemplo n.º 1
0
    def test_get_notification_handler_name(self):
        event_type = 'network.create.start'
        expected = 'create_network_alert'
        self.assertEqual(expected,
                         utils.get_notification_handler_name(event_type))

        event_type = 'network.create.end'
        expected = 'create_network_sync'
        self.assertEqual(expected,
                         utils.get_notification_handler_name(event_type))

        event_type = 'floatingip.delete.end'
        expected = 'delete_floatingip_sync'
        self.assertEqual(expected,
                         utils.get_notification_handler_name(event_type))

        event_type = 'compute.instance.create.end'
        expected = 'create_instance_sync'
        self.assertEqual(expected,
                         utils.get_notification_handler_name(event_type))
Exemplo n.º 2
0
    def process(self, ctxt, publisher_id, event_type, payload, metadata):
        self.ctxt = ctxt
        self.user_id = self.ctxt.get('user_id')

        try:
            handler_name = utils.get_notification_handler_name(event_type)
            handler = getattr(self, handler_name)
            if handler:
                handler(payload)
            return oslo_messaging.NotificationResult.HANDLED
        except sql_exc.OperationalError as e:
            LOG.info("Operational Error occurred. Please restart the agent.")
            LOG.error(encodeutils.exception_to_unicode(e))
        except Exception as e:
            LOG.error(encodeutils.exception_to_unicode(e))
    def test_notification_endpoint_with_notification_handler(self):
        msg_context = {}
        publisher_id = 'test_publisher'
        payload = {}
        metadata = {}

        endpoint = notification.NotificationEndpoint(self.ctx, None)
        endpoint.handler = self.event_handler

        # go through each event type and verify that each event handler is
        # called from notification handler
        event_types = notification.NotificationEndpoint.event_subscription_list
        for event_type in event_types:
            handler_name = utils.get_notification_handler_name(event_type)
            with mock.patch.object(endpoint.handler,
                                   handler_name) as handler_mock:
                endpoint.info(msg_context, publisher_id, event_type, payload,
                              metadata)
                handler_mock.assert_called_once_with(payload)
Exemplo n.º 4
0
    def test_notification_endpoint_with_notification_handler(self):
        msg_context = {}
        publisher_id = 'test_publisher'
        payload = {}
        metadata = {}

        endpoint = notification.NotificationEndpoint(self.ctx, None)
        endpoint.handler = self.event_handler

        # go through each event type and verify that each event handler is
        # called from notification handler
        event_types = notification.NotificationEndpoint.event_subscription_list
        for event_type in event_types:
            handler_name = utils.get_notification_handler_name(event_type)
            with mock.patch.object(endpoint.handler,
                                   handler_name) as handler_mock:
                endpoint.info(msg_context, publisher_id, event_type, payload,
                              metadata)
                handler_mock.assert_called_once_with(payload)