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
@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
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 '
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,
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):