]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update and add notifiers in create volume
authorjenny-shieh <jenny.shieh@hp.com>
Thu, 13 Jun 2013 22:04:59 +0000 (15:04 -0700)
committerjenny-shieh <jenny.shieh@hp.com>
Fri, 14 Jun 2013 18:58:04 +0000 (11:58 -0700)
1. Change status from 'creating' to 'available' when the volume is created
2. Add a notifier when it fails to create the volume

Implements: notifiers for create volume
Fixes: bug #1190754
Change-Id: I3a7d118630b32cfa7efb6bc8984418ca9836764a

cinder/tests/test_volume.py
cinder/volume/manager.py

index 64761e83100be3e2e3cd94fd7977c2606d9c11b3..bdfe0154d58d49e205d21891f67b46602c5ed607 100644 (file)
@@ -144,7 +144,7 @@ class VolumeTestCase(test.TestCase):
         msg = test_notifier.NOTIFICATIONS[1]
         self.assertEqual(msg['event_type'], 'volume.create.end')
         expected = {
-            'status': 'creating',
+            'status': 'available',
             'display_name': None,
             'availability_zone': 'nova',
             'tenant_id': 'fake',
index e986b7cd0ee671690b8abe263cfca79deb52efb1..678d9892a31ad7fd5cb76dd792bf9cb91a3fdf8e 100644 (file)
@@ -287,9 +287,13 @@ class VolumeManager(manager.SchedulerDependentManager):
                 self.db.volume_update(context, volume_ref['id'], model_update)
         except Exception:
             with excutils.save_and_reraise_exception():
+                volume_ref['status'] = 'error'
                 self.db.volume_update(context,
-                                      volume_ref['id'], {'status': 'error'})
+                                      volume_ref['id'],
+                                      {'status': volume_ref['status']})
                 LOG.error(_("volume %s: create failed"), volume_ref['name'])
+                self._notify_about_volume_usage(context, volume_ref,
+                                                "create.end")
 
         if snapshot_id:
             # Copy any Glance metadata from the original volume
@@ -315,9 +319,11 @@ class VolumeManager(manager.SchedulerDependentManager):
                                                       key, value)
 
         now = timeutils.utcnow()
+        volume_ref['status'] = status
         self.db.volume_update(context,
-                              volume_ref['id'], {'status': status,
-                                                 'launched_at': now})
+                              volume_ref['id'],
+                              {'status': volume_ref['status'],
+                              'launched_at': now})
         LOG.info(_("volume %s: created successfully"), volume_ref['name'])
         self._reset_stats()