From 57637c60181c2b621771bbf751f811228ae9c433 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 3 Aug 2012 15:26:03 -0400 Subject: Create unique volumes_dir for testing. Updates several Nova volume test classes so that we create a unique volumes_dir for testing. This avoids polluting the source tree with fake volume UUID's when running tests. Note: I opted to go utils.tempdir in test_volume (which seemed cleaner). I did not however use utils.tempdir in the other test modules since it would have required a good be more reformatting effort... Change-Id: I24a53c28c52156750cf65942639af0b15fbeefc1 --- nova/tests/api/ec2/test_cinder_cloud.py | 8 ++++++++ nova/tests/api/ec2/test_cloud.py | 7 +++++++ nova/tests/test_volume.py | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/nova/tests/api/ec2/test_cinder_cloud.py b/nova/tests/api/ec2/test_cinder_cloud.py index fe684d7cd..ed05b7a94 100644 --- a/nova/tests/api/ec2/test_cinder_cloud.py +++ b/nova/tests/api/ec2/test_cinder_cloud.py @@ -18,6 +18,8 @@ # under the License. import copy +import shutil +import tempfile from nova.api.ec2 import cloud from nova.api.ec2 import ec2utils @@ -80,8 +82,10 @@ def get_instances_with_cached_ips(orig_func, *args, **kwargs): class CinderCloudTestCase(test.TestCase): def setUp(self): super(CinderCloudTestCase, self).setUp() + vol_tmpdir = tempfile.mkdtemp() self.flags(compute_driver='nova.virt.fake.FakeDriver', volume_api_class='nova.tests.fake_volume.API', + volumes_dir=vol_tmpdir, stub_network=True) def fake_show(meh, context, id): @@ -136,6 +140,10 @@ class CinderCloudTestCase(test.TestCase): '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6') def tearDown(self): + try: + shutil.rmtree(FLAGS.volumes_dir) + except OSError, e: + pass self.volume_api.reset_fake_api(self.context) super(CinderCloudTestCase, self).tearDown() fake.FakeImageService_reset() diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index ef78c007b..f4f8879f6 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -22,6 +22,7 @@ import copy import datetime import functools import os +import shutil import string import tempfile @@ -92,7 +93,9 @@ def get_instances_with_cached_ips(orig_func, *args, **kwargs): class CloudTestCase(test.TestCase): def setUp(self): super(CloudTestCase, self).setUp() + vol_tmpdir = tempfile.mkdtemp() self.flags(compute_driver='nova.virt.fake.FakeDriver', + volumes_dir=vol_tmpdir, stub_network=True) def fake_show(meh, context, id): @@ -146,6 +149,10 @@ class CloudTestCase(test.TestCase): '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6') def tearDown(self): + try: + shutil.rmtree(FLAGS.volumes_dir) + except OSError, e: + pass super(CloudTestCase, self).tearDown() fake.FakeImageService_reset() diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py index 57ca52786..00e2606cb 100644 --- a/nova/tests/test_volume.py +++ b/nova/tests/test_volume.py @@ -23,6 +23,8 @@ Tests for Volume Code. import cStringIO import mox +import shutil +import tempfile from nova import context from nova import db @@ -49,7 +51,9 @@ class VolumeTestCase(test.TestCase): def setUp(self): super(VolumeTestCase, self).setUp() self.compute = importutils.import_object(FLAGS.compute_manager) - self.flags(compute_driver='nova.virt.fake.FakeDriver') + vol_tmpdir = tempfile.mkdtemp() + self.flags(compute_driver='nova.virt.fake.FakeDriver', + volumes_dir=vol_tmpdir) self.stubs.Set(nova.flags.FLAGS, 'notification_driver', ['nova.openstack.common.notifier.test_notifier']) self.volume = importutils.import_object(FLAGS.volume_manager) @@ -60,6 +64,10 @@ class VolumeTestCase(test.TestCase): test_notifier.NOTIFICATIONS = [] def tearDown(self): + try: + shutil.rmtree(FLAGS.volumes_dir) + except OSError, e: + pass db.instance_destroy(self.context, self.instance_uuid) notifier_api._reset_drivers() super(VolumeTestCase, self).tearDown() @@ -454,7 +462,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() @@ -474,6 +484,13 @@ class DriverTestCase(test.TestCase): self.instance_id = instance['id'] self.instance_uuid = instance['uuid'] + 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.""" -- cgit