]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Ensure name is utf-8 when deleting rbd vol or snap
authorEdward Hope-Morley <edward.hope-morley@canonical.com>
Fri, 14 Mar 2014 10:07:45 +0000 (10:07 +0000)
committerEdward Hope-Morley <edward.hope-morley@canonical.com>
Fri, 14 Mar 2014 10:21:05 +0000 (10:21 +0000)
If the name supplied to librbd is not utf-8 e.g. unicode,
an exception is raised. This was previously fixed and
subsequently broken by commit cbe1d5f.

Change-Id: I29f5e9db87ceb5f9cfe3be43e76d3e860edaf6d7
Closes-Bug: bug 1292433

cinder/volume/drivers/rbd.py

index f0646d16445b5a6e94cd8ae065de00a8af693d0e..1a2b9f999b3013acef5f0d807b5481e89bf41ced 100644 (file)
@@ -26,6 +26,7 @@ from cinder import exception
 from cinder.image import image_utils
 from cinder.openstack.common import fileutils
 from cinder.openstack.common import log as logging
+from cinder.openstack.common import strutils
 from cinder import units
 from cinder.volume import driver
 
@@ -585,7 +586,9 @@ class RBDDriver(driver.VolumeDriver):
 
     def delete_volume(self, volume):
         """Deletes a logical volume."""
-        volume_name = volume['name']
+        # NOTE(dosaboy): this was broken by commit cbe1d5f. Ensure names are
+        #                utf-8 otherwise librbd will barf.
+        volume_name = strutils.safe_encode(volume['name'])
         with RADOSClient(self) as client:
             try:
                 rbd_image = self.rbd.Image(client.ioctx, volume_name)
@@ -658,14 +661,17 @@ class RBDDriver(driver.VolumeDriver):
 
     def delete_snapshot(self, snapshot):
         """Deletes an rbd snapshot."""
-        with RBDVolumeProxy(self, snapshot['volume_name']) as volume:
-            snap = snapshot['name']
+        # NOTE(dosaboy): this was broken by commit cbe1d5f. Ensure names are
+        #                utf-8 otherwise librbd will barf.
+        volume_name = strutils.safe_encode(snapshot['volume_name'])
+        snap_name = strutils.safe_encode(snapshot['name'])
+        with RBDVolumeProxy(self, volume_name) as volume:
             if self._supports_layering():
                 try:
-                    volume.unprotect_snap(snap)
+                    volume.unprotect_snap(snap_name)
                 except self.rbd.ImageBusy:
-                    raise exception.SnapshotIsBusy(snapshot_name=snap)
-            volume.remove_snap(snap)
+                    raise exception.SnapshotIsBusy(snapshot_name=snap_name)
+            volume.remove_snap(snap_name)
 
     def ensure_export(self, context, volume):
         """Synchronously recreates an export for a logical volume."""