def setUp(self): super(WhenUsingKeystoneEventConsumerProcessMethod, self).setUp() # Override the database start function as repositories.start() is # already invoked by the RepositoryTestCase base class setUp(). # Similarly, override the clear function. self.task = consumer.KeystoneEventConsumer(db_start=mock.MagicMock(), db_clear=mock.MagicMock())
def process_event(self, ctxt, publisher_id, event_type, payload, metadata): """Process Keystone Event based on event_type and payload data. Parses notification data to identify if the event is related to delete project or not. In case of delete project event, it passes project_id to KeystoneEventConsumer logic for further processing. Barbican service is not interested in other events so in that case it just returns None as acknowledgment. Messaging server considers message is acknowledged when either return value is `oslo_messaging.NotificationResult.HANDLED` or None. In case of successful processing of notification, the returned value is `oslo_messaging.NotificationResult.HANDLED` In case of notification processing error, the value returned is oslo_messaging.NotificationResult.REQUEUE when transport supports this feature otherwise `oslo_messaging.NotificationResult.HANDLED` is returned. """ LOG.debug(u._("Input keystone event publisher_id = %s"), publisher_id) LOG.debug(u._("Input keystone event payload = %s"), payload) LOG.debug(u._("Input keystone event type = %s"), event_type) LOG.debug(u._("Input keystone event metadata = %s"), metadata) project_id = self._parse_payload_for_project_id(payload) resource_type, operation_type = self._parse_event_type(event_type) LOG.debug('Keystone Event: resource type={0}, operation type={1}, ' 'keystone id={2}'.format(resource_type, operation_type, project_id)) if (project_id and resource_type == 'project' and operation_type == 'deleted'): task = keystone_consumer.KeystoneEventConsumer() try: task.process(project_id=project_id, resource_type=resource_type, operation_type=operation_type) return oslo_messaging.NotificationResult.HANDLED except Exception: # No need to log message here as task process method has # already logged it # TODO(john-wood-w) This really should be retried on a # schedule and really only if the database is down, not # for any exception otherwise tasks will be re-queued # repeatedly. Revisit as part of the retry task work later. if self.conf.keystone_notifications.allow_requeue: return oslo_messaging.NotificationResult.REQUEUE else: return oslo_messaging.NotificationResult.HANDLED return None # in case event is not project delete
def test_invoke_handle_error(self): task = consumer.KeystoneEventConsumer(repositories='Fake Repository') project = mock.MagicMock() project.project_id = 'project_id' status = 'status' message = 'message' exception_test = ValueError('Abort!') resource_type = 'type' operation_type = 'operation' task.handle_error( project, status, message, exception_test, project_id=None, resource_type=resource_type, operation_type=operation_type)