From 46c00f5c0c918dc967292c50d81d1e300f845223 Mon Sep 17 00:00:00 2001 From: Ed Balduf Date: Fri, 11 Mar 2016 20:56:08 -0700 Subject: [PATCH] Emit notifications for volume retype Emit a notification for volume retype when retype is sucessful. The event contains the new volume type to allow proper billing. Change-Id: I46590f214e42e187458d06b27fc07adfa49c0b62 Closes-Bug: #1555722 --- cinder/tests/unit/test_volume.py | 19 +++++++++++++++++++ cinder/volume/manager.py | 3 +++ 2 files changed, 22 insertions(+) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index ff0134d21..6f9650594 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -4868,6 +4868,8 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): self.context, volume, new_vol_type['id']) volume = db.volume_get(elevated, volume.id) + self.assertEqual(0, len(self.notifier.notifications), + self.notifier.notifications) self.assertEqual('available', volume['status']) def _retype_volume_exec(self, driver, snap=False, policy='on-demand', @@ -4982,16 +4984,33 @@ class VolumeMigrationTestCase(BaseVolumeTestCase): self.assertEqual('available', volume.status) self.assertEqual(CONF.host, volume.host) self.assertEqual(1, volumes_in_use) + self.assertEqual(1, len(self.notifier.notifications), + "Notifier count incorrect %s" % + (self.notifier.notifications)) + self.assertEqual(vol_type['id'], self.notifier.notifications[0] + ['payload']['volume_type']) + self.assertEqual('volume.retype', self.notifier.notifications[0] + ['event_type']) elif not exc: self.assertEqual(old_vol_type['id'], volume.volume_type_id) self.assertEqual('retyping', volume.status) self.assertEqual(CONF.host, volume.host) self.assertEqual(1, volumes_in_use) + self.assertEqual(1, len(self.notifier.notifications), + "Notifier count incorrect %s" % + (self.notifier.notifications)) + self.assertEqual(vol_type['id'], self.notifier.notifications[0] + ['payload']['volume_type']) + self.assertEqual('volume.retype', self.notifier.notifications[0] + ['event_type']) else: self.assertEqual(old_vol_type['id'], volume.volume_type_id) self.assertEqual('available', volume.status) self.assertEqual(CONF.host, volume.host) self.assertEqual(0, volumes_in_use) + self.assertEqual(0, len(self.notifier.notifications), + "Notifier count incorrect %s" % + (self.notifier.notifications)) def test_retype_volume_driver_success(self): self._retype_volume_exec(True) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 102fcdbf4..63e64535c 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -2317,6 +2317,9 @@ class VolumeManager(manager.SchedulerDependentManager): QUOTAS.commit(context, old_reservations, project_id=project_id) if new_reservations: QUOTAS.commit(context, new_reservations, project_id=project_id) + self._notify_about_volume_usage( + context, volume, "retype", + extra_usage_info={'volume_type': new_type_id}) self.publish_service_capabilities(context) LOG.info(_LI("Retype volume completed successfully."), resource=volume) -- 2.45.2