@@ -191,14 +191,16 @@ def test_get_size(self):
191
191
"""
192
192
Test that we can get the size of an object in the swift store
193
193
"""
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 )
195
196
loc = get_location_from_uri (uri )
196
197
image_size = self .store .get_size (loc )
197
198
self .assertEqual (image_size , 5120 )
198
199
199
200
def test_get (self ):
200
201
"""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 )
202
204
loc = get_location_from_uri (uri )
203
205
(image_swift , image_size ) = self .store .get (loc )
204
206
self .assertEqual (image_size , 5120 )
@@ -216,8 +218,9 @@ def test_get_with_http_auth(self):
216
218
specified either via a Location header with swift+http:// or using
217
219
http:// in the swift_store_auth_address config value
218
220
"""
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 ))
221
224
(image_swift , image_size ) = self .store .get (loc )
222
225
self .assertEqual (image_size , 5120 )
223
226
@@ -233,7 +236,8 @@ def test_get_non_existing(self):
233
236
Test that trying to retrieve a swift that doesn't exist
234
237
raises an error
235
238
"""
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' ]))
237
241
self .assertRaises (exception .NotFound ,
238
242
self .store .get ,
239
243
loc )
@@ -244,8 +248,9 @@ def test_add(self):
244
248
expected_swift_contents = "*" * expected_swift_size
245
249
expected_checksum = hashlib .md5 (expected_swift_contents ).hexdigest ()
246
250
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 )
249
254
image_swift = StringIO .StringIO (expected_swift_contents )
250
255
251
256
global SWIFT_PUT_OBJECT_CALLS
@@ -275,28 +280,29 @@ def test_add_auth_url_variations(self):
275
280
a variety of different auth_address values
276
281
"""
277
282
variations = {
278
- 'http://localhost:80' : 'swift+http://user :key@localhost:80'
283
+ 'http://localhost:80' : 'swift+http://%s :key@localhost:80'
279
284
'/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'
282
287
'/v1/glance/%s' ,
283
- 'http://localhost/v1/' : 'swift+http://user :key@localhost'
288
+ 'http://localhost/v1/' : 'swift+http://%s :key@localhost'
284
289
'/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'
287
292
'/glance/%s' ,
288
- 'https://localhost/v1' : 'swift+https://user :key@localhost'
293
+ 'https://localhost/v1' : 'swift+https://%s :key@localhost'
289
294
'/v1/glance/%s' ,
290
- 'https://localhost/v1/' : 'swift+https://user :key@localhost'
295
+ 'https://localhost/v1/' : 'swift+https://%s :key@localhost'
291
296
'/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'
294
299
'/v1/glance/%s' ,
295
300
}
296
301
297
302
for variation , expected_location in variations .items ():
298
303
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 )
300
306
expected_swift_size = FIVE_KB
301
307
expected_swift_contents = "*" * expected_swift_size
302
308
expected_checksum = \
@@ -362,8 +368,9 @@ def test_add_no_container_and_create(self):
362
368
expected_swift_contents = "*" * expected_swift_size
363
369
expected_checksum = hashlib .md5 (expected_swift_contents ).hexdigest ()
364
370
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 )
367
374
image_swift = StringIO .StringIO (expected_swift_contents )
368
375
369
376
global SWIFT_PUT_OBJECT_CALLS
@@ -399,8 +406,9 @@ def test_add_large_object(self):
399
406
expected_swift_contents = "*" * expected_swift_size
400
407
expected_checksum = hashlib .md5 (expected_swift_contents ).hexdigest ()
401
408
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 )
404
412
image_swift = StringIO .StringIO (expected_swift_contents )
405
413
406
414
global SWIFT_PUT_OBJECT_CALLS
@@ -452,8 +460,9 @@ def test_add_large_object_zero_size(self):
452
460
expected_swift_contents = "*" * expected_swift_size
453
461
expected_checksum = hashlib .md5 (expected_swift_contents ).hexdigest ()
454
462
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 )
457
466
image_swift = StringIO .StringIO (expected_swift_contents )
458
467
459
468
global SWIFT_PUT_OBJECT_CALLS
@@ -536,7 +545,8 @@ def test_delete(self):
536
545
"""
537
546
Test we can delete an existing image in the swift store
538
547
"""
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 )
540
550
loc = get_location_from_uri (uri )
541
551
self .store .delete (loc )
542
552
@@ -547,7 +557,8 @@ def test_delete_non_existing(self):
547
557
Test that trying to delete a swift that doesn't exist
548
558
raises an error
549
559
"""
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' ]))
551
562
self .assertRaises (exception .NotFound , self .store .delete , loc )
552
563
553
564
@@ -557,6 +568,7 @@ def setUp(self):
557
568
"""Establish a clean test environment"""
558
569
self .conf = SWIFT_CONF .copy ()
559
570
self .conf ['swift_store_auth_version' ] = '1'
571
+ self .conf ['swift_store_user' ] = 'user'
560
572
self .stubs = stubout .StubOutForTesting ()
561
573
stub_out_swift_common_client (self .stubs , self .conf )
562
574
self .store = Store (test_utils .TestConfigOpts (self .conf ))
@@ -571,11 +583,21 @@ class TestStoreAuthV2(TestStoreAuthV1):
571
583
def setUp (self ):
572
584
"""Establish a clean test environment"""
573
585
self .conf = SWIFT_CONF .copy ()
586
+ self .conf ['swift_store_user' ] = 'tenant:user'
574
587
self .conf ['swift_store_auth_version' ] = '2'
575
588
self .stubs = stubout .StubOutForTesting ()
576
589
stub_out_swift_common_client (self .stubs , self .conf )
577
590
self .store = Store (test_utils .TestConfigOpts (self .conf ))
578
591
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
+
579
601
580
602
class TestChunkReader (unittest .TestCase ):
581
603
0 commit comments