Ensure services shutdown during unit testing

* Use stop() instead of kill() in Service fixture.
* Add reset() methods to each rpcapi, and call them after
  shutting down services, allowing for the above to work.

Change-Id: I90a1d9c40fc7f60864cfbfc7c9e47429405bc32c
Closes-Bug: 1411717
This commit is contained in:
Kiall Mac Innes 2016-05-16 13:26:18 +01:00
parent 96de5c139b
commit ed51f49a90
5 changed files with 38 additions and 4 deletions

View File

@ -26,6 +26,11 @@ LOG = logging.getLogger(__name__)
CENTRAL_API = None
def reset():
global CENTRAL_API
CENTRAL_API = None
@rpc_logging(LOG, 'central')
class CentralAPI(object):
"""

View File

@ -25,6 +25,11 @@ LOG = logging.getLogger(__name__)
MDNS_API = None
def reset():
global MDNS_API
MDNS_API = None
@rpc_logging(LOG, 'mdns')
class MdnsAPI(object):

View File

@ -28,6 +28,11 @@ LOG = logging.getLogger(__name__)
MNGR_API = None
def reset():
global MNGR_API
MNGR_API = None
@rpc_logging(LOG, 'pool_manager')
class PoolManagerAPI(object):
"""

View File

@ -74,17 +74,31 @@ class ServiceFixture(fixtures.Fixture):
cls = importutils.import_class(
'designate.%s.service.Service' % svc_name)
self.svc = cls()
self.svc_name = svc_name
def setUp(self):
super(ServiceFixture, self).setUp()
LOG.info('Starting service %s (%s)', self.svc_name, id(self.svc))
self.svc.start()
self.addCleanup(self.kill)
self.addCleanup(self.stop)
def stop(self):
LOG.info('Stopping service %s (%s)', self.svc_name, id(self.svc))
def kill(self):
try:
self.svc.kill()
self.svc.stop()
except Exception:
pass
LOG.error('Failed to stop service %s (%s)',
self.svc_name, id(self.svc))
raise
finally:
# Always try reset the service's RPCAPI
mod = importutils.try_import('designate.%s.rpcapi' % self.svc_name)
if hasattr(mod, 'reset'):
LOG.info('Resetting service %s RPCAPI', self.svc_name)
mod.reset()
class PolicyFixture(fixtures.Fixture):

View File

@ -26,6 +26,11 @@ LOG = logging.getLogger(__name__)
ZONE_MANAGER_API = None
def reset():
global ZONE_MANAGER_API
ZONE_MANAGER_API = None
@rpc_logging(LOG, 'zone_manager')
class ZoneManagerAPI(object):
"""