Merge "Update glance to pass properly tenant_name."

This commit is contained in:
Jenkins 2012-05-15 20:28:27 +00:00 committed by Gerrit Code Review
commit 6880a4ecf6
4 changed files with 60 additions and 29 deletions

View File

@ -138,7 +138,7 @@ swift_store_auth_version = 2
# Valid schemes are 'http://' and 'https://'
# If no scheme specified, default to 'https://'
# For swauth, use something like '127.0.0.1:8080/v1.0/'
swift_store_auth_address = 127.0.0.1:35357/v2.0/
swift_store_auth_address = 127.0.0.1:5000/v2.0/
# User to authenticate against the Swift authentication service
# If you use Swift authentication service, set it to 'account':'user'

View File

@ -309,9 +309,18 @@ class Store(glance.store.base.Store):
"(auth_address=%(full_auth_url)s, user=%(user)s, "
"snet=%(snet)s, auth_version=%(auth_version)s)") %
locals())
tenant_name = None
if self.auth_version == '2':
tenant_user = user.split(':')
if len(tenant_user) != 2:
reason = (_("Badly formed tenant:user '%(tenant_user)s' in "
"Swift URI") % locals())
raise exception.BadStoreUri(auth_url, reason)
(tenant_name, user) = tenant_user
return swift_client.Connection(
authurl=full_auth_url, user=user, key=key, snet=snet,
auth_version=auth_version)
tenant_name=tenant_name, auth_version=auth_version)
def _option_get(self, param):
result = getattr(self.conf, param)

View File

@ -191,14 +191,16 @@ class SwiftTests(object):
"""
Test that we can get the size of an object in the swift store
"""
uri = "swift://user:key@auth_address/glance/%s" % FAKE_UUID
uri = "swift://%s:key@auth_address/glance/%s" % (
self.conf['swift_store_user'], FAKE_UUID)
loc = get_location_from_uri(uri)
image_size = self.store.get_size(loc)
self.assertEqual(image_size, 5120)
def test_get(self):
"""Test a "normal" retrieval of an image in chunks"""
uri = "swift://user:key@auth_address/glance/%s" % FAKE_UUID
uri = "swift://%s:key@auth_address/glance/%s" % (
self.conf['swift_store_user'], FAKE_UUID)
loc = get_location_from_uri(uri)
(image_swift, image_size) = self.store.get(loc)
self.assertEqual(image_size, 5120)
@ -216,8 +218,9 @@ class SwiftTests(object):
specified either via a Location header with swift+http:// or using
http:// in the swift_store_auth_address config value
"""
loc = get_location_from_uri("swift+http://user:key@auth_address/"
"glance/%s" % FAKE_UUID)
loc = get_location_from_uri("swift+http://%s:key@auth_address/"
"glance/%s" % (
self.conf['swift_store_user'], FAKE_UUID))
(image_swift, image_size) = self.store.get(loc)
self.assertEqual(image_size, 5120)
@ -233,7 +236,8 @@ class SwiftTests(object):
Test that trying to retrieve a swift that doesn't exist
raises an error
"""
loc = get_location_from_uri("swift://user:key@authurl/glance/noexist")
loc = get_location_from_uri("swift://%s:key@authurl/glance/noexist" % (
self.conf['swift_store_user']))
self.assertRaises(exception.NotFound,
self.store.get,
loc)
@ -244,8 +248,9 @@ class SwiftTests(object):
expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = utils.generate_uuid()
expected_location = 'swift+https://user:key@localhost:8080' + \
'/glance/%s' % expected_image_id
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.conf['swift_store_user'],
expected_image_id)
image_swift = StringIO.StringIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
@ -275,28 +280,29 @@ class SwiftTests(object):
a variety of different auth_address values
"""
variations = {
'http://localhost:80': 'swift+http://user:key@localhost:80'
'http://localhost:80': 'swift+http://%s:key@localhost:80'
'/glance/%s',
'http://localhost': 'swift+http://user:key@localhost/glance/%s',
'http://localhost/v1': 'swift+http://user:key@localhost'
'http://localhost': 'swift+http://%s:key@localhost/glance/%s',
'http://localhost/v1': 'swift+http://%s:key@localhost'
'/v1/glance/%s',
'http://localhost/v1/': 'swift+http://user:key@localhost'
'http://localhost/v1/': 'swift+http://%s:key@localhost'
'/v1/glance/%s',
'https://localhost': 'swift+https://user:key@localhost/glance/%s',
'https://localhost:8080': 'swift+https://user:key@localhost:8080'
'https://localhost': 'swift+https://%s:key@localhost/glance/%s',
'https://localhost:8080': 'swift+https://%s:key@localhost:8080'
'/glance/%s',
'https://localhost/v1': 'swift+https://user:key@localhost'
'https://localhost/v1': 'swift+https://%s:key@localhost'
'/v1/glance/%s',
'https://localhost/v1/': 'swift+https://user:key@localhost'
'https://localhost/v1/': 'swift+https://%s:key@localhost'
'/v1/glance/%s',
'localhost': 'swift+https://user:key@localhost/glance/%s',
'localhost:8080/v1': 'swift+https://user:key@localhost:8080'
'localhost': 'swift+https://%s:key@localhost/glance/%s',
'localhost:8080/v1': 'swift+https://%s:key@localhost:8080'
'/v1/glance/%s',
}
for variation, expected_location in variations.items():
image_id = utils.generate_uuid()
expected_location = expected_location % image_id
expected_location = expected_location % (
self.conf['swift_store_user'], image_id)
expected_swift_size = FIVE_KB
expected_swift_contents = "*" * expected_swift_size
expected_checksum = \
@ -362,8 +368,9 @@ class SwiftTests(object):
expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = utils.generate_uuid()
expected_location = 'swift+https://user:key@localhost:8080' + \
'/noexist/%s' % expected_image_id
loc = 'swift+https://%s:key@localhost:8080/noexist/%s'
expected_location = loc % (self.conf['swift_store_user'],
expected_image_id)
image_swift = StringIO.StringIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
@ -399,8 +406,9 @@ class SwiftTests(object):
expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = utils.generate_uuid()
expected_location = 'swift+https://user:key@localhost:8080' + \
'/glance/%s' % expected_image_id
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.conf['swift_store_user'],
expected_image_id)
image_swift = StringIO.StringIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
@ -452,8 +460,9 @@ class SwiftTests(object):
expected_swift_contents = "*" * expected_swift_size
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
expected_image_id = utils.generate_uuid()
expected_location = 'swift+https://user:key@localhost:8080' + \
'/glance/%s' % expected_image_id
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
expected_location = loc % (self.conf['swift_store_user'],
expected_image_id)
image_swift = StringIO.StringIO(expected_swift_contents)
global SWIFT_PUT_OBJECT_CALLS
@ -536,7 +545,8 @@ class SwiftTests(object):
"""
Test we can delete an existing image in the swift store
"""
uri = "swift://user:key@authurl/glance/%s" % FAKE_UUID
uri = "swift://%s:key@authurl/glance/%s" % (
self.conf['swift_store_user'], FAKE_UUID)
loc = get_location_from_uri(uri)
self.store.delete(loc)
@ -547,7 +557,8 @@ class SwiftTests(object):
Test that trying to delete a swift that doesn't exist
raises an error
"""
loc = get_location_from_uri("swift://user:key@authurl/glance/noexist")
loc = get_location_from_uri("swift://%s:key@authurl/glance/noexist" % (
self.conf['swift_store_user']))
self.assertRaises(exception.NotFound, self.store.delete, loc)
@ -557,6 +568,7 @@ class TestStoreAuthV1(unittest.TestCase, SwiftTests):
"""Establish a clean test environment"""
self.conf = SWIFT_CONF.copy()
self.conf['swift_store_auth_version'] = '1'
self.conf['swift_store_user'] = 'user'
self.stubs = stubout.StubOutForTesting()
stub_out_swift_common_client(self.stubs, self.conf)
self.store = Store(test_utils.TestConfigOpts(self.conf))
@ -571,11 +583,21 @@ class TestStoreAuthV2(TestStoreAuthV1):
def setUp(self):
"""Establish a clean test environment"""
self.conf = SWIFT_CONF.copy()
self.conf['swift_store_user'] = 'tenant:user'
self.conf['swift_store_auth_version'] = '2'
self.stubs = stubout.StubOutForTesting()
stub_out_swift_common_client(self.stubs, self.conf)
self.store = Store(test_utils.TestConfigOpts(self.conf))
def test_v2_with_no_tenant(self):
self.conf['swift_store_user'] = 'failme'
uri = "swift://%s:key@auth_address/glance/%s" % (
self.conf['swift_store_user'], FAKE_UUID)
loc = get_location_from_uri(uri)
self.assertRaises(exception.BadStoreUri,
self.store.get,
loc)
class TestChunkReader(unittest.TestCase):

View File

@ -12,7 +12,6 @@ webob==1.0.8
wsgiref
argparse
boto==2.1.1
swift
sqlalchemy-migrate>=0.7
httplib2
xattr>=0.6.0
@ -28,6 +27,7 @@ iso8601>=0.1.4
# Trying to hit a moving target causes our local unittests to fail
# when they should remain unaffected.
-e git://github.com/openstack/keystone.git@ab6be05068068b0902db44b1d60f56eea4fe1215#egg=keystone
-e git://github.com/openstack/swift.git@208b8e85a80e46ddb49dc2035cb292570a20c7db#egg=swift
# Note you will need gcc buildtools installed and must
# have installed libxml headers for lxml to be successfully