summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2012-11-09 15:49:51 +0100
committerMonty Taylor <mordred@inaugust.com>2012-12-07 23:14:58 -0800
commit70965c3ec5a562200fa414aa25a0a8bc99d20d90 (patch)
tree59cab6958f2f328d7c35475c9d499d356e806c5e /nova/tests
parent86cc905734f81c5363c1dc86ea2bba662bb18892 (diff)
Use fixtures library for nova test fixtures.
Moving the test-case setup and teardown code into managed fixtures so that we can better interact with them when we start running things in parallel. Part of blueprint grizzly-testtools Change-Id: I406be0a88b14c0dba2d22b4957e26a53442bbae3
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_rpcapi.py2
-rw-r--r--nova/tests/conf_fixture.py66
-rw-r--r--nova/tests/fake_flags.py49
-rw-r--r--nova/tests/integrated/integrated_helpers.py2
-rw-r--r--nova/tests/network/test_manager.py5
-rw-r--r--nova/tests/test_imagecache.py2
-rw-r--r--nova/tests/test_test.py2
-rw-r--r--nova/tests/xenapi/stubs.py2
8 files changed, 74 insertions, 56 deletions
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index 54d8d47c7..437daaa14 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -33,11 +33,11 @@ CONF.import_opt('compute_topic', 'nova.config')
class ComputeRpcAPITestCase(test.TestCase):
def setUp(self):
+ super(ComputeRpcAPITestCase, self).setUp()
self.context = context.get_admin_context()
inst = db.instance_create(self.context, {'host': 'fake_host',
'instance_type_id': 1})
self.fake_instance = jsonutils.to_primitive(inst)
- super(ComputeRpcAPITestCase, self).setUp()
def test_serialized_instance_has_name(self):
self.assertTrue('name' in self.fake_instance)
diff --git a/nova/tests/conf_fixture.py b/nova/tests/conf_fixture.py
new file mode 100644
index 000000000..c0466447d
--- /dev/null
+++ b/nova/tests/conf_fixture.py
@@ -0,0 +1,66 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import fixtures
+
+from nova import config
+from nova.openstack.common import cfg
+
+CONF = cfg.CONF
+CONF.import_opt('state_path', 'nova.config')
+CONF.import_opt('scheduler_driver', 'nova.scheduler.manager')
+CONF.import_opt('fake_network', 'nova.network.manager')
+CONF.import_opt('network_size', 'nova.network.manager')
+CONF.import_opt('num_networks', 'nova.network.manager')
+CONF.import_opt('policy_file', 'nova.policy')
+CONF.import_opt('compute_driver', 'nova.virt.driver')
+
+
+class ConfFixture(fixtures.Fixture):
+ """Fixture to manage global conf settings."""
+
+ def __init__(self, conf):
+ self.conf = conf
+
+ def setUp(self):
+ super(ConfFixture, self).setUp()
+
+ self.conf.set_default('api_paste_config',
+ '$state_path/etc/nova/api-paste.ini')
+ self.conf.set_default('compute_driver', 'nova.virt.fake.FakeDriver')
+ self.conf.set_default('fake_network', True)
+ self.conf.set_default('fake_rabbit', True)
+ self.conf.set_default('flat_network_bridge', 'br100')
+ self.conf.set_default('floating_ip_dns_manager',
+ 'nova.tests.utils.dns_manager')
+ self.conf.set_default('instance_dns_manager',
+ 'nova.tests.utils.dns_manager')
+ self.conf.set_default('lock_path', None)
+ self.conf.set_default('network_size', 8)
+ self.conf.set_default('num_networks', 2)
+ self.conf.set_default('rpc_backend',
+ 'nova.openstack.common.rpc.impl_fake')
+ self.conf.set_default('rpc_cast_timeout', 5)
+ self.conf.set_default('rpc_response_timeout', 5)
+ self.conf.set_default('sql_connection', "sqlite://")
+ self.conf.set_default('sqlite_synchronous', False)
+ self.conf.set_default('use_ipv6', True)
+ self.conf.set_default('verbose', True)
+ self.conf.set_default('vlan_interface', 'eth0')
+ config.parse_args([], default_config_files=[])
+ self.addCleanup(self.conf.reset)
diff --git a/nova/tests/fake_flags.py b/nova/tests/fake_flags.py
deleted file mode 100644
index 83ec33cab..000000000
--- a/nova/tests/fake_flags.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2010 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from nova.openstack.common import cfg
-
-CONF = cfg.CONF
-CONF.import_opt('state_path', 'nova.config')
-CONF.import_opt('scheduler_driver', 'nova.scheduler.manager')
-CONF.import_opt('fake_network', 'nova.network.manager')
-CONF.import_opt('network_size', 'nova.network.manager')
-CONF.import_opt('num_networks', 'nova.network.manager')
-CONF.import_opt('policy_file', 'nova.policy')
-CONF.import_opt('compute_driver', 'nova.virt.driver')
-
-
-def set_defaults(conf):
- conf.set_default('api_paste_config', '$state_path/etc/nova/api-paste.ini')
- conf.set_default('compute_driver', 'nova.virt.fake.FakeDriver')
- conf.set_default('fake_network', True)
- conf.set_default('fake_rabbit', True)
- conf.set_default('flat_network_bridge', 'br100')
- conf.set_default('network_size', 8)
- conf.set_default('num_networks', 2)
- conf.set_default('vlan_interface', 'eth0')
- conf.set_default('rpc_backend', 'nova.openstack.common.rpc.impl_fake')
- conf.set_default('sql_connection', "sqlite://")
- conf.set_default('sqlite_synchronous', False)
- conf.set_default('use_ipv6', True)
- conf.set_default('verbose', True)
- conf.set_default('rpc_response_timeout', 5)
- conf.set_default('rpc_cast_timeout', 5)
- conf.set_default('lock_path', None)
- conf.set_default('floating_ip_dns_manager', 'nova.tests.utils.dns_manager')
- conf.set_default('instance_dns_manager', 'nova.tests.utils.dns_manager')
diff --git a/nova/tests/integrated/integrated_helpers.py b/nova/tests/integrated/integrated_helpers.py
index 7c316aaa8..1f6a278cf 100644
--- a/nova/tests/integrated/integrated_helpers.py
+++ b/nova/tests/integrated/integrated_helpers.py
@@ -67,7 +67,7 @@ class _IntegratedTestBase(test.TestCase):
self.flags(**f)
self.flags(verbose=True)
- self.stub_module('crypto', fake_crypto)
+ self.useFixture(test.ReplaceModule('crypto', fake_crypto))
nova.tests.image.fake.stub_out_image_service(self.stubs)
self.flags(scheduler_driver='nova.scheduler.'
'chance.ChanceScheduler')
diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py
index b12d12167..2c04806b7 100644
--- a/nova/tests/network/test_manager.py
+++ b/nova/tests/network/test_manager.py
@@ -15,10 +15,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
-import mox
import shutil
import tempfile
+import mox
+
from nova import context
from nova import db
from nova.db.sqlalchemy import models
@@ -1998,7 +1999,7 @@ class LdapDNSTestCase(test.TestCase):
def setUp(self):
super(LdapDNSTestCase, self).setUp()
- self.stub_module('ldap', fake_ldap)
+ self.useFixture(test.ReplaceModule('ldap', fake_ldap))
dns_class = 'nova.network.ldapdns.LdapDNS'
self.driver = importutils.import_object(dns_class)
diff --git a/nova/tests/test_imagecache.py b/nova/tests/test_imagecache.py
index 2a927b362..bfa948ce5 100644
--- a/nova/tests/test_imagecache.py
+++ b/nova/tests/test_imagecache.py
@@ -763,7 +763,7 @@ class ImageCacheManagerTestCase(test.TestCase):
def listdir(path):
# The python coverage tool got angry with my overly broad mocks
if not path.startswith('/instance_path'):
- return orig_list(path)
+ return orig_listdir(path)
if path == '/instance_path':
return ['instance-1', 'instance-2', 'instance-3', '_base']
diff --git a/nova/tests/test_test.py b/nova/tests/test_test.py
index f89a5bb94..2e045b2ac 100644
--- a/nova/tests/test_test.py
+++ b/nova/tests/test_test.py
@@ -30,7 +30,7 @@ class IsolationTestCase(test.TestCase):
"""
def test_service_isolation(self):
- self.start_service('compute')
+ self.useFixture(test.ServiceFixture('compute'))
def test_rpc_consumer_isolation(self):
class NeverCalled(object):
diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py
index 560e12d70..ca8281295 100644
--- a/nova/tests/xenapi/stubs.py
+++ b/nova/tests/xenapi/stubs.py
@@ -352,6 +352,6 @@ class XenAPITestBase(test.TestCase):
def setUp(self):
super(XenAPITestBase, self).setUp()
- self.stub_module('XenAPI', fake)
+ self.useFixture(test.ReplaceModule('XenAPI', fake))
fake.reset()