From: Josh Durgin Date: Thu, 25 Oct 2012 23:14:07 +0000 (-0700) Subject: Fix typo so setting volume_tmp_dir works X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=452b92a13bcf4cc2afdf97c742f0773455608a26;p=openstack-build%2Fcinder-build.git Fix typo so setting volume_tmp_dir works This can be controlled by environment variables without setting volume_tmp_dir as well, so there's an easy workaround for Folsom. Fixes LP bug #1071536 Signed-off-by: Josh Durgin Change-Id: I50996c7c7a870d8e2bab1d3f44fd4d15b8ced6a6 --- diff --git a/cinder/tests/test_rbd.py b/cinder/tests/test_rbd.py index 704e18029..4ce9cfa97 100644 --- a/cinder/tests/test_rbd.py +++ b/cinder/tests/test_rbd.py @@ -15,6 +15,10 @@ # License for the specific language governing permissions and limitations # under the License. +import contextlib +import os +import tempfile + from cinder import db from cinder import exception from cinder.openstack.common import log as logging @@ -27,6 +31,11 @@ from cinder.volume.driver import RBDDriver LOG = logging.getLogger(__name__) +class FakeImageService: + def download(self, context, image_id, path): + pass + + class RBDTestCase(test.TestCase): def setUp(self): @@ -77,6 +86,26 @@ class RBDTestCase(test.TestCase): location = 'rbd://abc/pool/image/snap' self.assertFalse(self.driver._is_cloneable(location)) + def _copy_image(self): + @contextlib.contextmanager + def fake_temp_file(dir): + class FakeTmp: + def __init__(self, name): + self.name = name + yield FakeTmp('test') + self.stubs.Set(tempfile, 'NamedTemporaryFile', fake_temp_file) + self.stubs.Set(os.path, 'exists', lambda x: True) + self.driver.copy_image_to_volume(None, {'name': 'test'}, + FakeImageService(), None) + + def test_copy_image_no_volume_tmp(self): + self.flags(volume_tmp_dir=None) + self._copy_image() + + def test_copy_image_volume_tmp(self): + self.flags(volume_tmp_dir='/var/run/cinder/tmp') + self._copy_image() + class FakeRBDDriver(RBDDriver): diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index f803ab5ea..14022bfbf 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -759,7 +759,7 @@ class RBDDriver(VolumeDriver): # TODO(jdurgin): replace with librbd # this is a temporary hack, since rewriting this driver # to use librbd would take too long - if FLAGS.volume_tmp_dir and not os.exists(FLAGS.volume_tmp_dir): + if FLAGS.volume_tmp_dir and not os.path.exists(FLAGS.volume_tmp_dir): os.makedirs(FLAGS.volume_tmp_dir) with tempfile.NamedTemporaryFile(dir=FLAGS.volume_tmp_dir) as tmp: