Create unique volumes_dir for testing.

Updates test_volume.py so that we create a uniq volumes_dir for testing.
This avoids polluting the source tree with fake volume UUID's when running
tests.

Change-Id: I3c37083915effec0eff7c8d9bfffb9f7674fe6f5
This commit is contained in:
Dan Prince 2012-08-07 16:25:52 -04:00
parent 6773b92c4e
commit 69aa04d1f8

View File

@ -24,6 +24,8 @@ import cStringIO
import logging
import mox
import shutil
import tempfile
from cinder import context
from cinder import exception
@ -45,11 +47,17 @@ class VolumeTestCase(test.TestCase):
def setUp(self):
super(VolumeTestCase, self).setUp()
self.flags(connection_type='fake')
vol_tmpdir = tempfile.mkdtemp()
self.flags(connection_type='fake',
volumes_dir=vol_tmpdir)
self.volume = importutils.import_object(FLAGS.volume_manager)
self.context = context.get_admin_context()
def tearDown(self):
try:
shutil.rmtree(FLAGS.volumes_dir)
except OSError, e:
pass
super(VolumeTestCase, self).tearDown()
@staticmethod
@ -360,7 +368,9 @@ class DriverTestCase(test.TestCase):
def setUp(self):
super(DriverTestCase, self).setUp()
vol_tmpdir = tempfile.mkdtemp()
self.flags(volume_driver=self.driver_name,
volumes_dir=vol_tmpdir,
logging_default_format_string="%(message)s")
self.volume = importutils.import_object(FLAGS.volume_manager)
self.context = context.get_admin_context()
@ -375,6 +385,13 @@ class DriverTestCase(test.TestCase):
self.stream = cStringIO.StringIO()
log.addHandler(logging.StreamHandler(self.stream))
def tearDown(self):
try:
shutil.rmtree(FLAGS.volumes_dir)
except OSError, e:
pass
super(DriverTestCase, self).tearDown()
def _attach_volume(self):
"""Attach volumes to an instance. This function also sets
a fake log message."""