def test_a_list_of_callbacks(self): def callback(*args, **kwargs): pass class C(object): def callback(self, *args, **kwargs): pass with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback(CREATED_OPERATION, 'thing', [callback, C.callback]) callback_1 = 'keystone.tests.unit.common.test_notifications.callback' callback_2 = 'keystone.tests.unit.common.test_notifications.C.callback' expected_log_data = [ { 'callback': callback_1, 'event': 'identity.thing.created' }, { 'callback': callback_2, 'event': 'identity.thing.created' }, ] self.verify_log_message(expected_log_data)
def test_notification_received(self): notifications.register_event_callback('created', 'project', self._project_created_callback) project_ref = self.new_project_ref(domain_id=self.domain_id) self.assignment_api.create_project(project_ref['id'], project_ref) self.assertTrue(self.has_been_called)
def register_event_callbacks(self): # NOTE(morganfainberg): A provider who has an implicit # dependency on other providers may utilize the event callback # mechanism to react to any changes in those providers. This is # performed at the .provider() mechanism so that we can ensure # that the callback is only ever called once and guaranteed # to be on the properly configured and instantiated backend. if not hasattr(self, 'event_callbacks'): return if not isinstance(self.event_callbacks, dict): msg = _('event_callbacks must be a dict') raise ValueError(msg) for event in self.event_callbacks: if not isinstance(self.event_callbacks[event], dict): msg = _('event_callbacks[%s] must be a dict') % event raise ValueError(msg) for resource_type in self.event_callbacks[event]: # Make sure we register the provider for each event it # cares to call back. callbacks = self.event_callbacks[event][resource_type] if not callbacks: continue if not hasattr(callbacks, '__iter__'): # ensure the callback information is a list # allowing multiple callbacks to exist callbacks = [callbacks] notifications.register_event_callback( event, resource_type, callbacks)
def register_event_callbacks(self): # NOTE(morganfainberg): A provider who has an implicit # dependency on other providers may utilize the event callback # mechanism to react to any changes in those providers. This is # performed at the .provider() mechanism so that we can ensure # that the callback is only ever called once and guaranteed # to be on the properly configured and instantiated backend. if not hasattr(self, 'event_callbacks'): return if not isinstance(self.event_callbacks, dict): msg = _('event_callbacks must be a dict') raise ValueError(msg) for event in self.event_callbacks: if not isinstance(self.event_callbacks[event], dict): msg = _('event_callbacks[%s] must be a dict') % event raise ValueError(msg) for resource_type in self.event_callbacks[event]: # Make sure we register the provider for each event it # cares to call back. callbacks = self.event_callbacks[event][resource_type] if not callbacks: continue if not hasattr(callbacks, '__iter__'): # ensure the callback information is a list # allowing multiple callbacks to exist callbacks = [callbacks] notifications.register_event_callback(event, resource_type, callbacks)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_callback], ['OS-OAUTH1:consumer', self._consumer_callback], ['OS-OAUTH1:access_token', self._access_token_callback], ['role', self._role_callback], ['user', self._user_callback], ['project', self._project_callback], ], notifications.ACTIONS.disabled: [ ['user', self._user_callback], ['project', self._project_callback], ['domain', self._domain_callback], ], notifications.ACTIONS.internal: [ [ notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._user_callback ], ] } for event, cb_info in six.iteritems(callbacks): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_callback], ['OS-OAUTH1:consumer', self._consumer_callback], ['OS-OAUTH1:access_token', self._access_token_callback], ['role', self._role_callback], ['user', self._user_callback], ['project', self._project_callback], ['role_assignment', self._role_assignment_callback] ], notifications.ACTIONS.disabled: [ ['user', self._user_callback], ['project', self._project_callback], ['domain', self._domain_callback], ], notifications.ACTIONS.internal: [ [notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._user_callback], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_callback_listeners(self): # This is used by the @dependency.provider decorator to register the # provider (token_provider_api) manager to listen for trust deletions. callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_deleted_event_callback], ['user', self._delete_user_tokens_callback], ['domain', self._delete_domain_tokens_callback], ], notifications.ACTIONS.disabled: [ ['user', self._delete_user_tokens_callback], ['domain', self._delete_domain_tokens_callback], ['project', self._delete_project_tokens_callback], ], notifications.ACTIONS.internal: [ [ notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._delete_user_tokens_callback ], [ notifications.INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE, self._delete_user_project_tokens_callback ], [ notifications.INVALIDATE_USER_OAUTH_CONSUMER_TOKENS, self._delete_user_oauth_consumer_tokens_callback ], ] } for event, cb_info in six.iteritems(callbacks): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def test_a_list_of_callbacks(self): def callback(*args, **kwargs): pass class C(object): def callback(self, *args, **kwargs): pass with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback( CREATED_OPERATION, 'thing', [callback, C.callback]) callback_1 = 'keystone.tests.unit.common.test_notifications.callback' callback_2 = 'keystone.tests.unit.common.test_notifications.C.callback' expected_log_data = [ { 'callback': callback_1, 'event': 'identity.thing.created' }, { 'callback': callback_2, 'event': 'identity.thing.created' }, ] self.verify_log_message(expected_log_data)
def register_callback(operation, resource_type=EXP_RESOURCE_TYPE): """Helper for creating and registering a mock callback. """ callback = mock.Mock(__name__="callback", im_class=mock.Mock(__name__="class")) notifications.register_event_callback(operation, resource_type, callback) return callback
def _register_callback_listeners(self): # This is used by the @dependency.provider decorator to register the # provider (token_provider_api) manager to listen for trust deletions. callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_deleted_event_callback], ['user', self._delete_user_tokens_callback], ['domain', self._delete_domain_tokens_callback], ], notifications.ACTIONS.disabled: [ ['user', self._delete_user_tokens_callback], ['domain', self._delete_domain_tokens_callback], ['project', self._delete_project_tokens_callback], ], notifications.ACTIONS.internal: [ [notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._delete_user_tokens_callback], [notifications.INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE, self._delete_user_project_tokens_callback], [notifications.INVALIDATE_USER_OAUTH_CONSUMER_TOKENS, self._delete_user_oauth_consumer_tokens_callback], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def __init__(self): super(Manager, self).__init__(CONF.catalog.driver) notifications.register_event_callback( notifications.ACTIONS.deleted, 'project', self._on_project_or_endpoint_delete) notifications.register_event_callback( notifications.ACTIONS.deleted, 'endpoint', self._on_project_or_endpoint_delete)
def __init__(self): super(EndpointFilterV3Controller, self).__init__() notifications.register_event_callback( notifications.ACTIONS.deleted, 'project', self._on_project_or_endpoint_delete) notifications.register_event_callback( notifications.ACTIONS.deleted, 'endpoint', self._on_project_or_endpoint_delete)
def test_event_registration_for_unknown_resource_type(self): # Registration for unknown resource types should succeed. If no event # is issued for that resource type, the callback wont be triggered. notifications.register_event_callback("deleted", uuid.uuid4().hex, self._project_deleted_callback) resource_type = uuid.uuid4().hex notifications.register_event_callback("deleted", resource_type, self._project_deleted_callback) self.assertIn("deleted", notifications.SUBSCRIBERS) self.assertIn(resource_type, notifications.SUBSCRIBERS["deleted"])
def register_callback(operation, resource_type=EXP_RESOURCE_TYPE): """Helper for creating and registering a mock callback. """ callback = mock.Mock(__name__='callback', im_class=mock.Mock(__name__='class')) notifications.register_event_callback(operation, resource_type, callback) return callback
def test_event_registration_for_unknown_resource_type(self): # Registration for unknown resource types should succeed. If no event # is issued for that resource type, the callback wont be triggered. notifications.register_event_callback(DELETED_OPERATION, uuid.uuid4().hex, self._project_deleted_callback) resource_type = uuid.uuid4().hex notifications.register_event_callback(DELETED_OPERATION, resource_type, self._project_deleted_callback)
def test_a_function_callback(self): def callback(*args, **kwargs): pass resource_type = "thing" with mock.patch("keystone.notifications.LOG", self.mock_log): notifications.register_event_callback(CREATED_OPERATION, resource_type, callback) callback = "keystone.tests.unit.common.test_notifications.callback" expected_log_data = {"callback": callback, "event": "identity.%s.created" % resource_type} self.verify_log_message([expected_log_data])
def test_event_registration_for_unknown_resource_type(self): # Registration for unknown resource types should succeed. If no event # is issued for that resource type, the callback wont be triggered. notifications.register_event_callback('deleted', uuid.uuid4().hex, self._project_deleted_callback) resource_type = uuid.uuid4().hex notifications.register_event_callback('deleted', resource_type, self._project_deleted_callback) self.assertIn('deleted', notifications.SUBSCRIBERS) self.assertIn(resource_type, notifications.SUBSCRIBERS['deleted'])
def test_a_method_callback(self): class C(object): def callback(self, *args, **kwargs): pass with mock.patch("keystone.notifications.LOG", self.mock_log): notifications.register_event_callback(CREATED_OPERATION, "thing", C().callback) callback = "keystone.tests.unit.common.test_notifications.C.callback" expected_log_data = {"callback": callback, "event": "identity.thing.created"} self.verify_log_message([expected_log_data])
def _register_listeners(self): callbacks = [ ['deleted', 'OS-TRUST:trust', self._trust_callback], ['deleted', 'OS-OAUTH1:consumer', self._consumer_callback], ['deleted', 'OS-OAUTH1:access_token', self._access_token_callback], ['deleted', 'role', self._role_callback], ['deleted', 'user', self._user_callback], ['disabled', 'user', self._user_callback], ['deleted', 'project', self._project_callback], ['disabled', 'project', self._project_callback], ['disabled', 'domain', self._domain_callback]] for cb in callbacks: notifications.register_event_callback(*cb)
def test_a_method_callback(self): class C(object): def callback(self, *args, **kwargs): pass with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback(CREATED_OPERATION, 'thing', C.callback) expected_log_data = { 'callback': 'keystone.tests.test_notifications.C.callback', 'event': 'identity.thing.created' } self.verify_log_message([expected_log_data])
def test_a_function_callback(self): def callback(*args, **kwargs): pass resource_type = 'thing' with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback(CREATED_OPERATION, resource_type, callback) expected_log_data = { 'callback': 'keystone.tests.test_notifications.callback', 'event': 'identity.%s.created' % resource_type } self.verify_log_message([expected_log_data])
def _register_listeners(self): callbacks = [ ['deleted', 'OS-TRUST:trust', self._trust_callback], ['deleted', 'OS-OAUTH1:consumer', self._consumer_callback], ['deleted', 'OS-OAUTH1:access_token', self._access_token_callback], ['deleted', 'role', self._role_callback], ['deleted', 'user', self._user_callback], ['disabled', 'user', self._user_callback], ['deleted', 'project', self._project_callback], ['disabled', 'project', self._project_callback], ['disabled', 'domain', self._domain_callback] ] for cb in callbacks: notifications.register_event_callback(*cb)
def test_a_function_callback(self): def callback(*args, **kwargs): pass resource_type = 'thing' with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback( CREATED_OPERATION, resource_type, callback) expected_log_data = { 'callback': 'keystone.tests.test_notifications.callback', 'event': 'identity.%s.created' % resource_type } self.verify_log_message([expected_log_data])
def test_a_method_callback(self): class C(object): def callback(self, *args, **kwargs): pass with mock.patch('keystone.notifications.LOG', self.mock_log): notifications.register_event_callback( CREATED_OPERATION, 'thing', C.callback) expected_log_data = { 'callback': 'keystone.tests.test_notifications.C.callback', 'event': 'identity.thing.created' } self.verify_log_message([expected_log_data])
def test_a_list_of_callbacks(self): def callback(*args, **kwargs): pass class C(object): def callback(self, *args, **kwargs): pass with mock.patch("keystone.notifications.LOG", self.mock_log): notifications.register_event_callback(CREATED_OPERATION, "thing", [callback, C.callback]) expected_log_data = [ {"callback": "keystone.tests.test_notifications.callback", "event": "identity.thing.created"}, {"callback": "keystone.tests.test_notifications.C.callback", "event": "identity.thing.created"}, ] self.verify_log_message(expected_log_data)
def __init__(self): super(EndpointPolicyV3Controller, self).__init__() notifications.register_event_callback( 'deleted', 'endpoint', self._on_endpoint_delete) notifications.register_event_callback( 'deleted', 'service', self._on_service_delete) notifications.register_event_callback( 'deleted', 'region', self._on_region_delete) notifications.register_event_callback( 'deleted', 'policy', self._on_policy_delete)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_callback], ['OS-OAUTH1:consumer', self._consumer_callback], ['user', self._user_callback], ['project', self._project_callback], ], notifications.ACTIONS.disabled: [['user', self._user_callback]], notifications.ACTIONS.internal: [ [ notifications.PERSIST_REVOCATION_EVENT_FOR_USER, self._user_callback ], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ["OS-TRUST:trust", self._trust_callback], ["OS-OAUTH1:consumer", self._consumer_callback], ["OS-OAUTH1:access_token", self._access_token_callback], ["role", self._role_callback], ["user", self._user_callback], ["project", self._project_callback], ], notifications.ACTIONS.disabled: [ ["user", self._user_callback], ["project", self._project_callback], ["domain", self._domain_callback], ], notifications.ACTIONS.internal: [[notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._user_callback]], } for event, cb_info in six.iteritems(callbacks): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._trust_callback], ['OS-OAUTH1:consumer', self._consumer_callback], ['user', self._user_callback], ['project', self._project_callback], ], notifications.ACTIONS.disabled: [ ['user', self._user_callback] ], notifications.ACTIONS.internal: [ [notifications.PERSIST_REVOCATION_EVENT_FOR_USER, self._user_callback], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_callback_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._drop_receipt_cache], ['user', self._drop_receipt_cache], ['domain', self._drop_receipt_cache], ], notifications.ACTIONS.disabled: [ ['user', self._drop_receipt_cache], ['domain', self._drop_receipt_cache], ['project', self._drop_receipt_cache], ], notifications.ACTIONS.internal: [ [notifications.INVALIDATE_TOKEN_CACHE, self._drop_receipt_cache], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_listeners(self): callbacks = { notifications.ACTIONS.deleted: [ ['role', self._role_callback], ['user', self._user_callback], ['project', self._project_callback], ], notifications.ACTIONS.disabled: [ ['user', self._user_callback], ['project', self._project_callback], ['domain', self._domain_callback], ], notifications.ACTIONS.internal: [ [notifications.INVALIDATE_USER_TOKEN_PERSISTENCE, self._user_callback], ] } for event, cb_info in six.iteritems(callbacks): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_callback_listeners(self): # This is used by the @dependency.provider decorator to register the # provider (token_provider_api) manager to listen for trust deletions. callbacks = { notifications.ACTIONS.deleted: [ ['OS-TRUST:trust', self._drop_token_cache], ['user', self._drop_token_cache], ['domain', self._drop_token_cache], ], notifications.ACTIONS.disabled: [ ['user', self._drop_token_cache], ['domain', self._drop_token_cache], ['project', self._drop_token_cache], ], notifications.ACTIONS.internal: [ [notifications.INVALIDATE_TOKEN_CACHE, self._drop_token_cache], ] } for event, cb_info in callbacks.items(): for resource_type, callback_fns in cb_info: notifications.register_event_callback(event, resource_type, callback_fns)
def _register_callback_listeners(self): notifications.register_event_callback( notifications.ACTIONS.deleted, 'user', self._delete_app_creds_on_user_delete_callback) notifications.register_event_callback( notifications.ACTIONS.disabled, 'user', self._delete_app_creds_on_user_delete_callback) notifications.register_event_callback( notifications.ACTIONS.internal, notifications.REMOVE_APP_CREDS_FOR_USER, self._delete_app_creds_on_assignment_removal)
def _register_callback_listeners(self): notifications.register_event_callback( notifications.ACTIONS.deleted, 'user', self._delete_app_creds_on_user_delete_callback) notifications.register_event_callback( notifications.ACTIONS.disabled, 'user', self._delete_app_creds_on_user_delete_callback) notifications.register_event_callback( notifications.ACTIONS.internal, # This notification is emitted when a role assignment is removed, # we can take advantage of it even though we're not a token. notifications.INVALIDATE_USER_PROJECT_TOKEN_PERSISTENCE, self._delete_app_creds_on_assignment_removal)
def __init__(self): super(Manager, self).__init__(CONF.federation.driver) notifications.register_event_callback( notifications.ACTIONS.internal, notifications.DOMAIN_DELETED, self._cleanup_identity_provider )
def __init__(self): super(Manager, self).__init__(CONF.trust.driver) notifications.register_event_callback( notifications.ACTIONS.deleted, 'user', self._on_user_delete)
def __init__(self): super(Manager, self).__init__(CONF.federation.driver) notifications.register_event_callback(notifications.ACTIONS.internal, notifications.DOMAIN_DELETED, self._cleanup_identity_provider)
def __init__(self): super(Manager, self).__init__(CONF.trust.driver) notifications.register_event_callback(notifications.ACTIONS.deleted, 'user', self._on_user_delete)
def __init__(self): super(ProjectEndpointGroupV3Controller, self).__init__() notifications.register_event_callback(notifications.ACTIONS.deleted, "project", self._on_project_delete)