summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2015-03-06 21:49:54 +0100
committerIhar Hrachyshka <ihrachys@redhat.com>2015-03-10 11:58:22 +0000
commit1843c9cc0c2c751bcb995f2668b272fd9c7720a4 (patch)
tree72758b318548f02f9e3ec5fc75b15ca05753500a
parent0e5a9f4b1a6ff3100d770dc71f6be86d57d54432 (diff)
downloadoslo-incubator-1843c9cc0c2c751bcb995f2668b272fd9c7720a4.tar.gz
Fix matchmaker_redis ack_alive fails with KeyError
Fix matchmaker_redis: ack_alive fails with KeyError on re-registration attempt. def ack_alive(self, key, host): topic = "%s.%s" % (key, host) if not self.redis.expire(topic, CONF.matchmaker_heartbeat_ttl): # If we could not update the expiration, the key # might have been pruned. Re-register, creating a new # key in Redis. self.register(self.host_topic[host], host) self.host_topic is a dict with keys of tuple (key, host), not 'host', register's first parameter is the topic like 'notification-info', so modify it to key. And it will not cause indefinite recursion, because when register end, the key exist in redis, redis.expire will return True. Add test case for ack_alive. (backported from oslo.messaging; omitting master branch since it does not have RPC module anymore.) Closes-Bug: #1419718 Change-Id: I8d972afe89aec02a5c8f0d9dd4e216bc12c298a1
-rw-r--r--openstack/common/rpc/matchmaker_redis.py2
-rw-r--r--tests/unit/rpc/test_matchmaker_redis.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/openstack/common/rpc/matchmaker_redis.py b/openstack/common/rpc/matchmaker_redis.py
index 215ab9e3..0ea69df0 100644
--- a/openstack/common/rpc/matchmaker_redis.py
+++ b/openstack/common/rpc/matchmaker_redis.py
@@ -109,7 +109,7 @@ class MatchMakerRedis(mm_common.HeartbeatMatchMakerBase):
# If we could not update the expiration, the key
# might have been pruned. Re-register, creating a new
# key in Redis.
- self.register(self.host_topic[host], host)
+ self.register(key, host)
def is_alive(self, topic, host):
ttl = self.redis.ttl(host)
diff --git a/tests/unit/rpc/test_matchmaker_redis.py b/tests/unit/rpc/test_matchmaker_redis.py
index 9ebd677d..492b560f 100644
--- a/tests/unit/rpc/test_matchmaker_redis.py
+++ b/tests/unit/rpc/test_matchmaker_redis.py
@@ -121,6 +121,12 @@ class MatchMakerRedisHeartbeatTestCase(test.BaseTestCase,
# Tests that host is removed from results
self.assertEqual(self.driver.queues(self.topic), [])
+ def test_ack_alive(self):
+ self.driver.ack_alive('ack_alive', 'controller1')
+ self.assertEqual(
+ sorted(self.driver.redis.smembers('ack_alive')),
+ ['ack_alive.controller1'])
+
class MatchMakerRedisTestCase(test.BaseTestCase):
"""Generic tests that do not require a Redis server."""