]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Don't leave snapshots on the floor
authorJohn Griffith <john.griffith@solidfire.com>
Wed, 16 Jul 2014 14:49:37 +0000 (08:49 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Wed, 16 Jul 2014 14:49:37 +0000 (08:49 -0600)
The current cloning process in the LVM
driver uses a snapshot to do the data
copy in the background.  Trouble here
is that if the creation or activation
of the new volume fails, we don't
cleanup the snapshot we created.

Just move the create_volume and activate
calls down into the try block so the finally
clause can do the cleanup for us.

Change-Id: If0fbab9d9f39102cdc7d287527be22c4a2b35934
Closes-Bug: #1312718

cinder/volume/drivers/lvm.py

index bdfe12d2413c9b4d7808bddfabfc6e8af35fe2ae..47ac5910fd001746e14d1572616977352a1089fb 100644 (file)
@@ -291,16 +291,17 @@ class LVMVolumeDriver(driver.VolumeDriver):
                          'id': temp_id}
 
         self.create_snapshot(temp_snapshot)
-        self._create_volume(volume['name'],
-                            self._sizestr(volume['size']),
-                            self.configuration.lvm_type,
-                            mirror_count)
-
-        self.vg.activate_lv(temp_snapshot['name'], is_snapshot=True)
 
         # copy_volume expects sizes in MiB, we store integer GiB
         # be sure to convert before passing in
         try:
+            self._create_volume(volume['name'],
+                                self._sizestr(volume['size']),
+                                self.configuration.lvm_type,
+                                mirror_count)
+
+            self.vg.activate_lv(temp_snapshot['name'], is_snapshot=True)
+
             volutils.copy_volume(
                 self.local_path(temp_snapshot),
                 self.local_path(volume),