diff options
author | Ihar Hrachyshka <ihrachys@redhat.com> | 2014-11-10 15:30:24 +0100 |
---|---|---|
committer | Ihar Hrachyshka <ihrachys@redhat.com> | 2014-11-11 17:01:36 +0100 |
commit | 8957723112cc533f302935dd982ec8dc2b942881 (patch) | |
tree | 030bf58d79b4a604a3308ffad0bf7b170aee117d | |
parent | eabe46630d53bd430361c9d9253864e473c567e1 (diff) | |
download | oslo-incubator-8957723112cc533f302935dd982ec8dc2b942881.tar.gz |
Squashed two patches that simultaneously block the gate
===
Redis: for non-strict Redis class, expired ttl is None, not -1
Python bindings for Redis return None if ttl is expired instead of -1
when Redis class is used (instead of StrictRedis) which is the default
for oslo-incubator. Fixed unit test to pass the check.
The patch does not belong to master where old RPC layer was removed
since Kilo. Neither it belongs to oslo.messaging since the test was not
copied there.
Closes-Bug: #1259532
Change-Id: Id54e78ca56bb5a5bf1cdad31bc5965ff02c0d9b4
===
Fix build break - switch from str to hash for lookup
Closes-Bug: #1372177
Change-Id: I1a1f70bb204d3f43bdacd4ded53225f8416f1639
(cherry picked from commit 6b65a41dd2653aa9e2558c510fa9d3ca3538a908)
-rw-r--r-- | openstack/common/rpc/impl_qpid.py | 4 | ||||
-rw-r--r-- | openstack/common/rpc/matchmaker_redis.py | 5 | ||||
-rw-r--r-- | tests/unit/rpc/test_matchmaker_redis.py | 12 |
3 files changed, 11 insertions, 10 deletions
diff --git a/openstack/common/rpc/impl_qpid.py b/openstack/common/rpc/impl_qpid.py index f8339b13..bbfb90f1 100644 --- a/openstack/common/rpc/impl_qpid.py +++ b/openstack/common/rpc/impl_qpid.py @@ -491,10 +491,10 @@ class Connection(object): self.connection.tcp_nodelay = self.conf.qpid_tcp_nodelay def _register_consumer(self, consumer): - self.consumers[str(consumer.get_receiver())] = consumer + self.consumers[hash(consumer.get_receiver())] = consumer def _lookup_consumer(self, receiver): - return self.consumers[str(receiver)] + return self.consumers[hash(receiver)] def reconnect(self): """Handles reconnecting and re-establishing sessions and queues.""" diff --git a/openstack/common/rpc/matchmaker_redis.py b/openstack/common/rpc/matchmaker_redis.py index 10bb106b..bb24ea4b 100644 --- a/openstack/common/rpc/matchmaker_redis.py +++ b/openstack/common/rpc/matchmaker_redis.py @@ -111,7 +111,10 @@ class MatchMakerRedis(mm_common.HeartbeatMatchMakerBase): self.register(self.topic_host[host], host) def is_alive(self, topic, host): - if self.redis.ttl(host) == -1: + ttl = self.redis.ttl(host) + # old python-redis versions returned -1 for Redis, while new + # versions return None, so check both + if ttl is None or ttl == -1: self.expire(topic, host) return False return True diff --git a/tests/unit/rpc/test_matchmaker_redis.py b/tests/unit/rpc/test_matchmaker_redis.py index cdc0f732..e5a47114 100644 --- a/tests/unit/rpc/test_matchmaker_redis.py +++ b/tests/unit/rpc/test_matchmaker_redis.py @@ -102,10 +102,10 @@ class MatchMakerRedisHeartbeatTestCase(test_base.BaseTestCase, self.assertTrue(ttl > -1) def test_expires_hosts(self): - """Tests that hosts expire. + """Tests hosts expiration. Registers a host, ensures it is registered, then waits for it to - expire. Ensures is no longer registered. + expire. Finally, ensures it is no longer registered. """ self.driver.register(self.topic, self.hosts[0]) @@ -115,12 +115,10 @@ class MatchMakerRedisHeartbeatTestCase(test_base.BaseTestCase, eventlet.sleep(ttl + 1) ttl2 = self.driver.redis.ttl(key_host) - # Tests that host has actually expired. - self.assertEqual(ttl2, -1) + # Tests that host has actually expired + self.assertEqual(ttl2, None) - def test_expired_hosts_removed(self): - """Test that expired hosts are removed from results.""" - self.test_expires_hosts() + # Tests that host is removed from results self.assertEqual(self.driver.queues(self.topic), []) |