Clear hash ring cache in get_topic_for*
This causes the hash ring to be reset on each API request, avoiding an issue where a new conductor never joins the ring until the API service is restarted. Closes-Bug: 1378570 Change-Id: Ic57370163f2f833efab662837036298f29f4ca90
This commit is contained in:
parent
af59e4b313
commit
d7cc831299
@ -87,6 +87,8 @@ class ConductorAPI(object):
|
||||
:raises: NoValidHost
|
||||
|
||||
"""
|
||||
self.ring_manager.reset()
|
||||
|
||||
try:
|
||||
ring = self.ring_manager[node.driver]
|
||||
dest = ring.get_hosts(node.uuid)
|
||||
@ -106,6 +108,8 @@ class ConductorAPI(object):
|
||||
:raises: DriverNotFound
|
||||
|
||||
"""
|
||||
self.ring_manager.reset()
|
||||
|
||||
hash_ring = self.ring_manager[driver_name]
|
||||
host = random.choice(list(hash_ring.hosts))
|
||||
return self.topic + "." + host
|
||||
|
@ -78,6 +78,22 @@ class RPCAPITestCase(base.DbTestCase):
|
||||
rpcapi.get_topic_for,
|
||||
self.fake_node_obj)
|
||||
|
||||
def test_get_topic_doesnt_cache(self):
|
||||
CONF.set_override('host', 'fake-host')
|
||||
|
||||
rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic')
|
||||
self.assertRaises(exception.NoValidHost,
|
||||
rpcapi.get_topic_for,
|
||||
self.fake_node_obj)
|
||||
|
||||
self.dbapi.register_conductor({'hostname': 'fake-host',
|
||||
'drivers': ['fake-driver']})
|
||||
|
||||
rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic')
|
||||
expected_topic = 'fake-topic.fake-host'
|
||||
self.assertEqual(expected_topic,
|
||||
rpcapi.get_topic_for(self.fake_node_obj))
|
||||
|
||||
def test_get_topic_for_driver_known_driver(self):
|
||||
CONF.set_override('host', 'fake-host')
|
||||
self.dbapi.register_conductor({
|
||||
@ -99,6 +115,21 @@ class RPCAPITestCase(base.DbTestCase):
|
||||
rpcapi.get_topic_for_driver,
|
||||
'fake-driver')
|
||||
|
||||
def test_get_topic_for_driver_doesnt_cache(self):
|
||||
CONF.set_override('host', 'fake-host')
|
||||
rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic')
|
||||
self.assertRaises(exception.DriverNotFound,
|
||||
rpcapi.get_topic_for_driver,
|
||||
'fake-driver')
|
||||
|
||||
self.dbapi.register_conductor({
|
||||
'hostname': 'fake-host',
|
||||
'drivers': ['fake-driver'],
|
||||
})
|
||||
rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic')
|
||||
self.assertEqual('fake-topic.fake-host',
|
||||
rpcapi.get_topic_for_driver('fake-driver'))
|
||||
|
||||
def _test_rpcapi(self, method, rpc_method, **kwargs):
|
||||
rpcapi = conductor_rpcapi.ConductorAPI(topic='fake-topic')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user