Skip to content

Commit fe3ae1d

Browse files
committed
Update glance to pass properly tenant_name.
- Update glance with the latest changes in swift.common.client. - Use 5000 for port. - Properly test v2 in tests. - Fixes bug 980196. - Test swift against a specific stable version like for keystone. Change-Id: Iaff536efc92e78e51d8042010ce0eb407c4a71b2
1 parent f0a0c4a commit fe3ae1d

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

etc/glance-api.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ swift_store_auth_version = 2
138138
# Valid schemes are 'http://' and 'https://'
139139
# If no scheme specified, default to 'https://'
140140
# For swauth, use something like '127.0.0.1:8080/v1.0/'
141-
swift_store_auth_address = 127.0.0.1:35357/v2.0/
141+
swift_store_auth_address = 127.0.0.1:5000/v2.0/
142142

143143
# User to authenticate against the Swift authentication service
144144
# If you use Swift authentication service, set it to 'account':'user'

glance/store/swift.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,18 @@ def _make_swift_connection(self, auth_url, user, key):
309309
"(auth_address=%(full_auth_url)s, user=%(user)s, "
310310
"snet=%(snet)s, auth_version=%(auth_version)s)") %
311311
locals())
312+
tenant_name = None
313+
if self.auth_version == '2':
314+
tenant_user = user.split(':')
315+
if len(tenant_user) != 2:
316+
reason = (_("Badly formed tenant:user '%(tenant_user)s' in "
317+
"Swift URI") % locals())
318+
raise exception.BadStoreUri(auth_url, reason)
319+
(tenant_name, user) = tenant_user
320+
312321
return swift_client.Connection(
313322
authurl=full_auth_url, user=user, key=key, snet=snet,
314-
auth_version=auth_version)
323+
tenant_name=tenant_name, auth_version=auth_version)
315324

316325
def _option_get(self, param):
317326
result = getattr(self.conf, param)

glance/tests/unit/test_swift_store.py

+48-26
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ def test_get_size(self):
191191
"""
192192
Test that we can get the size of an object in the swift store
193193
"""
194-
uri = "swift://user:key@auth_address/glance/%s" % FAKE_UUID
194+
uri = "swift://%s:key@auth_address/glance/%s" % (
195+
self.conf['swift_store_user'], FAKE_UUID)
195196
loc = get_location_from_uri(uri)
196197
image_size = self.store.get_size(loc)
197198
self.assertEqual(image_size, 5120)
198199

199200
def test_get(self):
200201
"""Test a "normal" retrieval of an image in chunks"""
201-
uri = "swift://user:key@auth_address/glance/%s" % FAKE_UUID
202+
uri = "swift://%s:key@auth_address/glance/%s" % (
203+
self.conf['swift_store_user'], FAKE_UUID)
202204
loc = get_location_from_uri(uri)
203205
(image_swift, image_size) = self.store.get(loc)
204206
self.assertEqual(image_size, 5120)
@@ -216,8 +218,9 @@ def test_get_with_http_auth(self):
216218
specified either via a Location header with swift+http:// or using
217219
http:// in the swift_store_auth_address config value
218220
"""
219-
loc = get_location_from_uri("swift+http://user:key@auth_address/"
220-
"glance/%s" % FAKE_UUID)
221+
loc = get_location_from_uri("swift+http://%s:key@auth_address/"
222+
"glance/%s" % (
223+
self.conf['swift_store_user'], FAKE_UUID))
221224
(image_swift, image_size) = self.store.get(loc)
222225
self.assertEqual(image_size, 5120)
223226

@@ -233,7 +236,8 @@ def test_get_non_existing(self):
233236
Test that trying to retrieve a swift that doesn't exist
234237
raises an error
235238
"""
236-
loc = get_location_from_uri("swift://user:key@authurl/glance/noexist")
239+
loc = get_location_from_uri("swift://%s:key@authurl/glance/noexist" % (
240+
self.conf['swift_store_user']))
237241
self.assertRaises(exception.NotFound,
238242
self.store.get,
239243
loc)
@@ -244,8 +248,9 @@ def test_add(self):
244248
expected_swift_contents = "*" * expected_swift_size
245249
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
246250
expected_image_id = utils.generate_uuid()
247-
expected_location = 'swift+https://user:key@localhost:8080' + \
248-
'/glance/%s' % expected_image_id
251+
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
252+
expected_location = loc % (self.conf['swift_store_user'],
253+
expected_image_id)
249254
image_swift = StringIO.StringIO(expected_swift_contents)
250255

251256
global SWIFT_PUT_OBJECT_CALLS
@@ -275,28 +280,29 @@ def test_add_auth_url_variations(self):
275280
a variety of different auth_address values
276281
"""
277282
variations = {
278-
'http://localhost:80': 'swift+http://user:key@localhost:80'
283+
'http://localhost:80': 'swift+http://%s:key@localhost:80'
279284
'/glance/%s',
280-
'http://localhost': 'swift+http://user:key@localhost/glance/%s',
281-
'http://localhost/v1': 'swift+http://user:key@localhost'
285+
'http://localhost': 'swift+http://%s:key@localhost/glance/%s',
286+
'http://localhost/v1': 'swift+http://%s:key@localhost'
282287
'/v1/glance/%s',
283-
'http://localhost/v1/': 'swift+http://user:key@localhost'
288+
'http://localhost/v1/': 'swift+http://%s:key@localhost'
284289
'/v1/glance/%s',
285-
'https://localhost': 'swift+https://user:key@localhost/glance/%s',
286-
'https://localhost:8080': 'swift+https://user:key@localhost:8080'
290+
'https://localhost': 'swift+https://%s:key@localhost/glance/%s',
291+
'https://localhost:8080': 'swift+https://%s:key@localhost:8080'
287292
'/glance/%s',
288-
'https://localhost/v1': 'swift+https://user:key@localhost'
293+
'https://localhost/v1': 'swift+https://%s:key@localhost'
289294
'/v1/glance/%s',
290-
'https://localhost/v1/': 'swift+https://user:key@localhost'
295+
'https://localhost/v1/': 'swift+https://%s:key@localhost'
291296
'/v1/glance/%s',
292-
'localhost': 'swift+https://user:key@localhost/glance/%s',
293-
'localhost:8080/v1': 'swift+https://user:key@localhost:8080'
297+
'localhost': 'swift+https://%s:key@localhost/glance/%s',
298+
'localhost:8080/v1': 'swift+https://%s:key@localhost:8080'
294299
'/v1/glance/%s',
295300
}
296301

297302
for variation, expected_location in variations.items():
298303
image_id = utils.generate_uuid()
299-
expected_location = expected_location % image_id
304+
expected_location = expected_location % (
305+
self.conf['swift_store_user'], image_id)
300306
expected_swift_size = FIVE_KB
301307
expected_swift_contents = "*" * expected_swift_size
302308
expected_checksum = \
@@ -362,8 +368,9 @@ def test_add_no_container_and_create(self):
362368
expected_swift_contents = "*" * expected_swift_size
363369
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
364370
expected_image_id = utils.generate_uuid()
365-
expected_location = 'swift+https://user:key@localhost:8080' + \
366-
'/noexist/%s' % expected_image_id
371+
loc = 'swift+https://%s:key@localhost:8080/noexist/%s'
372+
expected_location = loc % (self.conf['swift_store_user'],
373+
expected_image_id)
367374
image_swift = StringIO.StringIO(expected_swift_contents)
368375

369376
global SWIFT_PUT_OBJECT_CALLS
@@ -399,8 +406,9 @@ def test_add_large_object(self):
399406
expected_swift_contents = "*" * expected_swift_size
400407
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
401408
expected_image_id = utils.generate_uuid()
402-
expected_location = 'swift+https://user:key@localhost:8080' + \
403-
'/glance/%s' % expected_image_id
409+
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
410+
expected_location = loc % (self.conf['swift_store_user'],
411+
expected_image_id)
404412
image_swift = StringIO.StringIO(expected_swift_contents)
405413

406414
global SWIFT_PUT_OBJECT_CALLS
@@ -452,8 +460,9 @@ def test_add_large_object_zero_size(self):
452460
expected_swift_contents = "*" * expected_swift_size
453461
expected_checksum = hashlib.md5(expected_swift_contents).hexdigest()
454462
expected_image_id = utils.generate_uuid()
455-
expected_location = 'swift+https://user:key@localhost:8080' + \
456-
'/glance/%s' % expected_image_id
463+
loc = 'swift+https://%s:key@localhost:8080/glance/%s'
464+
expected_location = loc % (self.conf['swift_store_user'],
465+
expected_image_id)
457466
image_swift = StringIO.StringIO(expected_swift_contents)
458467

459468
global SWIFT_PUT_OBJECT_CALLS
@@ -536,7 +545,8 @@ def test_delete(self):
536545
"""
537546
Test we can delete an existing image in the swift store
538547
"""
539-
uri = "swift://user:key@authurl/glance/%s" % FAKE_UUID
548+
uri = "swift://%s:key@authurl/glance/%s" % (
549+
self.conf['swift_store_user'], FAKE_UUID)
540550
loc = get_location_from_uri(uri)
541551
self.store.delete(loc)
542552

@@ -547,7 +557,8 @@ def test_delete_non_existing(self):
547557
Test that trying to delete a swift that doesn't exist
548558
raises an error
549559
"""
550-
loc = get_location_from_uri("swift://user:key@authurl/glance/noexist")
560+
loc = get_location_from_uri("swift://%s:key@authurl/glance/noexist" % (
561+
self.conf['swift_store_user']))
551562
self.assertRaises(exception.NotFound, self.store.delete, loc)
552563

553564

@@ -557,6 +568,7 @@ def setUp(self):
557568
"""Establish a clean test environment"""
558569
self.conf = SWIFT_CONF.copy()
559570
self.conf['swift_store_auth_version'] = '1'
571+
self.conf['swift_store_user'] = 'user'
560572
self.stubs = stubout.StubOutForTesting()
561573
stub_out_swift_common_client(self.stubs, self.conf)
562574
self.store = Store(test_utils.TestConfigOpts(self.conf))
@@ -571,11 +583,21 @@ class TestStoreAuthV2(TestStoreAuthV1):
571583
def setUp(self):
572584
"""Establish a clean test environment"""
573585
self.conf = SWIFT_CONF.copy()
586+
self.conf['swift_store_user'] = 'tenant:user'
574587
self.conf['swift_store_auth_version'] = '2'
575588
self.stubs = stubout.StubOutForTesting()
576589
stub_out_swift_common_client(self.stubs, self.conf)
577590
self.store = Store(test_utils.TestConfigOpts(self.conf))
578591

592+
def test_v2_with_no_tenant(self):
593+
self.conf['swift_store_user'] = 'failme'
594+
uri = "swift://%s:key@auth_address/glance/%s" % (
595+
self.conf['swift_store_user'], FAKE_UUID)
596+
loc = get_location_from_uri(uri)
597+
self.assertRaises(exception.BadStoreUri,
598+
self.store.get,
599+
loc)
600+
579601

580602
class TestChunkReader(unittest.TestCase):
581603

tools/pip-requires

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ webob==1.0.8
1212
wsgiref
1313
argparse
1414
boto==2.1.1
15-
swift
1615
sqlalchemy-migrate>=0.7
1716
httplib2
1817
xattr>=0.6.0
@@ -28,6 +27,7 @@ iso8601>=0.1.4
2827
# Trying to hit a moving target causes our local unittests to fail
2928
# when they should remain unaffected.
3029
-e git://github.com/openstack/keystone.git@ab6be05068068b0902db44b1d60f56eea4fe1215#egg=keystone
30+
-e git://github.com/openstack/swift.git@208b8e85a80e46ddb49dc2035cb292570a20c7db#egg=swift
3131

3232
# Note you will need gcc buildtools installed and must
3333
# have installed libxml headers for lxml to be successfully

0 commit comments

Comments
 (0)