Fixed renaming topic breaking service

Changing the topic currently changes the service_name. This
breaks the service, as the service_name is also used to
load the appropriate configuration seection for the service.

> self._service_config = CONF['service:%s' % self.service_name]

* Renames cfg option [service:<name>].<name>_topic to [service:<name>].topic
* Removed previously unused configs related to topics.
* Added topic override for producer.
* Added test coverage.

Closes-Bug: #1832799
Change-Id: I16385361ec25025aa533df80793dfc4d22151cbb
This commit is contained in:
Erik Olof Gunnar Andersson 2019-06-13 17:24:50 -07:00
parent fc5700bd61
commit fcb3290be7
20 changed files with 98 additions and 29 deletions

View File

@ -72,9 +72,10 @@ class CentralAPI(object):
LOGGING_BLACKLIST = ['update_service_status']
def __init__(self, topic=None):
topic = topic if topic else cfg.CONF['service:central'].central_topic
self.topic = topic if topic else cfg.CONF['service:central'].topic
target = messaging.Target(topic=topic, version=self.RPC_API_VERSION)
target = messaging.Target(topic=self.topic,
version=self.RPC_API_VERSION)
self.client = rpc.get_client(target, version_cap='6.2')
@classmethod

View File

@ -222,10 +222,9 @@ class Service(service.RPCService, service.Service):
@property
def service_name(self):
return cfg.CONF['service:central'].central_topic
return 'central'
def start(self):
if (cfg.CONF['service:central'].managed_resource_tenant_id ==
"00000000-0000-0000-0000-000000000000"):
LOG.warning("Managed Resource Tenant ID is not properly "

View File

@ -38,12 +38,6 @@ DESIGNATE_OPTS = [
help="Additional modules that contains allowed RPC exceptions.",
deprecated_name='allowed_rpc_exception_modules'),
cfg.StrOpt('central-topic', default='central', help='Central Topic'),
cfg.StrOpt('mdns-topic', default='mdns', help='mDNS Topic'),
cfg.StrOpt('pool-manager-topic', default='pool_manager',
help='Pool Manager Topic'),
cfg.StrOpt('worker-topic', default='worker', help='Worker Topic'),
# Default TTL
cfg.IntOpt('default-ttl', default=3600, help='TTL Value'),

View File

@ -44,9 +44,8 @@ CENTRAL_OPTS = [
cfg.StrOpt('default_pool_id',
default='794ccc2c-d751-44fe-b57f-8894c9f5c842',
help="The name of the default pool"),
cfg.StrOpt('central_topic',
default='central',
help="RPC topic name of central service."),
cfg.StrOpt('topic', default='central',
help='RPC topic name for central'),
cfg.ListOpt(
'scheduler_filters',
default=['default_pool'],

View File

@ -50,8 +50,8 @@ MDNS_OPTS = [
help='The storage driver to use'),
cfg.IntOpt('max-message-size', default=65535,
help='Maximum message size to emit'),
cfg.StrOpt('mdns_topic', default='mdns',
help='RPC topic name for mini-DNS'),
cfg.StrOpt('topic', default='mdns',
help='RPC topic name for mdns'),
cfg.IntOpt('xfr_timeout', help="Timeout in seconds for XFR's.",
default=10),
]

View File

@ -80,7 +80,7 @@ POOL_MANAGER_OPTS = [
help='Interval between zone update attempts during sync'),
cfg.StrOpt('cache-driver', default='memcache',
help='The cache driver to use'),
cfg.StrOpt('pool_manager_topic', default='pool_manager',
cfg.StrOpt('topic', default='pool_manager',
help='RPC topic name for pool-manager'),
]

View File

@ -39,6 +39,8 @@ PRODUCER_OPTS = [
help='Whether to allow synchronous zone exports',
deprecated_for_removal=True,
deprecated_reason='Migrated to designate-worker'),
cfg.StrOpt('topic', default='producer',
help='RPC topic name for producer'),
]
ZONE_MANAGER_OPTS = [

View File

@ -53,8 +53,8 @@ WORKER_OPTS = [
'noop NOTIFYs in mdns if true'),
cfg.BoolOpt('export-synchronous', default=True,
help='Whether to allow synchronous zone exports'),
cfg.StrOpt('worker_topic', default='worker',
help='RPC topic for worker component'),
cfg.StrOpt('topic', default='worker',
help='RPC topic name for worker'),
]

View File

@ -49,14 +49,14 @@ class MdnsAPI(object):
RPC_XFR_API_VERSION = '1.0'
def __init__(self, topic=None):
topic = topic if topic else cfg.CONF['service:mdns'].mdns_topic
self.topic = topic if topic else cfg.CONF['service:mdns'].topic
notify_target = messaging.Target(topic=topic,
notify_target = messaging.Target(topic=self.topic,
namespace='notify',
version=self.RPC_NOTIFY_API_VERSION)
self.notify_client = rpc.get_client(notify_target, version_cap='2.0')
xfr_target = messaging.Target(topic=topic,
xfr_target = messaging.Target(topic=self.topic,
namespace='xfr',
version=self.RPC_XFR_API_VERSION)
self.xfr_client = rpc.get_client(xfr_target, version_cap='1.0')

View File

@ -43,7 +43,7 @@ class Service(service.DNSService, service.RPCService, service.Service):
@property
def service_name(self):
return cfg.CONF['service:mdns'].mdns_topic
return 'mdns'
@property
@utils.cache_result

View File

@ -47,8 +47,7 @@ class PoolManagerAPI(object):
RPC_API_VERSION = '2.1'
def __init__(self, topic=None):
self.topic = topic if topic \
else cfg.CONF['service:pool_manager'].pool_manager_topic
self.topic = topic if topic else cfg.CONF['service:pool_manager'].topic
target = messaging.Target(topic=self.topic,
version=self.RPC_API_VERSION)

View File

@ -128,7 +128,7 @@ class Service(service.RPCService, coordination.CoordinationMixin,
@property
def service_name(self):
return cfg.CONF['service:pool_manager'].pool_manager_topic
return 'pool_manager'
@property
def _rpc_topic(self):

View File

@ -154,7 +154,7 @@ class RPCService(object):
@property
def _rpc_topic(self):
return self.service_name
return CONF['service:%s' % self.service_name].topic
def start(self):
super(RPCService, self).start()

View File

@ -15,6 +15,8 @@
# under the License.
import mock
import oslotest.base
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
import designate.dnsutils
import designate.rpc
@ -24,11 +26,14 @@ import designate.utils
from designate.mdns import handler
from designate.mdns import service
CONF = cfg.CONF
class MdnsServiceTest(oslotest.base.BaseTestCase):
@mock.patch.object(designate.rpc, 'get_server')
def setUp(self, mock_rpc_server):
super(MdnsServiceTest, self).setUp()
self.useFixture(cfg_fixture.Config(CONF))
self.service = service.Service()
@ -41,6 +46,14 @@ class MdnsServiceTest(oslotest.base.BaseTestCase):
def test_service_name(self):
self.assertEqual('mdns', self.service.service_name)
def test_mdns_rpc_topic(self):
CONF.set_override('topic', 'test-topic', 'service:mdns')
self.service = service.Service()
self.assertEqual('test-topic', self.service._rpc_topic)
self.assertEqual('mdns', self.service.service_name)
def test_rpc_endpoints(self):
endpoints = self.service._rpc_endpoints

View File

@ -17,12 +17,16 @@ import time
from datetime import datetime
import mock
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
from designate import exceptions
from designate import objects
from designate import tests
from designate.pool_manager import service
CONF = cfg.CONF
POOL_DICT = {
'also_notifies': [
{
@ -75,6 +79,8 @@ POOL_DICT = {
class PoolManagerInitTest(tests.TestCase):
def setUp(self):
super(PoolManagerInitTest, self).setUp()
self.useFixture(cfg_fixture.Config(CONF))
self.service = service.Service()
def test_init_no_pool_targets(self):
@ -90,6 +96,15 @@ class PoolManagerInitTest(tests.TestCase):
def test_service_name(self):
self.assertEqual('pool_manager', self.service.service_name)
def test_pool_manager_rpc_topic(self):
CONF.set_override('topic', 'test-topic', 'service:pool_manager')
self.service = service.Service()
self.assertEqual('test-topic.794ccc2c-d751-44fe-b57f-8894c9f5c842',
self.service._rpc_topic)
self.assertEqual('pool_manager', self.service.service_name)
@mock.patch('designate.service.RPCService.start')
def test_start(self, mock_rpc_start):
self.service.tg.add_timer = mock.Mock()

View File

@ -19,15 +19,21 @@ Unit-test Producer service
"""
import mock
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
from oslotest import base as test
from designate.producer import service
from designate.tests.unit import RoObject
CONF = cfg.CONF
@mock.patch.object(service.rpcapi.CentralAPI, 'get_instance')
class ProducerTest(test.BaseTestCase):
def setUp(self):
self.useFixture(cfg_fixture.Config(CONF))
service.CONF = RoObject({
'service:producer': RoObject({
'enabled_tasks': None, # enable all tasks
@ -49,6 +55,14 @@ class ProducerTest(test.BaseTestCase):
def test_service_name(self, _):
self.assertEqual('producer', self.service.service_name)
def test_producer_rpc_topic(self, _):
CONF.set_override('topic', 'test-topic', 'service:producer')
self.service = service.Service()
self.assertEqual('test-topic', self.service._rpc_topic)
self.assertEqual('producer', self.service.service_name)
def test_central_api(self, _):
capi = self.service.central_api
self.assertIsInstance(capi, mock.MagicMock)

View File

@ -15,17 +15,34 @@
# under the License.mport threading
import mock
import oslotest.base
from oslo_config import cfg
from oslo_config import fixture as cfg_fixture
from designate.worker import service
CONF = cfg.CONF
class TestService(oslotest.base.BaseTestCase):
def setUp(self):
super(TestService, self).setUp()
self.useFixture(cfg_fixture.Config(CONF))
self.context = mock.Mock()
self.zone = mock.Mock()
self.service = service.Service()
def test_service_name(self):
self.assertEqual('worker', self.service.service_name)
def test_worker_rpc_topic(self):
CONF.set_override('topic', 'test-topic', 'service:worker')
self.service = service.Service()
self.assertEqual('test-topic', self.service._rpc_topic)
self.assertEqual('worker', self.service.service_name)
def test_create_zone(self):
self.service._do_zone_action = mock.Mock()

View File

@ -37,9 +37,10 @@ class WorkerAPI(object):
RPC_API_VERSION = '1.0'
def __init__(self, topic=None):
topic = topic if topic else cfg.CONF['service:worker'].worker_topic
self.topic = topic if topic else cfg.CONF['service:worker'].topic
target = messaging.Target(topic=topic, version=self.RPC_API_VERSION)
target = messaging.Target(topic=self.topic,
version=self.RPC_API_VERSION)
self.client = rpc.get_client(target, version_cap='1.0')
@classmethod

View File

@ -93,7 +93,7 @@ class Service(service.RPCService, service.Service):
@property
def service_name(self):
return cfg.CONF['service:worker'].worker_topic
return 'worker'
@property
def storage(self):

View File

@ -0,0 +1,15 @@
---
fixes:
- |
It was previously not possible to override the topics for various serivces (e.g. mdns),
due to `bug 1832799`_. This has been fixed, and these services now use a common option name to
override the topic.
e.g.
.. code-block:: ini
[service:mdns]
topic = mdns
.. _bug 1832799: https://bugs.launchpad.net/designate/+bug/1832799