summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-08-19 21:03:17 +0000
committerGerrit Code Review <review@openstack.org>2016-08-19 21:03:17 +0000
commitc6ce04c975f1fe40062be59d93bd69c61992d3a6 (patch)
treedb230e3c54f98f30b6461115840d524f7f771ec2
parentcf8e441fa924797b981759b223b149bc36841dd2 (diff)
parent34122ee3cb08b4de379b8095f4b18d64c38f62e2 (diff)
downloadoslo-messaging-c6ce04c975f1fe40062be59d93bd69c61992d3a6.tar.gz
Merge "Add warning when credential is not specified for each host"
-rw-r--r--oslo_messaging/tests/test_urls.py8
-rw-r--r--oslo_messaging/transport.py22
2 files changed, 28 insertions, 2 deletions
diff --git a/oslo_messaging/tests/test_urls.py b/oslo_messaging/tests/test_urls.py
index 176fb75..d722b81 100644
--- a/oslo_messaging/tests/test_urls.py
+++ b/oslo_messaging/tests/test_urls.py
@@ -95,6 +95,14 @@ class TestParseURL(test_utils.BaseTestCase):
username='u', password='p'),
dict(host='host2', port=4321),
]))),
+ ('multi_host_partial_creds',
+ dict(url='foo://u:p@host1,host2/bar', aliases=None,
+ expect=dict(transport='foo',
+ virtual_host='bar',
+ hosts=[
+ dict(host='host1', username='u', password='p'),
+ dict(host='host2'),
+ ]))),
('multi_creds',
dict(url='foo://u1:p1@host1:1234,u2:p2@host2:4321/bar', aliases=None,
expect=dict(transport='foo',
diff --git a/oslo_messaging/transport.py b/oslo_messaging/transport.py
index 703c8aa..c1361e7 100644
--- a/oslo_messaging/transport.py
+++ b/oslo_messaging/transport.py
@@ -34,6 +34,7 @@ import six
from six.moves.urllib import parse
from stevedore import driver
+from oslo_messaging._i18n import _LW
from oslo_messaging import exceptions
LOG = logging.getLogger(__name__)
@@ -372,8 +373,9 @@ class TransportURL(object):
Netloc is parsed following the sequence bellow:
* It is first split by ',' in order to support multiple hosts
- * Username and password should be specified for each host, in
- case of lack of specification they will be omitted::
+ * All hosts should be specified with username/password or not
+ at the same time. In case of lack of specification, username and
+ password will be omitted::
user:pass@host1:port1,host2:port2
@@ -416,6 +418,8 @@ class TransportURL(object):
if url.path.startswith('/'):
virtual_host = parse.unquote(url.path[1:])
+ hosts_with_credentials = []
+ hosts_without_credentials = []
hosts = []
for host in url.netloc.split(','):
@@ -454,9 +458,23 @@ class TransportURL(object):
hostname, port = hostname.split(':', 1)
port = int(port)
+ if username is None or password is None:
+ hosts_without_credentials.append(hostname)
+ else:
+ hosts_with_credentials.append(hostname)
+
hosts.append(TransportHost(hostname=hostname,
port=port,
username=username,
password=password))
+ if (len(hosts_with_credentials) > 0 and
+ len(hosts_without_credentials) > 0):
+ LOG.warning(_LW("All hosts must be set with username/password or "
+ "not at the same time. Hosts with credentials "
+ "are: %(hosts_with_credentials)s. Hosts without "
+ "credentials are %(hosts_without_credentials)s."),
+ {'hosts_with_credentials': hosts_with_credentials,
+ 'hosts_without_credentials':
+ hosts_without_credentials})
return cls(conf, transport, virtual_host, hosts, aliases, query)