Ensure designate-sink has policy initialized

We split the designate Service class into a base Service class,
and a RPCService class.

Service contains code common to every Designate service, while
RPCService contains code for any RPC servers.

Closes-Bug: 1366764
Change-Id: I2410a83c9f4123b2011f4f6409aacb18f010097f
This commit is contained in:
Kiall Mac Innes 2014-09-08 12:17:42 +01:00
parent aadfa1fdae
commit 00d7af0603
5 changed files with 27 additions and 15 deletions

View File

@ -24,7 +24,7 @@ from designate.central import rpcapi as central_rpcapi
LOG = logging.getLogger(__name__)
class Service(service.Service):
class Service(service.RPCService):
def __init__(self, *args, **kwargs):
super(Service, self).__init__(*args, **kwargs)

View File

@ -69,7 +69,7 @@ def transaction(f):
return wrapper
class Service(service.Service):
class Service(service.RPCService):
RPC_API_VERSION = '4.0'
target = messaging.Target(version=RPC_API_VERSION)

View File

@ -32,10 +32,11 @@ LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class Service(service.Service):
class Service(service.RPCService):
def __init__(self, *args, **kwargs):
notify_endpoint = notify.NotifyEndpoint()
kwargs['endpoints'] = [notify_endpoint]
super(Service, self).__init__(*args, **kwargs)
# Create an instance of the RequestHandler class

View File

@ -36,28 +36,38 @@ LOG = logging.getLogger(__name__)
class Service(service.Service):
"""
Service class to be shared among the diverse service inside of Designate.
Partially inspired by the code at cinder.service but for now without
support for loading so called "endpoints" or "managers".
"""
def __init__(self, host, binary, topic, service_name=None, endpoints=None):
super(Service, self).__init__()
def __init__(self, threads=1000):
super(Service, self).__init__(threads)
policy.init()
# NOTE(kiall): All services need RPC initialized, as this is used
# for clients AND servers. Hence, this is common to
# all Designate services.
if not rpc.initialized():
rpc.init(CONF)
class RPCService(Service):
"""
Service class to be shared by all Designate RPC Services
"""
def __init__(self, host, binary, topic, service_name=None, endpoints=None):
super(RPCService, self).__init__()
self.host = host
self.binary = binary
self.topic = topic
self.service_name = service_name
policy.init()
# TODO(ekarlso): change this to be loadable via mod import or
# stevedore?
self.endpoints = endpoints or [self]
def start(self):
super(RPCService, self).start()
version_string = version.version_info.version_string()
LOG.info(_('Starting %(topic)s node (version %(version_string)s)') %
{'topic': self.topic, 'version_string': version_string})
@ -99,19 +109,22 @@ class Service(service.Service):
for e in self.endpoints:
if e != self and hasattr(e, 'stop'):
e.stop()
# Try to shut the connection down, but if we get any sort of
# errors, go ahead and ignore them.. as we're shutting down anyway
try:
self.rpcserver.stop()
except Exception:
pass
super(Service, self).stop()
super(RPCService, self).stop()
def wait(self):
for e in self.endpoints:
if e != self and hasattr(e, 'wait'):
e.wait()
super(Service, self).wait()
super(RPCService, self).wait()
_launcher = None

View File

@ -18,10 +18,10 @@ from oslo.config import cfg
from oslo import messaging
from designate.openstack.common import log as logging
from designate.openstack.common import service
from designate.i18n import _LW
from designate import notification_handler
from designate import rpc
from designate import service
LOG = logging.getLogger(__name__)
@ -31,8 +31,6 @@ class Service(service.Service):
def __init__(self, *args, **kwargs):
super(Service, self).__init__(*args, **kwargs)
rpc.init(cfg.CONF)
# Initialize extensions
self.handlers = self._init_extensions()
self.subscribers = self._get_subscribers()