summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2012-10-28 01:32:59 -0400
committerMonty Taylor <mordred@inaugust.com>2012-11-22 11:23:11 -0800
commit529194e4e70c2efc46258c101509dffec3dc7e5d (patch)
treee034fa5617a1c218888c2187dd7551cc6eafd516 /nova
parent2d6abe49c35ab5c6200164455631a259eefe7457 (diff)
downloadnova-529194e4e70c2efc46258c101509dffec3dc7e5d.tar.gz
nova-529194e4e70c2efc46258c101509dffec3dc7e5d.tar.xz
nova-529194e4e70c2efc46258c101509dffec3dc7e5d.zip
Move global fixture setup into nova/test.py
There are global fixtures that get set up for testing in nova/tests/__init__.py, even though there is a base test class. As we move towards parallel testing, we want to convert all of these into proper fixtures. As a step towards that, move them into nova/test.py so that it's clear that they are part of the global test setup. From there we'll move them into proper fixture classes. Part of blueprint grizzly-testtools Change-Id: Ia0b0ae380069a212bc20e009d1088c2bad7d9177
Diffstat (limited to 'nova')
-rw-r--r--nova/test.py75
-rw-r--r--nova/tests/__init__.py83
2 files changed, 74 insertions, 84 deletions
diff --git a/nova/test.py b/nova/test.py
index 3a52a2493..4ea1d3023 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -23,15 +23,23 @@ inline callbacks.
"""
+import os
+import shutil
import sys
import uuid
+import eventlet
from fixtures import EnvironmentVariable
import mox
import stubout
import testtools
from nova import config
+from nova import context
+from nova import db
+from nova.db import migration
+from nova.db.sqlalchemy.session import get_engine
+from nova.network import manager as network_manager
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
@@ -51,9 +59,74 @@ test_opts = [
CONF = cfg.CONF
CONF.register_opts(test_opts)
+CONF.import_opt('sql_connection', 'nova.db.sqlalchemy.session')
+CONF.import_opt('sqlite_db', 'nova.db.sqlalchemy.session')
+CONF.import_opt('state_path', 'nova.config')
+CONF.set_override('use_stderr', False)
+logging.setup('nova')
LOG = logging.getLogger(__name__)
+eventlet.monkey_patch(os=False)
+
+_DB = None
+
+
+def reset_db():
+ if CONF.sql_connection == "sqlite://":
+ engine = get_engine()
+ engine.dispose()
+ conn = engine.connect()
+ if _DB:
+ conn.connection.executescript(_DB)
+ else:
+ setup()
+ else:
+ shutil.copyfile(os.path.join(CONF.state_path, CONF.sqlite_clean_db),
+ os.path.join(CONF.state_path, CONF.sqlite_db))
+
+
+def setup():
+
+ fake_flags.set_defaults(CONF)
+
+ if CONF.sql_connection == "sqlite://":
+ if migration.db_version() > migration.INIT_VERSION:
+ return
+ else:
+ testdb = os.path.join(CONF.state_path, CONF.sqlite_db)
+ if os.path.exists(testdb):
+ return
+ migration.db_sync()
+ ctxt = context.get_admin_context()
+ network = network_manager.VlanManager()
+ bridge_interface = CONF.flat_interface or CONF.vlan_interface
+ network.create_networks(ctxt,
+ label='test',
+ cidr=CONF.fixed_range,
+ multi_host=CONF.multi_host,
+ num_networks=CONF.num_networks,
+ network_size=CONF.network_size,
+ cidr_v6=CONF.fixed_range_v6,
+ gateway=CONF.gateway,
+ gateway_v6=CONF.gateway_v6,
+ bridge=CONF.flat_network_bridge,
+ bridge_interface=bridge_interface,
+ vpn_start=CONF.vpn_start,
+ vlan_start=CONF.vlan_start,
+ dns1=CONF.flat_network_dns)
+ for net in db.network_get_all(ctxt):
+ network.set_network_host(ctxt, net)
+
+ if CONF.sql_connection == "sqlite://":
+ global _DB
+ engine = get_engine()
+ conn = engine.connect()
+ _DB = "".join(line for line in conn.connection.iterdump())
+ else:
+ cleandb = os.path.join(CONF.state_path, CONF.sqlite_clean_db)
+ shutil.copyfile(testdb, cleandb)
+
class TestingException(Exception):
pass
@@ -73,7 +146,7 @@ class TestCase(testtools.TestCase):
# now that we have some required db setup for the system
# to work properly.
self.start = timeutils.utcnow()
- tests.reset_db()
+ reset_db()
# emulate some of the mox stuff, we can't use the metaclass
# because it screws with our generators
diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py
index 6e19e6dc2..7109e000f 100644
--- a/nova/tests/__init__.py
+++ b/nova/tests/__init__.py
@@ -28,86 +28,3 @@
# The code below enables nosetests to work with i18n _() blocks
import __builtin__
setattr(__builtin__, '_', lambda x: x)
-import os
-import shutil
-
-from nova.db.sqlalchemy.session import get_engine
-from nova.openstack.common import cfg
-from nova.openstack.common import log as logging
-
-import eventlet
-
-
-eventlet.monkey_patch(os=False)
-
-CONF = cfg.CONF
-CONF.import_opt('sql_connection', 'nova.db.sqlalchemy.session')
-CONF.import_opt('sqlite_db', 'nova.db.sqlalchemy.session')
-CONF.import_opt('state_path', 'nova.config')
-CONF.set_override('use_stderr', False)
-
-logging.setup('nova')
-
-_DB = None
-
-
-def reset_db():
- if CONF.sql_connection == "sqlite://":
- engine = get_engine()
- engine.dispose()
- conn = engine.connect()
- if _DB:
- conn.connection.executescript(_DB)
- else:
- setup()
- else:
- shutil.copyfile(os.path.join(CONF.state_path, CONF.sqlite_clean_db),
- os.path.join(CONF.state_path, CONF.sqlite_db))
-
-
-def setup():
- import mox # Fail fast if you don't have mox. Workaround for bug 810424
-
- from nova import context
- from nova import db
- from nova.db import migration
- from nova.network import manager as network_manager
- from nova.tests import fake_flags
- fake_flags.set_defaults(CONF)
-
- if CONF.sql_connection == "sqlite://":
- if migration.db_version() > migration.INIT_VERSION:
- return
- else:
- testdb = os.path.join(CONF.state_path, CONF.sqlite_db)
- if os.path.exists(testdb):
- return
- migration.db_sync()
- ctxt = context.get_admin_context()
- network = network_manager.VlanManager()
- bridge_interface = CONF.flat_interface or CONF.vlan_interface
- network.create_networks(ctxt,
- label='test',
- cidr=CONF.fixed_range,
- multi_host=CONF.multi_host,
- num_networks=CONF.num_networks,
- network_size=CONF.network_size,
- cidr_v6=CONF.fixed_range_v6,
- gateway=CONF.gateway,
- gateway_v6=CONF.gateway_v6,
- bridge=CONF.flat_network_bridge,
- bridge_interface=bridge_interface,
- vpn_start=CONF.vpn_start,
- vlan_start=CONF.vlan_start,
- dns1=CONF.flat_network_dns)
- for net in db.network_get_all(ctxt):
- network.set_network_host(ctxt, net)
-
- if CONF.sql_connection == "sqlite://":
- global _DB
- engine = get_engine()
- conn = engine.connect()
- _DB = "".join(line for line in conn.connection.iterdump())
- else:
- cleandb = os.path.join(CONF.state_path, CONF.sqlite_clean_db)
- shutil.copyfile(testdb, cleandb)