]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
RBD: use image_conversion_dir for image operations
authorJon Bernard <jobernar@redhat.com>
Thu, 9 Oct 2014 18:44:38 +0000 (14:44 -0400)
committerJon Bernard <jobernar@redhat.com>
Fri, 19 Dec 2014 21:11:45 +0000 (16:11 -0500)
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
cinder/volume/drivers/rbd.py

index 544696008b611d8e6ebffa86ba01432ee06f26fc..7b14e18bb5f6108cdece70b26d37ac80408576ab 100644 (file)
@@ -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
index ba7ae4ea1874f62aa35fd467b1479751095f9ef5..bf191614902c95b0ef422780ab41d950203cd7c1 100644 (file)
@@ -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):