]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Create unique volumes_dir for testing.
authorDan Prince <dprince@redhat.com>
Tue, 7 Aug 2012 20:25:52 +0000 (16:25 -0400)
committerDan Prince <dprince@redhat.com>
Fri, 10 Aug 2012 12:49:08 +0000 (08:49 -0400)
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

index dd5f0470ae9d5d084f0583f0fb85c89bafee18b8..fde6a397a2ef540683b0ab681e37820c2a1b224b 100644 (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."""