From bbf4f71bde3266f55f17484b9561041d21e3d31a Mon Sep 17 00:00:00 2001 From: replay Date: Wed, 4 Jun 2014 06:22:39 +0300 Subject: [PATCH] Corrects a flaw in the treatment of swift endpoints When keystone has a registered swift endpoint of which the url does not start with '/v1', the object-store pollster is not able to use it correctly. This commit fixes it's behaviour to provide more flexibility in endpoint urls. Change-Id: I579b1cf450f16853ac49f1d248a64a179e6443d9 Closes-Bug: #1325591 --- ceilometer/objectstore/swift.py | 4 ++-- ceilometer/tests/objectstore/test_swift.py | 27 +++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index 99a2b1936..05a076f24 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -80,8 +80,8 @@ class _Base(plugin.PollsterBase): def _neaten_url(endpoint, tenant_id): """Transform the registered url to standard and valid format. """ - return urlparse.urljoin(endpoint, - '/v1/' + cfg.CONF.reseller_prefix + tenant_id) + return urlparse.urljoin(endpoint.split('/v1')[0].rstrip('/') + '/', + 'v1/' + cfg.CONF.reseller_prefix + tenant_id) class ObjectsPollster(_Base): diff --git a/ceilometer/tests/objectstore/test_swift.py b/ceilometer/tests/objectstore/test_swift.py index 3a8472128..fa499ee34 100644 --- a/ceilometer/tests/objectstore/test_swift.py +++ b/ceilometer/tests/objectstore/test_swift.py @@ -132,22 +132,21 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios, self.assertEqual(self.ACCOUNTS[0][0], data[0][0]) def test_neaten_url(self): - test_endpoint = 'http://127.0.0.1:8080' + test_endpoints = ['http://127.0.0.1:8080', + 'http://127.0.0.1:8080/swift'] test_tenant_id = 'a7fd1695fa154486a647e44aa99a1b9b' - standard_url = test_endpoint + '/v1/' + 'AUTH_' + test_tenant_id + for test_endpoint in test_endpoints: + standard_url = test_endpoint + '/v1/AUTH_' + test_tenant_id - self.assertEqual(standard_url, - swift._Base._neaten_url(test_endpoint, - test_tenant_id)) - self.assertEqual(standard_url, - swift._Base._neaten_url(test_endpoint + '/', - test_tenant_id)) - self.assertEqual(standard_url, - swift._Base._neaten_url(test_endpoint + '/v1', - test_tenant_id)) - self.assertEqual(standard_url, - swift._Base._neaten_url(standard_url, - test_tenant_id)) + url = swift._Base._neaten_url(test_endpoint, test_tenant_id) + self.assertEqual(standard_url, url) + url = swift._Base._neaten_url(test_endpoint + '/', test_tenant_id) + self.assertEqual(standard_url, url) + url = swift._Base._neaten_url(test_endpoint + '/v1', + test_tenant_id) + self.assertEqual(standard_url, url) + url = swift._Base._neaten_url(standard_url, test_tenant_id) + self.assertEqual(standard_url, url) def test_metering(self): with PatchObject(self.factory, '_iter_accounts',