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-06 21:50:35 +0100
commit6b3474e1510d725fd1cd1908326339f9300d6b49 (patch)
tree54b8bfbab4c6432adf528363b07a0a6d64234c45
parent6f7cf28a43bc01d00fe589e9ad205397afa12c45 (diff)
downloadoslo-incubator-6b3474e1510d725fd1cd1908326339f9300d6b49.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 0b3d7dab..3fa7e790 100644
--- a/openstack/common/rpc/matchmaker_redis.py
+++ b/openstack/common/rpc/matchmaker_redis.py
@@ -108,7 +108,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 e5a47114..899a3d34 100644
--- a/tests/unit/rpc/test_matchmaker_redis.py
+++ b/tests/unit/rpc/test_matchmaker_redis.py
@@ -121,6 +121,12 @@ class MatchMakerRedisHeartbeatTestCase(test_base.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_base.BaseTestCase):
"""Generic tests that do not require a Redis server."""