Add notifications for groups and roles

Currently, we only issue notifications for projects, users and
domains. This patch will add support to issue notifications for
groups and roles. Notifications will be sent on create, update
and delete.

I've also updated tests to include tests for projects and users.

DocImpact
Change-Id: I23eac9afb2a227e5739dc25395705597a92eb23c
fixes: bug 1231220
This commit is contained in:
Steve Martinelli 2013-09-26 15:21:31 -05:00
parent 060ced47e5
commit 13583ee852
4 changed files with 102 additions and 1 deletions

View File

@ -30,8 +30,10 @@ A notification is sent when a resource is successfully ``created``,
``updated``, or ``deleted``. The following resource types (where a
``<resource type>`` is always a singular noun) produce notifications:
- ``user``
- ``group``
- ``project`` (i.e. "tenant")
- ``role``
- ``user``
The following message template is used to form a message when an operation on a
resource completes successfully::

View File

@ -303,17 +303,20 @@ class Manager(manager.Manager):
def get_role(self, role_id):
return self.driver.get_role(role_id)
@notifications.created('role')
def create_role(self, role_id, role):
ret = self.driver.create_role(role_id, role)
if SHOULD_CACHE(ret):
self.get_role.set(ret, self, role_id)
return ret
@notifications.updated('role')
def update_role(self, role_id, role):
ret = self.driver.update_role(role_id, role)
self.get_role.invalidate(self, role_id)
return ret
@notifications.deleted('role')
def delete_role(self, role_id):
self.driver.delete_role(role_id)
self.get_role.invalidate(self, role_id)

View File

@ -373,6 +373,7 @@ class Manager(manager.Manager):
domain_id, driver = self._get_domain_id_and_driver(domain_scope)
driver.delete_user(user_id)
@notifications.created('group')
@domains_configured
def create_group(self, group_id, group_ref):
group = group_ref.copy()
@ -396,6 +397,7 @@ class Manager(manager.Manager):
ref = self._set_domain_id(ref, domain_id)
return ref
@notifications.updated('group')
@domains_configured
def update_group(self, group_id, group, domain_scope=None):
domain_id, driver = self._get_domain_id_and_driver(domain_scope)
@ -406,6 +408,7 @@ class Manager(manager.Manager):
ref = self._set_domain_id(ref, domain_id)
return ref
@notifications.deleted('group')
@domains_configured
def delete_group(self, group_id, domain_scope=None):
domain_id, driver = self._get_domain_id_and_driver(domain_scope)

View File

@ -19,6 +19,7 @@ import uuid
from keystone import notifications
from keystone.openstack.common.notifier import api as notifier_api
from keystone import tests
from keystone.tests import test_v3
EXP_RESOURCE_TYPE = uuid.uuid4().hex
@ -145,3 +146,95 @@ class NotificationsTestCase(tests.TestCase):
self.stubs.Set(notifier_api, 'notify', fake_notify)
notifications._send_notification(resource, resource_type, operation,
host=host)
class NotificationsForEntities(test_v3.RestfulTestCase):
def setUp(self):
super(NotificationsForEntities, self).setUp()
self.exp_resource_id = None
self.exp_operation = None
self.exp_resource_type = None
self.send_notification_called = False
def fake_notify(operation, resource_type, resource_id, host=None):
self.exp_resource_id = resource_id
self.exp_operation = operation
self.exp_resource_type = resource_type
self.send_notification_called = True
self.stubs.Set(notifications, '_send_notification', fake_notify)
def _assertLastNotify(self, resource_id, operation, resource_type):
self.assertIs(self.exp_operation, operation)
self.assertIs(self.exp_resource_id, resource_id)
self.assertIs(self.exp_resource_type, resource_type)
self.assertTrue(self.send_notification_called)
def test_create_group(self):
group_ref = self.new_group_ref(domain_id=self.domain_id)
self.identity_api.create_group(group_ref['id'], group_ref)
self._assertLastNotify(group_ref['id'], 'created', 'group')
def test_create_project(self):
project_ref = self.new_project_ref(domain_id=self.domain_id)
self.assignment_api.create_project(project_ref['id'], project_ref)
self._assertLastNotify(project_ref['id'], 'created', 'project')
def test_create_role(self):
role_ref = self.new_role_ref()
self.assignment_api.create_role(role_ref['id'], role_ref)
self._assertLastNotify(role_ref['id'], 'created', 'role')
def test_create_user(self):
user_ref = self.new_user_ref(domain_id=self.domain_id)
self.identity_api.create_user(user_ref['id'], user_ref)
self._assertLastNotify(user_ref['id'], 'created', 'user')
def test_delete_group(self):
group_ref = self.new_group_ref(domain_id=self.domain_id)
self.identity_api.create_group(group_ref['id'], group_ref)
self.identity_api.delete_group(group_ref['id'])
self._assertLastNotify(group_ref['id'], 'deleted', 'group')
def test_delete_project(self):
project_ref = self.new_project_ref(domain_id=self.domain_id)
self.assignment_api.create_project(project_ref['id'], project_ref)
self.assignment_api.delete_project(project_ref['id'])
self._assertLastNotify(project_ref['id'], 'deleted', 'project')
def test_delete_role(self):
role_ref = self.new_role_ref()
self.assignment_api.create_role(role_ref['id'], role_ref)
self.assignment_api.delete_role(role_ref['id'])
self._assertLastNotify(role_ref['id'], 'deleted', 'role')
def test_delete_user(self):
user_ref = self.new_user_ref(domain_id=self.domain_id)
self.identity_api.create_user(user_ref['id'], user_ref)
self.identity_api.delete_user(user_ref['id'])
self._assertLastNotify(user_ref['id'], 'deleted', 'user')
def test_update_group(self):
group_ref = self.new_group_ref(domain_id=self.domain_id)
self.identity_api.create_group(group_ref['id'], group_ref)
self.identity_api.update_group(group_ref['id'], group_ref)
self._assertLastNotify(group_ref['id'], 'updated', 'group')
def test_update_project(self):
project_ref = self.new_project_ref(domain_id=self.domain_id)
self.assignment_api.create_project(project_ref['id'], project_ref)
self.assignment_api.update_project(project_ref['id'], project_ref)
self._assertLastNotify(project_ref['id'], 'updated', 'project')
def test_update_role(self):
role_ref = self.new_role_ref()
self.assignment_api.create_role(role_ref['id'], role_ref)
self.assignment_api.update_role(role_ref['id'], role_ref)
self._assertLastNotify(role_ref['id'], 'updated', 'role')
def test_update_user(self):
user_ref = self.new_user_ref(domain_id=self.domain_id)
self.identity_api.create_user(user_ref['id'], user_ref)
self.identity_api.update_user(user_ref['id'], user_ref)
self._assertLastNotify(user_ref['id'], 'updated', 'user')