diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index fbee19ec3..0dc6e8fa3 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -31,6 +31,8 @@ from ceilometer.openstack.common import log from ceilometer.openstack.common import timeutils from ceilometer import plugin +from urlparse import urljoin + LOG = log.getLogger(__name__) @@ -110,7 +112,19 @@ class SwiftPollster(_Base): LOG.debug(_("Swift endpoint not found")) return - base_url = '%s/v1/%s' % (endpoint, cfg.CONF.reseller_prefix) for t in ksclient.tenants.list(): - yield (t.id, swift.head_account('%s%s' % (base_url, t.id), + yield (t.id, swift.head_account(SwiftPollster. + _neaten_url(endpoint, t.id), ksclient.auth_token)) + + # Transform the registered url to standard and valid format. + @staticmethod + def _neaten_url(endpoint, tenant_id): + + path = 'v1/' + cfg.CONF.reseller_prefix + tenant_id + + # remove the tail '/' of the endpoint. + if endpoint.endswith('/'): + endpoint = endpoint[:-1] + + return urljoin(endpoint, path) diff --git a/tests/objectstore/test_swift.py b/tests/objectstore/test_swift.py index 3f519b8d0..7fc2b950d 100644 --- a/tests/objectstore/test_swift.py +++ b/tests/objectstore/test_swift.py @@ -59,6 +59,21 @@ class TestSwiftPollster(base.TestCase): self.pollster = swift.SwiftPollster() self.manager = TestManager() + def test_objectstore_neaten_url(self): + test_endpoint = 'http://127.0.0.1:8080' + test_tenant_id = 'a7fd1695fa154486a647e44aa99a1b9b' + standard_url = test_endpoint + '/v1/' + 'AUTH_' + test_tenant_id + + self.assertEqual(standard_url, + self.pollster._neaten_url(test_endpoint, + test_tenant_id)) + self.assertEqual(standard_url, + self.pollster._neaten_url(test_endpoint + '/', + test_tenant_id)) + self.assertEqual(standard_url, + self.pollster._neaten_url(test_endpoint + '/v1', + test_tenant_id)) + def test_objectstore_metering(self): self.stubs.Set(swift.SwiftPollster, 'iter_accounts', self.fake_iter_accounts)