Add new notifications types for volumes/snapshots

This change allows to collect and view notifications of different types -
volume/snapshot.(create | delete | update).(start | end) and
volume.(resize | attach | detach).(start | end).

Implements: blueprint add-new-notifications-types-for-volumes-and-snapshots
Change-Id: I592605bcea483d06f219a4d02d3a70a9fc0e27a3
This commit is contained in:
Lena Novokshonova 2014-10-27 16:40:57 +04:00
parent c1323cc47c
commit 2891d168f8
3 changed files with 372 additions and 295 deletions

View File

@ -1,320 +1,369 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import datetime
import mock import mock
from oslotest import base from oslotest import base
from ceilometer import sample
from ceilometer.volume import notifications from ceilometer.volume import notifications
def fake_uuid(x):
return '%s-%s-%s-%s' % (x * 8, x * 4, x * 4, x * 12)
NOW = datetime.datetime.isoformat(datetime.datetime.utcnow())
VOLUME_META = {u'status': u'exists',
u'instance_uuid': None,
u'user_id': u'bcb7746c7a41472d88a1ffac89ba6a9b',
u'availability_zone': u'nova',
u'tenant_id': u'7ffe17a15c724e2aa79fc839540aec15',
u'created_at': u'2014-10-28 09:31:20',
u'volume_id': fake_uuid('c'),
u'volume_type': u'3a9a398b-7e3b-40da-b09e-2115ad8cd68b',
u'replication_extended_status': None,
u'host': u'volumes.example.com',
u'snapshot_id': None,
u'replication_status': u'disabled',
u'size': 1,
u'display_name': u'2'}
NOTIFICATION_VOLUME_EXISTS = { NOTIFICATION_VOLUME_EXISTS = {
u'_context_roles': [u'admin'], "message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
u'_context_request_id': u'req-7ef29a5d-adeb-48a8-b104-59c05361aa27', "publisher_id": "volumes.example.com",
u'_context_quota_class': None, "event_type": "volume.exists",
u'event_type': u'volume.exists', "priority": "info",
u'timestamp': u'2012-09-21 09:29:10.620731', "payload": VOLUME_META,
u'message_id': u'e0e6a5ad-2fc9-453c-b3fb-03fe504538dc', "timestamp": NOW}
u'_context_auth_token': None,
u'_context_is_admin': True,
u'_context_project_id': None,
u'_context_timestamp': u'2012-09-21T09:29:10.266928',
u'_context_read_deleted': u'no',
u'_context_user_id': None,
u'_context_remote_address': None,
u'publisher_id': u'volume.ubuntu-VirtualBox',
u'payload': {u'status': u'available',
u'audit_period_beginning': u'2012-09-20 00:00:00',
u'display_name': u'volume1',
u'tenant_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'created_at': u'2012-09-20 15:05:16',
u'snapshot_id': None,
u'volume_type': None,
u'volume_id': u'84c363b9-9854-48dc-b949-fe04263f4cf0',
u'audit_period_ending': u'2012-09-21 00:00:00',
u'user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'launched_at': u'2012-09-20 15:05:23',
u'size': 2},
u'priority': u'INFO'
}
NOTIFICATION_VOLUME_DELETE = { NOTIFICATION_VOLUME_CREATE_START = {
u'_context_roles': [u'Member', u'admin'], "message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
u'_context_request_id': u'req-6ba8ccb4-1093-4a39-b029-adfaa3fc7ceb', "publisher_id": "volumes.example.com",
u'_context_quota_class': None, "event_type": "volume.create.start",
u'event_type': u'volume.delete.start', "priority": "info",
u'timestamp': u'2012-09-21 10:24:13.168630', "payload": VOLUME_META,
u'message_id': u'f6e6bc1f-fcd5-41e1-9a86-da7d024f03d9', "timestamp": NOW}
u'_context_auth_token': u'277c6899de8a4b3d999f3e2e4c0915ff',
u'_context_is_admin': True,
u'_context_project_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'_context_timestamp': u'2012-09-21T10:23:54.741228',
u'_context_read_deleted': u'no',
u'_context_user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'_context_remote_address': u'192.168.22.101',
u'publisher_id': u'volume.ubuntu-VirtualBox',
u'payload': {u'status': u'deleting',
u'volume_type_id': None,
u'display_name': u'abc',
u'tenant_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'created_at': u'2012-09-21 10:10:47',
u'snapshot_id': None,
u'volume_id': u'3b761164-84b4-4eb3-8fcb-1974c641d6ef',
u'user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'launched_at': u'2012-09-21 10:10:50',
u'size': 3},
u'priority': u'INFO'}
NOTIFICATION_VOLUME_CREATE_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.create.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_ATTACH = { NOTIFICATION_VOLUME_DELETE_START = {
u'_context_roles': [u'Member', u'admin'], "message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
u'_context_request_id': u'req-6ba8ccb4-1093-4a39-b029-adfaa3fc7ceb', "publisher_id": "volumes.example.com",
u'_context_quota_class': None, "event_type": "volume.delete.start",
u'event_type': u'volume.attach.end', "priority": "info",
u'timestamp': u'2012-09-21 10:24:13.168630', "payload": VOLUME_META,
u'message_id': u'c994ae8d-d068-4101-bd06-1048877c844a', "timestamp": NOW}
u'_context_auth_token': u'277c6899de8a4b3d999f3e2e4c0915ff',
u'_context_is_admin': True,
u'_context_project_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'_context_timestamp': u'2012-09-21T10:02:27.134211',
u'_context_read_deleted': u'no',
u'_context_user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'_context_remote_address': u'192.168.22.101',
u'publisher_id': u'volume.ubuntu-VirtualBox',
u'payload': {u'status': u'in-use',
u'volume_type_id': None,
u'display_name': u'abc',
u'tenant_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'created_at': u'2012-09-21 10:10:47',
u'snapshot_id': None,
u'volume_id': u'3b761164-84b4-4eb3-8fcb-1974c641d6ef',
u'user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'launched_at': u'2012-09-21 10:10:50',
u'size': 3},
u'priority': u'INFO'}
NOTIFICATION_VOLUME_DELETE_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.delete.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_DETACH = { NOTIFICATION_VOLUME_RESIZE_START = {
u'_context_roles': [u'Member', u'admin'], "message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
u'_context_request_id': u'req-6ba8ccb4-1093-4a39-b029-adfaa3fc7ceb', "publisher_id": "volumes.example.com",
u'_context_quota_class': None, "event_type": "volume.resize.start",
u'event_type': u'volume.detach.end', "priority": "info",
u'timestamp': u'2012-09-21 10:24:13.168630', "payload": VOLUME_META,
u'message_id': u'c994ae8d-d068-4101-bd06-1048877c844a', "timestamp": NOW}
u'_context_auth_token': u'277c6899de8a4b3d999f3e2e4c0915ff',
u'_context_is_admin': True,
u'_context_project_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'_context_timestamp': u'2012-09-21T10:02:27.134211',
u'_context_read_deleted': u'no',
u'_context_user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'_context_remote_address': u'192.168.22.101',
u'publisher_id': u'volume.ubuntu-VirtualBox',
u'payload': {u'status': u'available',
u'volume_type_id': None,
u'display_name': u'abc',
u'tenant_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'created_at': u'2012-09-21 10:10:47',
u'snapshot_id': None,
u'volume_id': u'3b761164-84b4-4eb3-8fcb-1974c641d6ef',
u'user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'launched_at': u'2012-09-21 10:10:50',
u'size': 3},
u'priority': u'INFO'}
NOTIFICATION_VOLUME_RESIZE_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.resize.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_RESIZE = { NOTIFICATION_VOLUME_ATTACH_START = {
u'_context_roles': [u'Member', u'admin'], "message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
u'_context_request_id': u'req-6ba8ccb4-1093-4a39-b029-adfaa3fc7ceb', "publisher_id": "volumes.example.com",
u'_context_quota_class': None, "event_type": "volume.attach.start",
u'event_type': u'volume.resize.end', "priority": "info",
u'timestamp': u'2012-09-21 10:24:13.168630', "payload": VOLUME_META,
u'message_id': u'b5814258-3425-4eb7-b6b7-bf4811203e58', "timestamp": NOW}
u'_context_auth_token': u'277c6899de8a4b3d999f3e2e4c0915ff',
u'_context_is_admin': True,
u'_context_project_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'_context_timestamp': u'2012-09-21T10:02:27.134211',
u'_context_read_deleted': u'no',
u'_context_user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'_context_remote_address': u'192.168.22.101',
u'publisher_id': u'volume.ubuntu-VirtualBox',
u'payload': {u'status': u'extending',
u'volume_type_id': None,
u'display_name': u'abc',
u'tenant_id': u'6c97f1ecf17047eab696786d56a0bff5',
u'created_at': u'2012-09-21 10:10:47',
u'snapshot_id': None,
u'volume_id': u'3b761164-84b4-4eb3-8fcb-1974c641d6ef',
u'user_id': u'4d2fa4b76a4a4ecab8c468c8dea42f89',
u'launched_at': u'2012-09-21 10:10:50',
u'size': 3},
u'priority': u'INFO'}
NOTIFICATION_VOLUME_ATTACH_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.attach.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_DETACH_START = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.detach.start",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_DETACH_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.detach.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_UPDATE_START = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.update.start",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
NOTIFICATION_VOLUME_UPDATE_END = {
"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "volumes.example.com",
"event_type": "volume.update.end",
"priority": "info",
"payload": VOLUME_META,
"timestamp": NOW}
SNAPSHOT_META = {u'status': u'creating',
u'user_id': u'bcb7746c7a41472d88a1ffac89ba6a9b',
u'availability_zone': u'nova',
u'deleted': u'',
u'tenant_id': u'7ffe17a15c724e2aa79fc839540aec15',
u'created_at': u'2014-10-28 09:49:07',
u'snapshot_id': fake_uuid('c'),
u'volume_size': 1,
u'volume_id': u'2925bb3b-2b51-496a-bb6e-01a20e950e07',
u'display_name': u'11'}
NOTIFICATION_SNAPSHOT_EXISTS = { NOTIFICATION_SNAPSHOT_EXISTS = {
u'_context_roles': [u'admin'], "message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
u'_context_request_id': u'req-7ef29a5d-adeb-48a8-b104-59c05361aa27', "publisher_id": "snapshots.example.com",
u'_context_quota_class': None, "event_type": "snapshot.exists",
u'event_type': u'snapshot.exists', "priority": "info",
u'timestamp': u'2012-09-21 09:29:10.620731', "payload": SNAPSHOT_META,
u'message_id': u'e0e6a5ad-2fc9-453c-b3fb-03fe504538dc', "timestamp": NOW}
u'_context_auth_token': None,
u'_context_is_admin': True, NOTIFICATION_SNAPSHOT_CREATE_START = {
u'_context_project_id': None, "message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
u'_context_timestamp': u'2012-09-21T09:29:10.266928', "publisher_id": "snapshots.example.com",
u'_context_read_deleted': u'no', "event_type": "snapshot.create.start",
u'_context_user_id': None, "priority": "info",
u'_context_remote_address': None, "payload": SNAPSHOT_META,
u'publisher_id': u'volume.ubuntu-VirtualBox', "timestamp": NOW}
u"payload": {u"audit_period_beginning": u"2014-05-06 11:00:00",
u"audit_period_ending": u"2014-05-06 12:00:00", NOTIFICATION_SNAPSHOT_CREATE_END = {
u"availability_zone": u"left", "message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
u"created_at": u"2014-05-06 09:33:43", "publisher_id": "snapshots.example.com",
u"deleted": u"", "event_type": "snapshot.create.end",
u"display_name": "lil snapshot", "priority": "info",
u"snapshot_id": u"dd163129-9476-4cf5-9311-dd425324d8d8", "payload": SNAPSHOT_META,
u"status": u"available", "timestamp": NOW}
u"tenant_id": u"compliance",
u"user_id": u"e0271f64847b49429bb304c775c7427a", NOTIFICATION_SNAPSHOT_DELETE_START = {
u"volume_id": u"b96e026e-c9bf-4418-8d6f-4ba493bbb7d6", "message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
u"volume_size": 3}, "publisher_id": "snapshots.example.com",
u'priority': u'INFO'} "event_type": "snapshot.delete.start",
"priority": "info",
"payload": SNAPSHOT_META,
"timestamp": NOW}
NOTIFICATION_SNAPSHOT_DELETE_END = {
"message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
"publisher_id": "snapshots.example.com",
"event_type": "snapshot.delete.end",
"priority": "info",
"payload": SNAPSHOT_META,
"timestamp": NOW}
NOTIFICATION_SNAPSHOT_UPDATE_START = {
"message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
"publisher_id": "snapshots.example.com",
"event_type": "snapshot.update.start",
"priority": "info",
"payload": SNAPSHOT_META,
"timestamp": NOW}
NOTIFICATION_SNAPSHOT_UPDATE_END = {
"message_id": "1d2944f9-f8e9-4b2b-8df1-465f759a63e8",
"publisher_id": "snapshots.example.com",
"event_type": "snapshot.update.end",
"priority": "info",
"payload": SNAPSHOT_META,
"timestamp": NOW}
class TestNotifications(base.BaseTestCase): class TestNotifications(base.BaseTestCase):
def _verify_common_sample_volume(self, s, name, notification): def setUp(self):
self.assertIsNotNone(s) super(TestNotifications, self).setUp()
self.assertEqual(s.name, name) self.host = None
self.assertEqual(notification['payload']['volume_id'], s.resource_id) self.handler_crud = None
self.assertEqual(notification['timestamp'], s.timestamp) self.handler = None
metadata = s.resource_metadata self.handler_size = None
self.assertEqual(notification['publisher_id'], metadata.get('host')) self.name = None
self.name_size = None
self.size = None
def test_volume_exists(self): def _verify_common_counter(self, c, name, volume):
v = notifications.Volume(mock.Mock()) self.assertIsNotNone(c)
samples = list(v.process_notification(NOTIFICATION_VOLUME_EXISTS)) self.assertEqual(name, c.name)
self.assertEqual(1, len(samples)) self.assertEqual(fake_uuid('c'), c.resource_id)
s = samples[0] self.assertEqual(NOW, c.timestamp)
self._verify_common_sample_volume( self.assertEqual(volume, c.volume)
s, 'volume', NOTIFICATION_VOLUME_EXISTS) metadata = c.resource_metadata
self.assertEqual(1, s.volume) self.assertEqual(self.host, metadata.get('host'))
def test_volume_size_exists(self): def _check_crud(self, notification_type, notification_name):
v = notifications.VolumeSize(mock.Mock()) counters = list(self.handler_crud.process_notification(
samples = list(v.process_notification(NOTIFICATION_VOLUME_EXISTS)) notification_type))
self.assertEqual(1, len(samples)) self.assertEqual(1, len(counters))
s = samples[0] notification = counters[0]
self._verify_common_sample_volume(s, 'volume.size', self._verify_common_counter(
NOTIFICATION_VOLUME_EXISTS) notification, notification_name, 1)
self.assertEqual(NOTIFICATION_VOLUME_EXISTS['payload']['size'], self.assertEqual(sample.TYPE_DELTA, notification.type)
s.volume)
def test_volume_delete(self): def _check(self, notification_type):
v = notifications.Volume(mock.Mock()) counters = list(self.handler.process_notification(notification_type))
samples = list(v.process_notification(NOTIFICATION_VOLUME_DELETE)) self.assertEqual(1, len(counters))
self.assertEqual(1, len(samples)) notification = counters[0]
s = samples[0] self._verify_common_counter(notification, self.name, 1)
self._verify_common_sample_volume( self.assertEqual(sample.TYPE_GAUGE, notification.type)
s, 'volume', NOTIFICATION_VOLUME_DELETE)
self.assertEqual(1, s.volume)
def test_volume_size_delete(self): def _check_size(self, notification_type):
v = notifications.VolumeSize(mock.Mock()) counters = list(self.handler_size.process_notification(
samples = list(v.process_notification(NOTIFICATION_VOLUME_DELETE)) notification_type))
self.assertEqual(1, len(samples)) self.assertEqual(1, len(counters))
s = samples[0] notification = counters[0]
self._verify_common_sample_volume(s, 'volume.size', self._verify_common_counter(
NOTIFICATION_VOLUME_DELETE) notification, self.name_size, self.size)
self.assertEqual(NOTIFICATION_VOLUME_DELETE['payload']['size'], self.assertEqual(sample.TYPE_GAUGE, notification.type)
s.volume)
def test_volume_attach(self):
v = notifications.Volume(mock.Mock())
samples = list(v.process_notification(NOTIFICATION_VOLUME_ATTACH))
self.assertEqual(1, len(samples))
s = samples[0]
self._verify_common_sample_volume(
s, 'volume', NOTIFICATION_VOLUME_ATTACH)
self.assertEqual(1, s.volume)
def test_volume_size_attach(self): class TestVolumeNotifications(TestNotifications):
v = notifications.VolumeSize(mock.Mock())
samples = list(v.process_notification(NOTIFICATION_VOLUME_ATTACH))
self.assertEqual(1, len(samples))
s = samples[0]
self._verify_common_sample_volume(s, 'volume.size',
NOTIFICATION_VOLUME_ATTACH)
self.assertEqual(NOTIFICATION_VOLUME_ATTACH['payload']['size'],
s.volume)
def test_volume_detach(self): def setUp(self):
v = notifications.Volume(mock.Mock()) super(TestVolumeNotifications, self).setUp()
samples = list(v.process_notification(NOTIFICATION_VOLUME_DETACH)) self.host = 'volumes.example.com'
self.assertEqual(1, len(samples)) self.handler_crud = notifications.VolumeCRUD(mock.Mock())
s = samples[0] self.handler = notifications.Volume(mock.Mock())
self._verify_common_sample_volume( self.handler_size = notifications.VolumeSize(mock.Mock())
s, 'volume', NOTIFICATION_VOLUME_ATTACH) self.name = 'volume'
self.assertEqual(1, s.volume) self.name_size = 'volume.size'
self.size = VOLUME_META['size']
def test_volume_size_detach(self): def test_volume_notifications(self):
v = notifications.VolumeSize(mock.Mock()) self._check_crud(
samples = list(v.process_notification(NOTIFICATION_VOLUME_DETACH)) NOTIFICATION_VOLUME_EXISTS, 'volume.exists')
self.assertEqual(1, len(samples)) self._check_crud(
s = samples[0] NOTIFICATION_VOLUME_CREATE_START, 'volume.create.start')
self._verify_common_sample_volume(s, 'volume.size', self._check_crud(
NOTIFICATION_VOLUME_DETACH) NOTIFICATION_VOLUME_CREATE_END, 'volume.create.end')
self.assertEqual(NOTIFICATION_VOLUME_DETACH['payload']['size'], self._check_crud(
s.volume) NOTIFICATION_VOLUME_DELETE_START, 'volume.delete.start')
self._check_crud(
NOTIFICATION_VOLUME_DELETE_END, 'volume.delete.end')
self._check_crud(
NOTIFICATION_VOLUME_RESIZE_START, 'volume.resize.start')
self._check_crud(
NOTIFICATION_VOLUME_RESIZE_END, 'volume.resize.end')
self._check_crud(
NOTIFICATION_VOLUME_ATTACH_START, 'volume.attach.start')
self._check_crud(
NOTIFICATION_VOLUME_ATTACH_END, 'volume.attach.end')
self._check_crud(
NOTIFICATION_VOLUME_DETACH_START, 'volume.detach.start')
self._check_crud(
NOTIFICATION_VOLUME_DETACH_END, 'volume.detach.end')
self._check_crud(
NOTIFICATION_VOLUME_UPDATE_START, 'volume.update.start')
self._check_crud(
NOTIFICATION_VOLUME_UPDATE_END, 'volume.update.end')
self._check(NOTIFICATION_VOLUME_EXISTS)
self._check(NOTIFICATION_VOLUME_CREATE_START)
self._check(NOTIFICATION_VOLUME_CREATE_END)
self._check(NOTIFICATION_VOLUME_DELETE_START)
self._check(NOTIFICATION_VOLUME_DELETE_END)
self._check(NOTIFICATION_VOLUME_RESIZE_START)
self._check(NOTIFICATION_VOLUME_RESIZE_END)
self._check(NOTIFICATION_VOLUME_ATTACH_START)
self._check(NOTIFICATION_VOLUME_ATTACH_END)
self._check(NOTIFICATION_VOLUME_DETACH_START)
self._check(NOTIFICATION_VOLUME_DETACH_END)
self._check(NOTIFICATION_VOLUME_UPDATE_START)
self._check(NOTIFICATION_VOLUME_UPDATE_END)
self._check_size(NOTIFICATION_VOLUME_EXISTS)
self._check_size(NOTIFICATION_VOLUME_CREATE_START)
self._check_size(NOTIFICATION_VOLUME_CREATE_END)
self._check_size(NOTIFICATION_VOLUME_DELETE_START)
self._check_size(NOTIFICATION_VOLUME_DELETE_END)
self._check_size(NOTIFICATION_VOLUME_RESIZE_START)
self._check_size(NOTIFICATION_VOLUME_RESIZE_END)
self._check_size(NOTIFICATION_VOLUME_ATTACH_START)
self._check_size(NOTIFICATION_VOLUME_ATTACH_END)
self._check_size(NOTIFICATION_VOLUME_DETACH_START)
self._check_size(NOTIFICATION_VOLUME_DETACH_END)
self._check_size(NOTIFICATION_VOLUME_UPDATE_START)
self._check_size(NOTIFICATION_VOLUME_UPDATE_END)
def test_volume_resize(self):
v = notifications.Volume(mock.Mock())
samples = list(v.process_notification(NOTIFICATION_VOLUME_RESIZE))
self.assertEqual(1, len(samples))
s = samples[0]
self._verify_common_sample_volume(
s, 'volume', NOTIFICATION_VOLUME_RESIZE)
self.assertEqual(1, s.volume)
def test_volume_size_resize(self): class TestSnapshotNotifications(TestNotifications):
v = notifications.VolumeSize(mock.Mock())
samples = list(v.process_notification(NOTIFICATION_VOLUME_RESIZE))
self.assertEqual(1, len(samples))
s = samples[0]
self._verify_common_sample_volume(s, 'volume.size',
NOTIFICATION_VOLUME_RESIZE)
self.assertEqual(NOTIFICATION_VOLUME_RESIZE['payload']['size'],
s.volume)
def _verify_common_sample_snapshot(self, s, name, notification): def setUp(self):
self.assertIsNotNone(s) super(TestSnapshotNotifications, self).setUp()
self.assertEqual(name, s.name) self.host = 'snapshots.example.com'
self.assertEqual(notification['payload']['snapshot_id'], s.resource_id) self.handler_crud = notifications.SnapshotCRUD(mock.Mock())
self.assertEqual(notification['timestamp'], s.timestamp) self.handler = notifications.Snapshot(mock.Mock())
metadata = s.resource_metadata self.handler_size = notifications.SnapshotSize(mock.Mock())
self.assertEqual(notification['publisher_id'], metadata.get('host')) self.name = 'snapshot'
self.name_size = 'snapshot.size'
self.size = SNAPSHOT_META['volume_size']
def test_snapshot_exists(self): def test_snapshot_notifications(self):
v = notifications.Snapshot(mock.Mock()) self._check_crud(
samples = list(v.process_notification(NOTIFICATION_SNAPSHOT_EXISTS)) NOTIFICATION_SNAPSHOT_EXISTS, 'snapshot.exists')
self.assertEqual(1, len(samples)) self._check_crud(
s = samples[0] NOTIFICATION_SNAPSHOT_CREATE_START, 'snapshot.create.start')
self._verify_common_sample_snapshot(s, 'snapshot', self._check_crud(
NOTIFICATION_SNAPSHOT_EXISTS) NOTIFICATION_SNAPSHOT_CREATE_END, 'snapshot.create.end')
self.assertEqual(1, s.volume) self._check_crud(
NOTIFICATION_SNAPSHOT_DELETE_START, 'snapshot.delete.start')
def test_snapshot_size_exists(self): self._check_crud(
v = notifications.SnapshotSize(mock.Mock()) NOTIFICATION_SNAPSHOT_DELETE_END, 'snapshot.delete.end')
samples = list(v.process_notification(NOTIFICATION_SNAPSHOT_EXISTS)) self._check_crud(
self.assertEqual(1, len(samples)) NOTIFICATION_SNAPSHOT_UPDATE_START, 'snapshot.update.start')
s = samples[0] self._check_crud(
self._verify_common_sample_snapshot(s, 'snapshot.size', NOTIFICATION_SNAPSHOT_UPDATE_END, 'snapshot.update.end')
NOTIFICATION_SNAPSHOT_EXISTS) self._check(NOTIFICATION_SNAPSHOT_EXISTS)
volume_size = NOTIFICATION_SNAPSHOT_EXISTS['payload']['volume_size'] self._check(NOTIFICATION_SNAPSHOT_CREATE_START)
self.assertEqual(volume_size, s.volume) self._check(NOTIFICATION_SNAPSHOT_CREATE_END)
self._check(NOTIFICATION_SNAPSHOT_DELETE_START)
self._check(NOTIFICATION_SNAPSHOT_DELETE_END)
self._check(NOTIFICATION_SNAPSHOT_UPDATE_START)
self._check(NOTIFICATION_SNAPSHOT_UPDATE_END)
self._check_size(NOTIFICATION_SNAPSHOT_EXISTS)
self._check_size(NOTIFICATION_SNAPSHOT_CREATE_START)
self._check_size(NOTIFICATION_SNAPSHOT_CREATE_END)
self._check_size(NOTIFICATION_SNAPSHOT_DELETE_START)
self._check_size(NOTIFICATION_SNAPSHOT_DELETE_END)
self._check_size(NOTIFICATION_SNAPSHOT_UPDATE_START)
self._check_size(NOTIFICATION_SNAPSHOT_UPDATE_END)

View File

@ -24,7 +24,6 @@ import oslo.messaging
from ceilometer import plugin from ceilometer import plugin
from ceilometer import sample from ceilometer import sample
OPTS = [ OPTS = [
cfg.StrOpt('cinder_control_exchange', cfg.StrOpt('cinder_control_exchange',
default='cinder', default='cinder',
@ -35,7 +34,7 @@ OPTS = [
cfg.CONF.register_opts(OPTS) cfg.CONF.register_opts(OPTS)
class _Base(plugin.NotificationBase): class VolumeBase(plugin.NotificationBase):
"""Convert volume/snapshot notification into Counters.""" """Convert volume/snapshot notification into Counters."""
@staticmethod @staticmethod
@ -50,7 +49,7 @@ class _Base(plugin.NotificationBase):
for topic in conf.notification_topics] for topic in conf.notification_topics]
class _VolumeBase(_Base): class VolumeCRUDBase(VolumeBase):
"""Convert volume notifications into Counters.""" """Convert volume notifications into Counters."""
event_types = [ event_types = [
@ -60,10 +59,24 @@ class _VolumeBase(_Base):
'volume.resize.*', 'volume.resize.*',
'volume.attach.*', 'volume.attach.*',
'volume.detach.*', 'volume.detach.*',
'volume.update.*'
] ]
class Volume(_VolumeBase): class VolumeCRUD(VolumeCRUDBase):
def process_notification(self, message):
yield sample.Sample.from_notification(
name=message['event_type'],
type=sample.TYPE_DELTA,
unit='volume',
volume=1,
user_id=message['payload']['user_id'],
project_id=message['payload']['tenant_id'],
resource_id=message['payload']['volume_id'],
message=message)
class Volume(VolumeCRUDBase):
def process_notification(self, message): def process_notification(self, message):
yield sample.Sample.from_notification( yield sample.Sample.from_notification(
name='volume', name='volume',
@ -76,7 +89,7 @@ class Volume(_VolumeBase):
message=message) message=message)
class VolumeSize(_VolumeBase): class VolumeSize(VolumeCRUDBase):
def process_notification(self, message): def process_notification(self, message):
yield sample.Sample.from_notification( yield sample.Sample.from_notification(
name='volume.size', name='volume.size',
@ -89,18 +102,31 @@ class VolumeSize(_VolumeBase):
message=message) message=message)
class _SnapshotBase(_Base): class SnapshotCRUDBase(VolumeBase):
"""Convert snapshot notifications into Counters.""" """Convert snapshot notifications into Counters."""
event_types = [ event_types = [
'snapshot.exists', 'snapshot.exists',
'snapshot.create.*', 'snapshot.create.*',
'snapshot.delete.*', 'snapshot.delete.*',
'snapshot.resize.*', 'snapshot.update.*'
] ]
class Snapshot(_SnapshotBase): class SnapshotCRUD(SnapshotCRUDBase):
def process_notification(self, message):
yield sample.Sample.from_notification(
name=message['event_type'],
type=sample.TYPE_DELTA,
unit='snapshot',
volume=1,
user_id=message['payload']['user_id'],
project_id=message['payload']['tenant_id'],
resource_id=message['payload']['snapshot_id'],
message=message)
class Snapshot(SnapshotCRUDBase):
def process_notification(self, message): def process_notification(self, message):
yield sample.Sample.from_notification( yield sample.Sample.from_notification(
name='snapshot', name='snapshot',
@ -113,7 +139,7 @@ class Snapshot(_SnapshotBase):
message=message) message=message)
class SnapshotSize(_SnapshotBase): class SnapshotSize(SnapshotCRUDBase):
def process_notification(self, message): def process_notification(self, message):
yield sample.Sample.from_notification( yield sample.Sample.from_notification(
name='snapshot.size', name='snapshot.size',

View File

@ -49,8 +49,10 @@ ceilometer.notification =
cpu_percent = ceilometer.compute.notifications.cpu:CpuPercent cpu_percent = ceilometer.compute.notifications.cpu:CpuPercent
volume = ceilometer.volume.notifications:Volume volume = ceilometer.volume.notifications:Volume
volume_size = ceilometer.volume.notifications:VolumeSize volume_size = ceilometer.volume.notifications:VolumeSize
volume_crud = ceilometer.volume.notifications:VolumeCRUD
snapshot = ceilometer.volume.notifications:Snapshot snapshot = ceilometer.volume.notifications:Snapshot
snapshot_size = ceilometer.volume.notifications:SnapshotSize snapshot_size = ceilometer.volume.notifications:SnapshotSize
snapshot_crud = ceilometer.volume.notifications:SnapshotCRUD
authenticate = ceilometer.identity.notifications:Authenticate authenticate = ceilometer.identity.notifications:Authenticate
user = ceilometer.identity.notifications:User user = ceilometer.identity.notifications:User
group = ceilometer.identity.notifications:Group group = ceilometer.identity.notifications:Group