from nova import rpc
from nova import service
from nova.tests.functional.api import client
+from nova.tests import uuidsentinel
_TRUE_VALUES = ('True', 'true', '1', 'yes')
'do use the database and cause failures later.')
+class SingleCellSimple(fixtures.Fixture):
+ """Setup the simplest cells environment possible
+
+ This should be used when you do not care about multiple cells,
+ or having a "real" environment for tests that should not care.
+ This will give you a single cell, and map any and all accesses
+ to that cell (even things that would go to cell0).
+
+ If you need to distinguish between cell0 and cellN, then you
+ should use the CellDatabases fixture.
+ """
+
+ def setUp(self):
+ super(SingleCellSimple, self).setUp()
+ self.useFixture(fixtures.MonkeyPatch(
+ 'nova.objects.CellMappingList._get_all_from_db',
+ self._fake_cell_list))
+ self.useFixture(fixtures.MonkeyPatch(
+ 'nova.context.target_cell',
+ self._fake_target_cell))
+
+ def _fake_cell_list(self, *args):
+ return [{'id': 1,
+ 'updated_at': None,
+ 'created_at': None,
+ 'uuid': uuidsentinel.cell1,
+ 'name': 'onlycell',
+ 'transport_url': 'fake://nowhere/',
+ 'database_connection': 'sqlite:///'}]
+
+ @contextmanager
+ def _fake_target_cell(self, context, target_cell):
+ # NOTE(danms): Just pass through the context without actually
+ # targetting anything.
+ yield context
+
+
class CellDatabases(fixtures.Fixture):
"""Create per-cell databases for testing.
from nova.compute import rpcapi as compute_rpcapi
from nova import conductor
+from nova import context
from nova.db.sqlalchemy import api as session
from nova import exception
+from nova import objects
from nova.objects import base as obj_base
from nova.objects import service as service_obj
from nova.tests import fixtures
self.useFixture(fixtures.NoopConductorFixture())
conductor.API().wait_until_ready()
self.assertFalse(mock_wait.called)
+
+
+class TestSingleCellSimpleFixture(testtools.TestCase):
+ def test_single_cell(self):
+ self.useFixture(fixtures.SingleCellSimple())
+ cml = objects.CellMappingList.get_all(None)
+ self.assertEqual(1, len(cml))
+
+ def test_target_cell(self):
+ self.useFixture(fixtures.SingleCellSimple())
+ with context.target_cell(mock.sentinel.context, None) as c:
+ self.assertIs(mock.sentinel.context, c)