diff --git a/glance/store/swift.py b/glance/store/swift.py index 57ff79022c..a3cd9af081 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -142,14 +142,10 @@ class StoreLocation(glance.store.location.StoreLocation): try: self.obj = path_parts.pop() self.container = path_parts.pop() - if self.scheme == 'swift+http': - self.authurl = 'http://' - else: - self.authurl = '' # default is https anyway if not netloc.startswith('http'): # push hostname back into the remaining to build full authurl path_parts.insert(0, netloc) - self.authurl += '/'.join(path_parts) + self.authurl = '/'.join(path_parts) except IndexError: reason = "Badly formed Swift URI" raise exception.BadStoreUri(uri, reason) @@ -163,16 +159,10 @@ class StoreLocation(glance.store.location.StoreLocation): HTTPS is assumed, unless 'swift+http' is specified. """ - if self.scheme.startswith('swift+http'): - auth_scheme = 'http://' - elif self.scheme.startswith('swift+https'): - auth_scheme = 'https://' - elif self.scheme.startswith('swift'): + if self.scheme in ('swift+https', 'swift'): auth_scheme = 'https://' else: - logger.warn("Unrecognized scheme '%s', defaulting auth url" - " to https", self.scheme) - auth_scheme = 'https://' + auth_scheme = 'http://' full_url = ''.join([auth_scheme, self.authurl]) return full_url diff --git a/tests/unit/test_store_location.py b/tests/unit/test_store_location.py index 537472ac0e..1de6ad3f87 100644 --- a/tests/unit/test_store_location.py +++ b/tests/unit/test_store_location.py @@ -138,6 +138,7 @@ class TestStoreLocation(unittest.TestCase): self.assertEqual("swift", loc.scheme) self.assertEqual("example.com", loc.authurl) + self.assertEqual("https://example.com", loc.swift_auth_url) self.assertEqual("images", loc.container) self.assertEqual("1", loc.obj) self.assertEqual(None, loc.user) @@ -148,6 +149,7 @@ class TestStoreLocation(unittest.TestCase): self.assertEqual("swift+https", loc.scheme) self.assertEqual("authurl.com", loc.authurl) + self.assertEqual("https://authurl.com", loc.swift_auth_url) self.assertEqual("images", loc.container) self.assertEqual("1", loc.obj) self.assertEqual("user", loc.user) @@ -159,17 +161,19 @@ class TestStoreLocation(unittest.TestCase): self.assertEqual("swift+https", loc.scheme) self.assertEqual("authurl.com/v1", loc.authurl) + self.assertEqual("https://authurl.com/v1", loc.swift_auth_url) self.assertEqual("container", loc.container) self.assertEqual("12345", loc.obj) self.assertEqual("user", loc.user) self.assertEqual("pass", loc.key) self.assertEqual(uri, loc.get_uri()) - uri = 'swift://account:user:pass@authurl.com/v1/container/12345' + uri = 'swift+http://account:user:pass@authurl.com/v1/container/12345' loc.parse_uri(uri) - self.assertEqual("swift", loc.scheme) + self.assertEqual("swift+http", loc.scheme) self.assertEqual("authurl.com/v1", loc.authurl) + self.assertEqual("http://authurl.com/v1", loc.swift_auth_url) self.assertEqual("container", loc.container) self.assertEqual("12345", loc.obj) self.assertEqual("account:user", loc.user)