Move restart_compute_service to a common place

Restarting a compute service properly in the functional test environment
is tricky. During a recent bugfix a util function was introduced to do
the restart. This patch moves the util to the base class and spreads
the usage of it to more functional tests to make them more realistic.

Change-Id: I17f67a02b27a90658df48856963ea3fb327e81dc
This commit is contained in:
Balazs Gibizer 2017-10-16 18:37:39 +02:00
parent c7b6c18755
commit ae2f9f89f8

View File

@ -421,6 +421,26 @@ class TestCase(testtools.TestCase):
return svc.service
def restart_compute_service(self, compute):
"""Restart a compute service in a realistic way.
:param:compute: the nova-compute service to be restarted
"""
# NOTE(gibi): The service interface cannot be used to simulate a real
# service restart as the manager object will not be recreated after a
# service.stop() and service.start() therefore the manager state will
# survive. For example the resource tracker will not be recreated after
# a stop start. The service.kill() call cannot help as it deletes
# the service from the DB which is unrealistic and causes that some
# operation that refers to the killed host (e.g. evacuate) fails.
# So this helper method tries to simulate a better compute service
# restart by cleaning up some of the internal state of the compute
# manager.
compute.stop()
compute.manager._resource_tracker = None
compute.start()
def assertJsonEqual(self, expected, observed, message=''):
"""Asserts that 2 complex data structures are json equivalent.