diff options
author | joyce <qiaojian@awcloud.com> | 2015-02-13 16:21:30 +0800 |
---|---|---|
committer | joyce <qiaojian@awcloud.com> | 2015-02-27 16:32:10 +0800 |
commit | e8def40a4149651b69d0ed8fa1bdbbb431912f27 (patch) | |
tree | afe5a692f26fbd569d91ef5bab20cc79affa720b | |
parent | 68cd8cfecc12a40b61a7b8557aad7b5a4e1f1c6d (diff) | |
download | oslo-messaging-e8def40a4149651b69d0ed8fa1bdbbb431912f27.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.
Closes-Bug: #1419718
Change-Id: I8d972afe89aec02a5c8f0d9dd4e216bc12c298a1
-rw-r--r-- | oslo_messaging/_drivers/matchmaker_redis.py | 2 | ||||
-rw-r--r-- | oslo_messaging/tests/drivers/test_matchmaker_redis.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/oslo_messaging/_drivers/matchmaker_redis.py b/oslo_messaging/_drivers/matchmaker_redis.py index 4ba5447..4f6e6f0 100644 --- a/oslo_messaging/_drivers/matchmaker_redis.py +++ b/oslo_messaging/_drivers/matchmaker_redis.py @@ -105,7 +105,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): if self.redis.ttl(host) == -1: diff --git a/oslo_messaging/tests/drivers/test_matchmaker_redis.py b/oslo_messaging/tests/drivers/test_matchmaker_redis.py index 9110296..097029d 100644 --- a/oslo_messaging/tests/drivers/test_matchmaker_redis.py +++ b/oslo_messaging/tests/drivers/test_matchmaker_redis.py @@ -81,3 +81,9 @@ class RedisMatchMakerTest(test_utils.BaseTestCase): self.assertEqual( sorted(self.matcher.redis.smembers('conductor')), ['conductor.node1', 'conductor.node2', 'conductor.node3']) + + def test_ack_alive(self): + self.matcher.ack_alive('ack_alive', 'controller1') + self.assertEqual( + sorted(self.matcher.redis.smembers('ack_alive')), + ['ack_alive.controller1']) |