From 414c3a90eaa30af637d8b0748c4902a58d7c191d Mon Sep 17 00:00:00 2001 From: Jon Bernard Date: Thu, 9 Oct 2014 14:44:38 -0400 Subject: [PATCH] RBD: use image_conversion_dir for image operations This patch deprecates the rbd-only 'volume_tmp_dir' from the rbd driver in favor of image_conversion_dir for image operations. Closes-Bug: #1375490 DocImpact: config option removal Change-Id: I46ab21c2a90be136d1eb677fcefcc3d65c48a3c5 --- cinder/tests/test_rbd.py | 5 ++++- cinder/volume/drivers/rbd.py | 29 +++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cinder/tests/test_rbd.py b/cinder/tests/test_rbd.py index 544696008..7b14e18bb 100644 --- a/cinder/tests/test_rbd.py +++ b/cinder/tests/test_rbd.py @@ -133,6 +133,7 @@ class RBDTestCase(test.TestCase): self.cfg = mock.Mock(spec=conf.Configuration) self.cfg.volume_tmp_dir = None + self.cfg.image_conversion_dir = None self.cfg.rbd_pool = 'rbd' self.cfg.rbd_ceph_conf = None self.cfg.rbd_secret_uuid = None @@ -634,11 +635,13 @@ class RBDTestCase(test.TestCase): @common_mocks def test_copy_image_no_volume_tmp(self): self.cfg.volume_tmp_dir = None + self.cfg.image_conversion_dir = None self._copy_image() @common_mocks def test_copy_image_volume_tmp(self): - self.cfg.volume_tmp_dir = '/var/run/cinder/tmp' + self.cfg.volume_tmp_dir = None + self.cfg.image_conversion_dir = '/var/run/cinder/tmp' self._copy_image() @common_mocks diff --git a/cinder/volume/drivers/rbd.py b/cinder/volume/drivers/rbd.py index ba7ae4ea1..bf1916149 100644 --- a/cinder/volume/drivers/rbd.py +++ b/cinder/volume/drivers/rbd.py @@ -66,7 +66,8 @@ rbd_opts = [ default=None, help='Directory where temporary image files are stored ' 'when the volume driver does not write them directly ' - 'to the volume.'), + 'to the volume. Warning: this option is now deprecated, ' + 'please use image_conversion_dir instead.'), cfg.IntOpt('rbd_max_clone_depth', default=5, help='Maximum number of nested volume clones that are ' @@ -814,14 +815,24 @@ class RBDDriver(driver.VolumeDriver): self._resize(volume) return {'provider_location': None}, True - def _ensure_tmp_exists(self): - tmp_dir = self.configuration.volume_tmp_dir - if tmp_dir and not os.path.exists(tmp_dir): - os.makedirs(tmp_dir) + def _image_conversion_dir(self): + tmpdir = (self.configuration.volume_tmp_dir or + CONF.image_conversion_dir or + tempfile.gettempdir()) + + if (tmpdir == self.configuration.volume_tmp_dir): + LOG.warn(_LW('volume_tmp_dir is now deprecated, please use ' + 'image_conversion_dir')) + + # ensure temporary directory exists + if not os.path.exists(tmpdir): + os.makedirs(tmpdir) + + return tmpdir def copy_image_to_volume(self, context, volume, image_service, image_id): - self._ensure_tmp_exists() - tmp_dir = self.configuration.volume_tmp_dir + + tmp_dir = self._image_conversion_dir() with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp: image_utils.fetch_to_raw(context, image_service, image_id, @@ -846,9 +857,7 @@ class RBDDriver(driver.VolumeDriver): self._resize(volume) def copy_volume_to_image(self, context, volume, image_service, image_meta): - self._ensure_tmp_exists() - - tmp_dir = self.configuration.volume_tmp_dir or '/tmp' + tmp_dir = self._image_conversion_dir() tmp_file = os.path.join(tmp_dir, volume['name'] + '-' + image_meta['id']) with fileutils.remove_path_on_error(tmp_file): -- 2.45.2