]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix typo so setting volume_tmp_dir works
authorJosh Durgin <josh.durgin@inktank.com>
Thu, 25 Oct 2012 23:14:07 +0000 (16:14 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Thu, 25 Oct 2012 23:25:19 +0000 (16:25 -0700)
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 <josh.durgin@inktank.com>
Change-Id: I50996c7c7a870d8e2bab1d3f44fd4d15b8ced6a6

cinder/tests/test_rbd.py
cinder/volume/driver.py

index 704e18029e0943e054db454d5e74f52737658325..4ce9cfa973766322d3a9b1dbcc03f240974ec2e1 100644 (file)
 #    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):
 
index f803ab5ea71ccf8438168f40babe6b25ef2c48f1..14022bfbfbb2b223c82c3874e71937d07edf7aec 100644 (file)
@@ -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: