Make api_samples tests use simple cell environment
The api_samples tests depend on a very static environment where we use the SpawnIsSynchronous fixture. This is somewhat at odds with the locking used in the CellDatabase fixture, which will necessarily recurse at times. Since the api_samples tests are already a bit naive in the service layout, and since they don't care about cells things, we do some monkeywork here to make them use the SingleCellSimple fixture instead of a full-blown multi-cell environment. Change-Id: If1138331f3a46f5aed87e898ce19879a787d435f
This commit is contained in:
parent
45e79583ce
commit
4e3b2abdc6
@ -347,7 +347,7 @@ class TestCase(testtools.TestCase):
|
||||
svc = self.useFixture(
|
||||
nova_fixtures.ServiceFixture(name, host, **kwargs))
|
||||
|
||||
if name == 'compute':
|
||||
if name == 'compute' and self.USES_DB:
|
||||
ctxt = context.get_context()
|
||||
cell = self.cell_mappings[kwargs.pop('cell', CELL1_NAME)]
|
||||
hm = objects.HostMapping(context=ctxt,
|
||||
|
@ -56,6 +56,8 @@ CONF = nova.conf.CONF
|
||||
|
||||
class ApiSampleTestBaseV21(testscenarios.WithScenarios,
|
||||
api_samples_test_base.ApiSampleTestBase):
|
||||
SUPPORTS_CELLS = False
|
||||
|
||||
api_major_version = 'v2'
|
||||
# any additional fixtures needed for this scenario
|
||||
_additional_fixtures = []
|
||||
@ -87,13 +89,29 @@ class ApiSampleTestBaseV21(testscenarios.WithScenarios,
|
||||
for fix in self._additional_fixtures:
|
||||
self.useFixture(fix())
|
||||
|
||||
if not self.SUPPORTS_CELLS:
|
||||
# NOTE(danms): Disable base automatic DB (and cells) config
|
||||
self.USES_DB = False
|
||||
self.USES_DB_SELF = True
|
||||
|
||||
# super class call is delayed here so that we have the right
|
||||
# paste and conf before loading all the services, as we can't
|
||||
# change these later.
|
||||
super(ApiSampleTestBaseV21, self).setUp()
|
||||
|
||||
if not self.SUPPORTS_CELLS:
|
||||
self.useFixture(fixtures.Database())
|
||||
self.useFixture(fixtures.Database(database='api'))
|
||||
self.useFixture(fixtures.DefaultFlavorsFixture())
|
||||
self.useFixture(fixtures.SingleCellSimple())
|
||||
|
||||
super(ApiSampleTestBaseV21, self)._setup_services()
|
||||
|
||||
self.useFixture(test.SampleNetworks(host=self.network.host))
|
||||
fake_network.stub_compute_with_ips(self.stubs)
|
||||
self.useFixture(fixtures.SpawnIsSynchronousFixture())
|
||||
# this is used to generate sample docs
|
||||
self.generate_samples = os.getenv('GENERATE_SAMPLES') is not None
|
||||
|
||||
def _setup_services(self):
|
||||
pass
|
||||
|
@ -79,19 +79,6 @@ class _IntegratedTestBase(test.TestCase):
|
||||
nova.tests.unit.image.fake.stub_out_image_service(self)
|
||||
self._setup_services()
|
||||
|
||||
self.api_fixture = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(self.api_major_version))
|
||||
|
||||
# if the class needs to run as admin, make the api endpoint
|
||||
# the admin, otherwise it's safer to run as non admin user.
|
||||
if self.ADMIN_API:
|
||||
self.api = self.api_fixture.admin_api
|
||||
else:
|
||||
self.api = self.api_fixture.api
|
||||
|
||||
if hasattr(self, 'microversion'):
|
||||
self.api.microversion = self.microversion
|
||||
|
||||
self.useFixture(cast_as_call.CastAsCall(self.stubs))
|
||||
|
||||
self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset)
|
||||
@ -104,14 +91,32 @@ class _IntegratedTestBase(test.TestCase):
|
||||
return self.start_service('scheduler')
|
||||
|
||||
def _setup_services(self):
|
||||
# NOTE(danms): Set the global MQ connection to that of our first cell
|
||||
# for any cells-ignorant code. Normally this is defaulted in the tests
|
||||
# which will result in us not doing the right thing.
|
||||
if 'cell1' in self.cell_mappings:
|
||||
self.flags(transport_url=self.cell_mappings['cell1'].transport_url)
|
||||
self.conductor = self.start_service('conductor')
|
||||
self.compute = self._setup_compute_service()
|
||||
self.consoleauth = self.start_service('consoleauth')
|
||||
|
||||
self.network = self.start_service('network',
|
||||
manager=CONF.network_manager)
|
||||
self.scheduler = self._setup_scheduler_service()
|
||||
|
||||
self.compute = self._setup_compute_service()
|
||||
self.api_fixture = self.useFixture(
|
||||
nova_fixtures.OSAPIFixture(self.api_major_version))
|
||||
|
||||
# if the class needs to run as admin, make the api endpoint
|
||||
# the admin, otherwise it's safer to run as non admin user.
|
||||
if self.ADMIN_API:
|
||||
self.api = self.api_fixture.admin_api
|
||||
else:
|
||||
self.api = self.api_fixture.api
|
||||
|
||||
if hasattr(self, 'microversion'):
|
||||
self.api.microversion = self.microversion
|
||||
|
||||
def get_unused_server_name(self):
|
||||
servers = self.api.get_servers()
|
||||
server_names = [server['name'] for server in servers]
|
||||
|
@ -370,9 +370,13 @@ class TestUpgradeCheckCellsV2(test.NoDBTestCase):
|
||||
"""Tests a successful cells v2 upgrade check."""
|
||||
# create the cell0 and first cell mappings
|
||||
self._setup_cells()
|
||||
# create the host mapping indirectly - host mappings existing implies
|
||||
# there is a compute node so that's not checked.
|
||||
self.start_service('compute')
|
||||
# Start a compute service and create a hostmapping for it
|
||||
svc = self.start_service('compute')
|
||||
cell = self.cell_mappings[test.CELL1_NAME]
|
||||
hm = objects.HostMapping(context=context.get_admin_context(),
|
||||
host=svc.host,
|
||||
cell_mapping=cell)
|
||||
hm.create()
|
||||
|
||||
result = self.cmd._check_cellsv2()
|
||||
self.assertEqual(status.UpgradeCheckCode.SUCCESS, result.code)
|
||||
|
Loading…
x
Reference in New Issue
Block a user