From af72ad9a924340a48651813f7156bc3d4a37f8d5 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" <eric.guo@easystack.cn> Date: Tue, 18 Mar 2014 21:42:14 +0800 Subject: [PATCH] Refactor AMQP message broker selection Drop redundant variable, make code more clean. Partial-Bug: #1261631 Change-Id: I5fd71ce3bcd3a82839204ee1fb130de3a3e1d3ac --- oslo/messaging/_drivers/impl_qpid.py | 7 ++----- oslo/messaging/_drivers/impl_rabbit.py | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/oslo/messaging/_drivers/impl_qpid.py b/oslo/messaging/_drivers/impl_qpid.py index f9b275f70..f3988409b 100644 --- a/oslo/messaging/_drivers/impl_qpid.py +++ b/oslo/messaging/_drivers/impl_qpid.py @@ -473,10 +473,7 @@ class Connection(object): } params.update(server_params or {}) - self.brokers = params['qpid_hosts'] - - brokers_count = len(self.brokers) - self.next_broker_indices = itertools.cycle(range(brokers_count)) + self.brokers = itertools.cycle(params['qpid_hosts']) self.username = params['username'] self.password = params['password'] @@ -515,7 +512,7 @@ class Connection(object): except qpid_exceptions.ConnectionError: pass - broker = self.brokers[next(self.next_broker_indices)] + broker = six.next(self.brokers) try: self.connection_create(broker) diff --git a/oslo/messaging/_drivers/impl_rabbit.py b/oslo/messaging/_drivers/impl_rabbit.py index 887a19a78..5b6cf03bc 100644 --- a/oslo/messaging/_drivers/impl_rabbit.py +++ b/oslo/messaging/_drivers/impl_rabbit.py @@ -466,10 +466,7 @@ class Connection(object): params_list.append(params) - self.params_list = params_list - - brokers_count = len(self.params_list) - self.next_broker_indices = itertools.cycle(range(brokers_count)) + self.params_list = itertools.cycle(params_list) self.memory_transport = self.conf.fake_rabbit @@ -575,7 +572,7 @@ class Connection(object): attempt = 0 while True: - params = self.params_list[next(self.next_broker_indices)] + params = six.next(self.params_list) attempt += 1 try: self._connect(params)