summaryrefslogtreecommitdiff
path: root/nova/test.py
diff options
context:
space:
mode:
authorDan Smith <dansmith@redhat.com>2016-12-02 12:14:30 -0800
committerDan Smith <dansmith@redhat.com>2016-12-09 10:30:43 -0800
commit979639b21cb55e7d1e585a091281a89933716b67 (patch)
treeef1335c64c4affffc273eb65d1643e5fd8e0b136 /nova/test.py
parent4728c3e4fde5b5b7b068f60ea410d663deea7db2 (diff)
downloadnova-979639b21cb55e7d1e585a091281a89933716b67.tar.gz
Setup CellsV2 environment in base test
This makes us automatically set up a usable CellsV2 environment in the base test case, if we're setting up database stuff. If the test uses the DB normally, we get a cell0, a real cell, and create hostmappings for any compute services that we start. If we're not a DB-using test, we mock out the cell mapping stuff so that everything appears to just be in the same cell. This includes a fix for the nova-manage tests, which need to control their own cells destiny now. This includes a fix to the pci tests for libvirt, which were starting the same compute service twice in a row. That no longer works because we fail to create the duplicate hostmapping record, but we should not have been doing that anyway. This makes us only create it once. This includes a fix to the connection switching test to set up the database fixtures itself since it requires a specific environment that we now confuse by always going through the CellDatabases fixture. Change-Id: I435bf18ab66ad1469c03f0cf3027033a5751af6f
Diffstat (limited to 'nova/test.py')
-rw-r--r--nova/test.py75
1 files changed, 66 insertions, 9 deletions
diff --git a/nova/test.py b/nova/test.py
index 5b6e043903..960ce0ceff 100644
--- a/nova/test.py
+++ b/nova/test.py
@@ -49,10 +49,12 @@ from nova import context
from nova import db
from nova.network import manager as network_manager
from nova.network.security_group import openstack_driver
+from nova import objects
from nova.objects import base as objects_base
from nova.tests import fixtures as nova_fixtures
from nova.tests.unit import conf_fixture
from nova.tests.unit import policy_fixture
+from nova.tests import uuidsentinel as uuids
from nova import utils
@@ -64,6 +66,8 @@ logging.setup(CONF, 'nova')
cache.configure(CONF)
_TRUE_VALUES = ('True', 'true', '1', 'yes')
+CELL1_NAME = 'cell1'
+
if six.PY2:
nested = contextlib.nested
@@ -218,25 +222,35 @@ class TestCase(testtools.TestCase):
self.useFixture(conf_fixture.ConfFixture(CONF))
self.useFixture(nova_fixtures.RPCFixture('nova.test'))
+ # NOTE(danms): Make sure to reset us back to non-remote objects
+ # for each test to avoid interactions. Also, backup the object
+ # registry.
+ objects_base.NovaObject.indirection_api = None
+ self._base_test_obj_backup = copy.copy(
+ objects_base.NovaObjectRegistry._registry._obj_classes)
+ self.addCleanup(self._restore_obj_registry)
+
+ self.cell_mappings = {}
+ self.host_mappings = {}
+ # NOTE(danms): If the test claims to want to set up the database
+ # itself, then it is responsible for all the mapping stuff too.
if self.USES_DB:
- self.useFixture(nova_fixtures.Database())
+ # NOTE(danms): Full database setup involves a cell0, cell1,
+ # and the relevant mappings.
self.useFixture(nova_fixtures.Database(database='api'))
+ self._setup_cells()
self.useFixture(nova_fixtures.DefaultFlavorsFixture())
elif not self.USES_DB_SELF:
+ # NOTE(danms): If not using the database, we mock out the
+ # mapping stuff and effectively collapse everything to a
+ # single cell.
+ self.useFixture(nova_fixtures.SingleCellSimple())
self.useFixture(nova_fixtures.DatabasePoisonFixture())
# NOTE(blk-u): WarningsFixture must be after the Database fixture
# because sqlalchemy-migrate messes with the warnings filters.
self.useFixture(nova_fixtures.WarningsFixture())
- # NOTE(danms): Make sure to reset us back to non-remote objects
- # for each test to avoid interactions. Also, backup the object
- # registry.
- objects_base.NovaObject.indirection_api = None
- self._base_test_obj_backup = copy.copy(
- objects_base.NovaObjectRegistry._registry._obj_classes)
- self.addCleanup(self._restore_obj_registry)
-
self.useFixture(ovo_fixture.StableObjectJsonFixture())
# NOTE(mnaser): All calls to utils.is_neutron() are cached in
@@ -257,6 +271,39 @@ class TestCase(testtools.TestCase):
self.useFixture(nova_fixtures.ForbidNewLegacyNotificationFixture())
+ def _setup_cells(self):
+ """Setup a normal cellsv2 environment.
+
+ This sets up the CellDatabase fixture with two cells, one cell0
+ and one normal cell. CellMappings are created for both so that
+ cells-aware code can find those two databases.
+ """
+ celldbs = nova_fixtures.CellDatabases()
+ celldbs.add_cell_database(objects.CellMapping.CELL0_UUID)
+ celldbs.add_cell_database(uuids.cell1, default=True)
+ self.useFixture(celldbs)
+
+ ctxt = context.get_context()
+ fake_transport = 'fake://nowhere/'
+
+ c0 = objects.CellMapping(
+ context=ctxt,
+ uuid=objects.CellMapping.CELL0_UUID,
+ name='cell0',
+ transport_url=fake_transport,
+ database_connection=objects.CellMapping.CELL0_UUID)
+ c0.create()
+
+ c1 = objects.CellMapping(
+ context=ctxt,
+ uuid=uuids.cell1,
+ name=CELL1_NAME,
+ transport_url=fake_transport,
+ database_connection=uuids.cell1)
+ c1.create()
+
+ self.cell_mappings = {cm.name: cm for cm in (c0, c1)}
+
def _restore_obj_registry(self):
objects_base.NovaObjectRegistry._registry._obj_classes = \
self._base_test_obj_backup
@@ -295,6 +342,16 @@ class TestCase(testtools.TestCase):
def start_service(self, name, host=None, **kwargs):
svc = self.useFixture(
nova_fixtures.ServiceFixture(name, host, **kwargs))
+
+ if name == 'compute':
+ ctxt = context.get_context()
+ cell = self.cell_mappings[kwargs.pop('cell', CELL1_NAME)]
+ hm = objects.HostMapping(context=ctxt,
+ host=svc.service.host,
+ cell_mapping=cell)
+ hm.create()
+ self.host_mappings[hm.host] = hm
+
return svc.service
def assertJsonEqual(self, expected, observed):