]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove redundant db.volume_update() in volume manager create_volume()
authorZhiteng Huang <zhiteng.huang@intel.com>
Tue, 20 Nov 2012 17:02:37 +0000 (01:02 +0800)
committerZhiteng Huang <zhiteng.huang@intel.com>
Tue, 20 Nov 2012 17:55:12 +0000 (01:55 +0800)
Since scheduler has already updated db to set the 'host' field and
recorded 'scheduled_at' time, it's not necessary to do db.volume_update()
again in volume manager create_volume() method.  Also let volume api
to update db when creating volume from snapshot while snapshot_same_host
is true, thus the behavior is consistent (updating db when placement
decision is made).

Change-Id: I43aaee8e2a5d0ceadb98bd608cc147467488349e

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

index 2b1231330c503f6b8852e2bff8557dee9a18b92b..c5188d8e28bf620c7805efc05a868fae30ac268e 100644 (file)
@@ -85,6 +85,7 @@ class VolumeTestCase(test.TestCase):
         vol['availability_zone'] = FLAGS.storage_availability_zone
         vol['status'] = "creating"
         vol['attach_status'] = "detached"
+        vol['host'] = FLAGS.host
         if metadata is not None:
             vol['metadata'] = metadata
         return db.volume_create(context.get_admin_context(), vol)
index 627f17b3567a67aa7634db80510447493e77aa00..1bdb165cf354379ec466a6379341857aa50fbc1d 100644 (file)
@@ -207,12 +207,14 @@ class API(base.Base):
             snapshot_ref = self.db.snapshot_get(context, snapshot_id)
             src_volume_ref = self.db.volume_get(context,
                                                 snapshot_ref['volume_id'])
-            volume_ref = self.db.volume_get(context,
-                                            volume_id)
+            now = timeutils.utcnow()
+            values = {'host': src_volume_ref['host'], 'scheduled_at': now}
+            volume_ref = self.db.volume_update(context, volume_id, values)
+
             # bypass scheduler and send request directly to volume
             self.volume_rpcapi.create_volume(context,
                                             volume_ref,
-                                            src_volume_ref['host'],
+                                            volume_ref['host'],
                                             snapshot_id,
                                             image_id)
         else:
index 7e5c2bb56429a00b209847d0c891aa6db56db042..40913763b5b7af174eaf6fb7bff3f7ce5f99b7af 100644 (file)
@@ -125,9 +125,6 @@ class VolumeManager(manager.SchedulerDependentManager):
         self._notify_about_volume_usage(context, volume_ref, "create.start")
         LOG.info(_("volume %s: creating"), volume_ref['name'])
 
-        self.db.volume_update(context,
-                              volume_id,
-                              {'host': self.host})
         # NOTE(vish): so we don't have to get volume from db again
         #             before passing it to the driver.
         volume_ref['host'] = self.host