From 5f35ef996cdfdca990f95ecb276039227c388ac6 Mon Sep 17 00:00:00 2001 From: Dima Kurguzov Date: Thu, 20 Apr 2017 16:56:12 +0300 Subject: [PATCH] Fix last chroot character trimming --- kombu/transport/zookeeper.py | 12 +++++++++--- t/unit/transport/test_zookeeper.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/kombu/transport/zookeeper.py b/kombu/transport/zookeeper.py index b133f7da..027afc68 100644 --- a/kombu/transport/zookeeper.py +++ b/kombu/transport/zookeeper.py @@ -28,8 +28,7 @@ import socket from kombu.five import Empty from kombu.utils.encoding import bytes_to_str, ensure_bytes -from kombu.utils.json import loads, dumps - +from kombu.utils.json import dumps, loads from . import virtual try: @@ -141,7 +140,7 @@ class Channel(virtual.Channel): def _open(self): conninfo = self.connection.client - self.vhost = os.path.join('/', conninfo.virtual_host[0:-1]) + self.vhost = self._normalize_chroot(conninfo.virtual_host) hosts = [] if conninfo.alt: for host_port in conninfo.alt: @@ -166,6 +165,13 @@ class Channel(virtual.Channel): conn.start() return conn + @staticmethod + def _normalize_chroot(chroot): + chroot = chroot.rstrip('/') + if not len(chroot) or chroot[0] != '/': + chroot = '/' + chroot + return chroot + @property def client(self): if self._client is None: diff --git a/t/unit/transport/test_zookeeper.py b/t/unit/transport/test_zookeeper.py index 7b435f19..03ba5134 100644 --- a/t/unit/transport/test_zookeeper.py +++ b/t/unit/transport/test_zookeeper.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, unicode_literals +import pytest from case import skip from kombu import Connection @@ -25,3 +26,12 @@ class test_Channel: self.channel._queues['foo'] = AssertQueue() self.channel._put(queue='foo', message='bar') + + +@pytest.mark.parametrize('input,expected', ( + ('/', '/'), + ('/root', '/root'), + ('/root/', '/root'), +)) +def test_normalize_chroot(input, expected): + assert zookeeper.Channel._normalize_chroot(input) == expected