From: Edward Hope-Morley Date: Fri, 14 Mar 2014 10:07:45 +0000 (+0000) Subject: Ensure name is utf-8 when deleting rbd vol or snap X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=c0f8cc39fc92517d1402d9eb82d9319c6cb72842;p=openstack-build%2Fcinder-build.git Ensure name is utf-8 when deleting rbd vol or snap 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 --- diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index f0646d164..1a2b9f999 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -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."""