Merge "Ceilometer may generate wrong format swift url in some situations"

This commit is contained in:
Jenkins 2013-06-14 16:53:22 +00:00 committed by Gerrit Code Review
commit af7953a417
2 changed files with 31 additions and 2 deletions

View File

@ -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)

View File

@ -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)