Add volume type access operations notification
According to existing notification system we have notify methods for different cinder operations such as volume create/delete, etc. This patch extend our notification system and add missing notifications for commands: type-access-add type-access-remove The notifications could be used for billing and event notifications. Change-Id: I55bbb69be9507b243cce245e92037ab00920a29c Closes-Bug: #1568707
This commit is contained in:
parent
7502e1fed3
commit
2f409f9ba1
|
@ -554,3 +554,26 @@ class VolumeTypeTestCase(test.TestCase):
|
|||
'cipher': 'fake1',
|
||||
'created_at': 'time1', }
|
||||
self._exec_volume_types_encryption_changed(enc1, None, True)
|
||||
|
||||
@mock.patch('cinder.volume.volume_types.CONF')
|
||||
@mock.patch('cinder.volume.volume_types.rpc')
|
||||
def test_notify_about_volume_type_access_usage(self, mock_rpc,
|
||||
mock_conf):
|
||||
mock_conf.host = 'host1'
|
||||
project_id = fake.PROJECT_ID
|
||||
volume_type_id = fake.VOLUME_TYPE_ID
|
||||
|
||||
output = volume_types.notify_about_volume_type_access_usage(
|
||||
mock.sentinel.context,
|
||||
volume_type_id,
|
||||
project_id,
|
||||
'test_suffix')
|
||||
|
||||
self.assertIsNone(output)
|
||||
mock_rpc.get_notifier.assert_called_once_with('volume_type_project',
|
||||
'host1')
|
||||
mock_rpc.get_notifier.return_value.info.assert_called_once_with(
|
||||
mock.sentinel.context,
|
||||
'volume_type_project.test_suffix',
|
||||
{'volume_type_id': volume_type_id,
|
||||
'project_id': project_id})
|
||||
|
|
|
@ -30,6 +30,7 @@ from cinder import db
|
|||
from cinder import exception
|
||||
from cinder.i18n import _, _LE
|
||||
from cinder import quota
|
||||
from cinder import rpc
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -185,6 +186,31 @@ def is_public_volume_type(context, volume_type_id):
|
|||
return volume_type['is_public']
|
||||
|
||||
|
||||
def notify_about_volume_type_access_usage(context,
|
||||
volume_type_id,
|
||||
project_id,
|
||||
event_suffix,
|
||||
host=None):
|
||||
"""Notify about successful usage type-access-(add/remove) command.
|
||||
|
||||
:param context: security context
|
||||
:param volume_type_id: volume type uuid
|
||||
:param project_id: tenant uuid
|
||||
:param event_suffix: name of called operation access-(add/remove)
|
||||
:param host: hostname
|
||||
"""
|
||||
notifier_info = {'volume_type_id': volume_type_id,
|
||||
'project_id': project_id}
|
||||
|
||||
if not host:
|
||||
host = CONF.host
|
||||
|
||||
notifier = rpc.get_notifier("volume_type_project", host)
|
||||
notifier.info(context,
|
||||
'volume_type_project.%s' % event_suffix,
|
||||
notifier_info)
|
||||
|
||||
|
||||
def add_volume_type_access(context, volume_type_id, project_id):
|
||||
"""Add access to volume type for project_id."""
|
||||
if volume_type_id is None:
|
||||
|
@ -195,7 +221,13 @@ def add_volume_type_access(context, volume_type_id, project_id):
|
|||
msg = _("Type access modification is not applicable to public volume "
|
||||
"type.")
|
||||
raise exception.InvalidVolumeType(reason=msg)
|
||||
return db.volume_type_access_add(elevated, volume_type_id, project_id)
|
||||
|
||||
db.volume_type_access_add(elevated, volume_type_id, project_id)
|
||||
|
||||
notify_about_volume_type_access_usage(context,
|
||||
volume_type_id,
|
||||
project_id,
|
||||
'access.add')
|
||||
|
||||
|
||||
def remove_volume_type_access(context, volume_type_id, project_id):
|
||||
|
@ -208,7 +240,13 @@ def remove_volume_type_access(context, volume_type_id, project_id):
|
|||
msg = _("Type access modification is not applicable to public volume "
|
||||
"type.")
|
||||
raise exception.InvalidVolumeType(reason=msg)
|
||||
return db.volume_type_access_remove(elevated, volume_type_id, project_id)
|
||||
|
||||
db.volume_type_access_remove(elevated, volume_type_id, project_id)
|
||||
|
||||
notify_about_volume_type_access_usage(context,
|
||||
volume_type_id,
|
||||
project_id,
|
||||
'access.remove')
|
||||
|
||||
|
||||
def is_encrypted(context, volume_type_id):
|
||||
|
|
Loading…
Reference in New Issue