From 383abe0f5f5e726246916ab5500026b09f986c11 Mon Sep 17 00:00:00 2001 From: XiaBing Yao Date: Wed, 12 Aug 2015 13:27:26 -0400 Subject: [PATCH] Add if condition for random.shuffle random.shuffle(hosts) only if the length of hosts > 1 then random.shuffle make sense. Change-Id: I94fbf457a7ca73fe11aa97e52a58cde9298015a7 --- oslo_messaging/_drivers/impl_rabbit.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py index 89ea619d9..eaa866882 100644 --- a/oslo_messaging/_drivers/impl_rabbit.py +++ b/oslo_messaging/_drivers/impl_rabbit.py @@ -407,7 +407,8 @@ class Connection(object): LOG.warn(_LW('Selecting the kombu transport through the ' 'transport url (%s) is a experimental feature ' 'and this is not yet supported.') % url.transport) - random.shuffle(url.hosts) + if len(url.hosts) > 1: + random.shuffle(url.hosts) for host in url.hosts: transport = url.transport.replace('kombu+', '') transport = transport.replace('rabbit', 'amqp') @@ -425,7 +426,8 @@ class Connection(object): transport = url.transport.replace('kombu+', '') self._url = "%s://%s" % (transport, virtual_host) else: - random.shuffle(self.rabbit_hosts) + if len(self.rabbit_hosts) > 1: + random.shuffle(self.rabbit_hosts) for adr in self.rabbit_hosts: hostname, port = netutils.parse_host_port( adr, default_port=self.rabbit_port)