]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Emit notifications for volume retype
authorEd Balduf <ed.balduf@solidfire.com>
Sat, 12 Mar 2016 03:56:08 +0000 (20:56 -0700)
committerEd Balduf <ed.balduf@solidfire.com>
Sat, 12 Mar 2016 03:56:08 +0000 (20:56 -0700)
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
cinder/volume/manager.py

index ff0134d21d0f1fcba47c47495d8c3c330506260b..6f9650594434fb9efc6a9ae76fd3c08dfbad9caa 100644 (file)
@@ -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)
index 102fcdbf45c2d50799cf3a00751fd068de99e89d..63e64535c94824c007f36d25e5133cafe3a703f0 100644 (file)
@@ -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)