diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index faf962c1a..c4a3cb469 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -79,8 +79,8 @@ class _Base(plugin.CentralPollster): 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 f66fed9a3..0d1da1b20 100644 --- a/ceilometer/tests/objectstore/test_swift.py +++ b/ceilometer/tests/objectstore/test_swift.py @@ -131,22 +131,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',