Merge "Only allow one scheduler service in tests" into stable/train
This commit is contained in:
commit
7fb07a8ecd
21
nova/test.py
21
nova/test.py
@ -24,6 +24,7 @@ inline callbacks.
|
|||||||
import nova.monkey_patch # noqa
|
import nova.monkey_patch # noqa
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
@ -213,6 +214,9 @@ class TestCase(testtools.TestCase):
|
|||||||
os.environ.get('OS_TEST_TIMEOUT', 0),
|
os.environ.get('OS_TEST_TIMEOUT', 0),
|
||||||
self.TIMEOUT_SCALING_FACTOR))
|
self.TIMEOUT_SCALING_FACTOR))
|
||||||
|
|
||||||
|
# How many of which service we've started. {$service-name: $count}
|
||||||
|
self._service_fixture_count = collections.defaultdict(int)
|
||||||
|
|
||||||
self.useFixture(nova_fixtures.OpenStackSDKFixture())
|
self.useFixture(nova_fixtures.OpenStackSDKFixture())
|
||||||
|
|
||||||
self.useFixture(fixtures.NestedTempfile())
|
self.useFixture(fixtures.NestedTempfile())
|
||||||
@ -426,6 +430,10 @@ class TestCase(testtools.TestCase):
|
|||||||
CONF.set_override(k, v, group)
|
CONF.set_override(k, v, group)
|
||||||
|
|
||||||
def start_service(self, name, host=None, **kwargs):
|
def start_service(self, name, host=None, **kwargs):
|
||||||
|
# Disallow starting multiple scheduler services
|
||||||
|
if name == 'scheduler' and self._service_fixture_count[name]:
|
||||||
|
raise TestingException("Duplicate start_service(%s)!" % name)
|
||||||
|
|
||||||
cell = None
|
cell = None
|
||||||
# if the host is None then the CONF.host remains defaulted to
|
# if the host is None then the CONF.host remains defaulted to
|
||||||
# 'fake-mini' (originally done in ConfFixture)
|
# 'fake-mini' (originally done in ConfFixture)
|
||||||
@ -451,6 +459,19 @@ class TestCase(testtools.TestCase):
|
|||||||
svc = self.useFixture(
|
svc = self.useFixture(
|
||||||
nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs))
|
nova_fixtures.ServiceFixture(name, host, cell=cell, **kwargs))
|
||||||
|
|
||||||
|
# Keep track of how many instances of this service are running.
|
||||||
|
self._service_fixture_count[name] += 1
|
||||||
|
real_stop = svc.service.stop
|
||||||
|
|
||||||
|
# Make sure stopping the service decrements the active count, so that
|
||||||
|
# start,stop,start doesn't trigger the "Duplicate start_service"
|
||||||
|
# exception.
|
||||||
|
def patch_stop(*a, **k):
|
||||||
|
self._service_fixture_count[name] -= 1
|
||||||
|
return real_stop(*a, **k)
|
||||||
|
self.useFixture(fixtures.MockPatchObject(
|
||||||
|
svc.service, 'stop', patch_stop))
|
||||||
|
|
||||||
return svc.service
|
return svc.service
|
||||||
|
|
||||||
def restart_compute_service(self, compute, keep_hypervisor_state=True):
|
def restart_compute_service(self, compute, keep_hypervisor_state=True):
|
||||||
|
Loading…
Reference in New Issue
Block a user