Merge "Corrects a flaw in the treatment of swift endpoints"

This commit is contained in:
Jenkins 2014-06-17 11:43:38 +00:00 committed by Gerrit Code Review
commit 668929eb40
2 changed files with 15 additions and 16 deletions

View File

@ -79,8 +79,8 @@ class _Base(plugin.CentralPollster):
def _neaten_url(endpoint, tenant_id): def _neaten_url(endpoint, tenant_id):
"""Transform the registered url to standard and valid format. """Transform the registered url to standard and valid format.
""" """
return urlparse.urljoin(endpoint, return urlparse.urljoin(endpoint.split('/v1')[0].rstrip('/') + '/',
'/v1/' + cfg.CONF.reseller_prefix + tenant_id) 'v1/' + cfg.CONF.reseller_prefix + tenant_id)
class ObjectsPollster(_Base): class ObjectsPollster(_Base):

View File

@ -131,22 +131,21 @@ class TestSwiftPollster(testscenarios.testcase.WithScenarios,
self.assertEqual(self.ACCOUNTS[0][0], data[0][0]) self.assertEqual(self.ACCOUNTS[0][0], data[0][0])
def test_neaten_url(self): 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' 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, url = swift._Base._neaten_url(test_endpoint, test_tenant_id)
swift._Base._neaten_url(test_endpoint, self.assertEqual(standard_url, url)
test_tenant_id)) url = swift._Base._neaten_url(test_endpoint + '/', test_tenant_id)
self.assertEqual(standard_url, self.assertEqual(standard_url, url)
swift._Base._neaten_url(test_endpoint + '/', url = swift._Base._neaten_url(test_endpoint + '/v1',
test_tenant_id)) test_tenant_id)
self.assertEqual(standard_url, self.assertEqual(standard_url, url)
swift._Base._neaten_url(test_endpoint + '/v1', url = swift._Base._neaten_url(standard_url, test_tenant_id)
test_tenant_id)) self.assertEqual(standard_url, url)
self.assertEqual(standard_url,
swift._Base._neaten_url(standard_url,
test_tenant_id))
def test_metering(self): def test_metering(self):
with PatchObject(self.factory, '_iter_accounts', with PatchObject(self.factory, '_iter_accounts',