From 69aa04d1f89c838d2ea1c96e715e175fb26f0883 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Tue, 7 Aug 2012 16:25:52 -0400 Subject: [PATCH] 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 --- cinder/tests/test_volume.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index dd5f0470a..fde6a397a 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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.""" -- 2.45.2