Skip to content

Commit

Permalink
Fix typo so setting volume_tmp_dir works
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jdurgin committed Oct 25, 2012
1 parent 628adc9 commit 452b92a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions cinder/tests/test_rbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +31,11 @@
LOG = logging.getLogger(__name__)


class FakeImageService:
def download(self, context, image_id, path):
pass


class RBDTestCase(test.TestCase):

def setUp(self):
Expand Down Expand Up @@ -77,6 +86,26 @@ def fake_exc(*args):
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):

Expand Down
2 changes: 1 addition & 1 deletion cinder/volume/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def copy_image_to_volume(self, context, volume, image_service, image_id):
# 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:
Expand Down

0 comments on commit 452b92a

Please sign in to comment.