~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/api/v2/test_volumes.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from cinder import exception
26
26
from cinder import flags
27
27
from cinder import test
28
 
from cinder.tests.api.openstack import fakes
 
28
from cinder.tests.api import fakes
 
29
from cinder.tests.api.v2 import stubs
29
30
from cinder.tests.image import fake as fake_image
30
31
from cinder.volume import api as volume_api
31
32
 
46
47
        'status': 'available',
47
48
        'volume_size': 100,
48
49
        'created_at': None,
49
 
        'display_name': 'Default name',
 
50
        'name': 'Default name',
50
51
        'display_description': 'Default description',
51
52
    }
52
53
 
59
60
        fake_image.stub_out_image_service(self.stubs)
60
61
        self.controller = volumes.VolumeController(self.ext_mgr)
61
62
 
62
 
        self.stubs.Set(db, 'volume_get_all', fakes.stub_volume_get_all)
 
63
        self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
63
64
        self.stubs.Set(db, 'volume_get_all_by_project',
64
 
                       fakes.stub_volume_get_all_by_project)
65
 
        self.stubs.Set(volume_api.API, 'get', fakes.stub_volume_get)
66
 
        self.stubs.Set(volume_api.API, 'delete', fakes.stub_volume_delete)
 
65
                       stubs.stub_volume_get_all_by_project)
 
66
        self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
 
67
        self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
 
68
        self.maxDiff = None
67
69
 
68
70
    def test_volume_create(self):
69
 
        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
71
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
70
72
 
71
73
        vol = {
72
74
            "size": 100,
73
 
            "display_name": "Volume Test Name",
 
75
            "name": "Volume Test Name",
74
76
            "display_description": "Volume Test Desc",
75
77
            "availability_zone": "zone1:host1"
76
78
        }
79
81
        res_dict = self.controller.create(req, body)
80
82
        expected = {
81
83
            'volume': {
82
 
                'status': 'fakestatus',
83
 
                'display_description': 'Volume Test Desc',
84
 
                'availability_zone': 'zone1:host1',
85
 
                'display_name': 'Volume Test Name',
86
 
                'attachments': [
87
 
                    {
88
 
                        'device': '/',
89
 
                        'server_id': 'fakeuuid',
90
 
                        'id': '1',
91
 
                        'volume_id': '1'
 
84
                'name': 'Volume Test Name',
 
85
                'id': '1',
 
86
                'links': [
 
87
                    {
 
88
                        'href': 'http://localhost/v1/fake/volumes/1',
 
89
                        'rel': 'self'
 
90
                    },
 
91
                    {
 
92
                        'href': 'http://localhost/fake/volumes/1',
 
93
                        'rel': 'bookmark'
92
94
                    }
93
95
                ],
94
 
                'volume_type': 'vol_type_name',
95
 
                'snapshot_id': None,
96
 
                'metadata': {},
97
 
                'id': '1',
98
 
                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
99
 
                'size': 100
100
96
            }
101
97
        }
102
98
        self.assertEqual(res_dict, expected)
111
107
 
112
108
        vol = {
113
109
            "size": 100,
114
 
            "display_name": "Volume Test Name",
 
110
            "name": "Volume Test Name",
115
111
            "display_description": "Volume Test Desc",
116
112
            "availability_zone": "zone1:host1",
117
113
            "volume_type": db_vol_type['name'],
119
115
        body = {"volume": vol}
120
116
        req = fakes.HTTPRequest.blank('/v2/volumes')
121
117
        res_dict = self.controller.create(req, body)
122
 
        self.assertEquals(res_dict['volume']['volume_type'],
123
 
                          db_vol_type['name'])
 
118
        volume_id = res_dict['volume']['id']
 
119
        self.assertEquals(len(res_dict), 1)
 
120
 
 
121
        self.stubs.Set(volume_api.API, 'get_all',
 
122
                       lambda *args, **kwargs:
 
123
                       [stubs.stub_volume(volume_id,
 
124
                                          volume_type={'name': vol_type})])
 
125
        req = fakes.HTTPRequest.blank('/v2/volumes/detail')
 
126
        res_dict = self.controller.detail(req)
124
127
 
125
128
    def test_volume_creation_fails_with_bad_size(self):
126
129
        vol = {"size": '',
127
 
               "display_name": "Volume Test Name",
 
130
               "name": "Volume Test Name",
128
131
               "display_description": "Volume Test Desc",
129
132
               "availability_zone": "zone1:host1"}
130
133
        body = {"volume": vol}
135
138
                          body)
136
139
 
137
140
    def test_volume_create_with_image_id(self):
138
 
        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
141
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
139
142
        self.ext_mgr.extensions = {'os-image-create': 'fake'}
140
143
        vol = {"size": '1',
141
 
               "display_name": "Volume Test Name",
 
144
               "name": "Volume Test Name",
142
145
               "display_description": "Volume Test Desc",
143
146
               "availability_zone": "nova",
144
147
               "imageRef": 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'}
145
148
        expected = {
146
149
            'volume': {
147
 
                'status': 'fakestatus',
148
 
                'display_description': 'Volume Test Desc',
149
 
                'availability_zone': 'nova',
150
 
                'display_name': 'Volume Test Name',
151
 
                'attachments': [
152
 
                    {
153
 
                        'device': '/',
154
 
                        'server_id': 'fakeuuid',
155
 
                        'id': '1',
156
 
                        'volume_id': '1'
 
150
                'name': 'Volume Test Name',
 
151
                'id': '1',
 
152
                'links': [
 
153
                    {
 
154
                        'href': 'http://localhost/v1/fake/volumes/1',
 
155
                        'rel': 'self'
 
156
                    },
 
157
                    {
 
158
                        'href': 'http://localhost/fake/volumes/1',
 
159
                        'rel': 'bookmark'
157
160
                    }
158
161
                ],
159
 
                'volume_type': 'vol_type_name',
160
 
                'image_id': 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
161
 
                'snapshot_id': None,
162
 
                'metadata': {},
163
 
                'id': '1',
164
 
                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
165
 
                'size': '1'}
 
162
            }
166
163
        }
167
164
        body = {"volume": vol}
168
165
        req = fakes.HTTPRequest.blank('/v2/volumes')
170
167
        self.assertEqual(res_dict, expected)
171
168
 
172
169
    def test_volume_create_with_image_id_and_snapshot_id(self):
173
 
        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
170
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
174
171
        self.stubs.Set(volume_api.API, "get_snapshot", stub_snapshot_get)
175
172
        self.ext_mgr.extensions = {'os-image-create': 'fake'}
176
173
        vol = {
177
174
            "size": '1',
178
 
            "display_name": "Volume Test Name",
 
175
            "name": "Volume Test Name",
179
176
            "display_description": "Volume Test Desc",
180
177
            "availability_zone": "cinder",
181
178
            "imageRef": 'c905cedb-7281-47e4-8a62-f26bc5fc4c77',
189
186
                          body)
190
187
 
191
188
    def test_volume_create_with_image_id_is_integer(self):
192
 
        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
189
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
193
190
        self.ext_mgr.extensions = {'os-image-create': 'fake'}
194
191
        vol = {
195
192
            "size": '1',
196
 
            "display_name": "Volume Test Name",
 
193
            "name": "Volume Test Name",
197
194
            "display_description": "Volume Test Desc",
198
195
            "availability_zone": "cinder",
199
196
            "imageRef": 1234,
206
203
                          body)
207
204
 
208
205
    def test_volume_create_with_image_id_not_uuid_format(self):
209
 
        self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
 
206
        self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
210
207
        self.ext_mgr.extensions = {'os-image-create': 'fake'}
211
208
        vol = {
212
209
            "size": '1',
213
 
            "display_name": "Volume Test Name",
 
210
            "name": "Volume Test Name",
214
211
            "display_description": "Volume Test Desc",
215
212
            "availability_zone": "cinder",
216
213
            "imageRef": '12345'
223
220
                          body)
224
221
 
225
222
    def test_volume_update(self):
226
 
        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
 
223
        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
227
224
        updates = {
228
 
            "display_name": "Updated Test Name",
 
225
            "name": "Updated Test Name",
229
226
        }
230
227
        body = {"volume": updates}
231
228
        req = fakes.HTTPRequest.blank('/v2/volumes/1')
235
232
                'status': 'fakestatus',
236
233
                'display_description': 'displaydesc',
237
234
                'availability_zone': 'fakeaz',
238
 
                'display_name': 'Updated Test Name',
 
235
                'name': 'Updated Test Name',
239
236
                'attachments': [
240
237
                    {
241
238
                        'id': '1',
246
243
                ],
247
244
                'volume_type': 'vol_type_name',
248
245
                'snapshot_id': None,
 
246
                'source_volid': None,
249
247
                'metadata': {},
250
248
                'id': '1',
251
249
                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
252
250
                'size': 1,
 
251
                'links': [
 
252
                    {
 
253
                        'href': 'http://localhost/v1/fake/volumes/1',
 
254
                        'rel': 'self'
 
255
                    },
 
256
                    {
 
257
                        'href': 'http://localhost/fake/volumes/1',
 
258
                        'rel': 'bookmark'
 
259
                    }
 
260
                ],
253
261
            }
254
262
        }
255
263
        self.assertEquals(res_dict, expected)
256
264
 
257
265
    def test_volume_update_metadata(self):
258
 
        self.stubs.Set(volume_api.API, "update", fakes.stub_volume_update)
 
266
        self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
259
267
        updates = {
260
268
            "metadata": {"qos_max_iops": 2000}
261
269
        }
266
274
            'status': 'fakestatus',
267
275
            'display_description': 'displaydesc',
268
276
            'availability_zone': 'fakeaz',
269
 
            'display_name': 'displayname',
 
277
            'name': 'displayname',
270
278
            'attachments': [{
271
279
                'id': '1',
272
280
                'volume_id': '1',
275
283
            }],
276
284
            'volume_type': 'vol_type_name',
277
285
            'snapshot_id': None,
 
286
            'source_volid': None,
278
287
            'metadata': {"qos_max_iops": 2000},
279
288
            'id': '1',
280
289
            'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
281
290
            'size': 1,
 
291
            'links': [
 
292
                {
 
293
                    'href': 'http://localhost/v1/fake/volumes/1',
 
294
                    'rel': 'self'
 
295
                },
 
296
                {
 
297
                    'href': 'http://localhost/fake/volumes/1',
 
298
                    'rel': 'bookmark'
 
299
                }
 
300
            ],
282
301
        }}
283
302
        self.assertEquals(res_dict, expected)
284
303
 
291
310
 
292
311
    def test_update_invalid_body(self):
293
312
        body = {
294
 
            'display_name': 'missing top level volume key'
 
313
            'name': 'missing top level volume key'
295
314
        }
296
315
        req = fakes.HTTPRequest.blank('/v2/volumes/1')
297
316
        self.assertRaises(webob.exc.HTTPUnprocessableEntity,
299
318
                          req, '1', body)
300
319
 
301
320
    def test_update_not_found(self):
302
 
        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
 
321
        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
303
322
        updates = {
304
 
            "display_name": "Updated Test Name",
 
323
            "name": "Updated Test Name",
305
324
        }
306
325
        body = {"volume": updates}
307
326
        req = fakes.HTTPRequest.blank('/v2/volumes/1')
309
328
                          self.controller.update,
310
329
                          req, '1', body)
311
330
 
312
 
    def test_volume_list(self):
 
331
    def test_volume_list_summary(self):
313
332
        self.stubs.Set(volume_api.API, 'get_all',
314
 
                       fakes.stub_volume_get_all_by_project)
315
 
 
 
333
                       stubs.stub_volume_get_all_by_project)
316
334
        req = fakes.HTTPRequest.blank('/v2/volumes')
317
335
        res_dict = self.controller.index(req)
318
336
        expected = {
319
337
            'volumes': [
320
338
                {
321
 
                    'status': 'fakestatus',
322
 
                    'display_description': 'displaydesc',
323
 
                    'availability_zone': 'fakeaz',
324
 
                    'display_name': 'displayname',
325
 
                    'attachments': [
326
 
                        {
327
 
                            'device': '/',
328
 
                            'server_id': 'fakeuuid',
329
 
                            'id': '1',
330
 
                            'volume_id': '1'
 
339
                    'name': 'displayname',
 
340
                    'id': '1',
 
341
                    'links': [
 
342
                        {
 
343
                            'href': 'http://localhost/v1/fake/volumes/1',
 
344
                            'rel': 'self'
 
345
                        },
 
346
                        {
 
347
                            'href': 'http://localhost/fake/volumes/1',
 
348
                            'rel': 'bookmark'
331
349
                        }
332
350
                    ],
333
 
                    'volume_type': 'vol_type_name',
334
 
                    'snapshot_id': None,
335
 
                    'metadata': {},
336
 
                    'id': '1',
337
 
                    'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
338
 
                    'size': 1
339
351
                }
340
352
            ]
341
353
        }
343
355
 
344
356
    def test_volume_list_detail(self):
345
357
        self.stubs.Set(volume_api.API, 'get_all',
346
 
                       fakes.stub_volume_get_all_by_project)
 
358
                       stubs.stub_volume_get_all_by_project)
347
359
        req = fakes.HTTPRequest.blank('/v2/volumes/detail')
348
 
        res_dict = self.controller.index(req)
 
360
        res_dict = self.controller.detail(req)
349
361
        expected = {
350
362
            'volumes': [
351
363
                {
352
364
                    'status': 'fakestatus',
353
365
                    'display_description': 'displaydesc',
354
366
                    'availability_zone': 'fakeaz',
355
 
                    'display_name': 'displayname',
 
367
                    'name': 'displayname',
356
368
                    'attachments': [
357
369
                        {
358
370
                            'device': '/',
363
375
                    ],
364
376
                    'volume_type': 'vol_type_name',
365
377
                    'snapshot_id': None,
 
378
                    'source_volid': None,
366
379
                    'metadata': {},
367
380
                    'id': '1',
368
381
                    'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
369
 
                    'size': 1
 
382
                    'size': 1,
 
383
                    'links': [
 
384
                        {
 
385
                            'href': 'http://localhost/v1/fake/volumes/1',
 
386
                            'rel': 'self'
 
387
                        },
 
388
                        {
 
389
                            'href': 'http://localhost/fake/volumes/1',
 
390
                            'rel': 'bookmark'
 
391
                        }
 
392
                    ],
370
393
                }
371
394
            ]
372
395
        }
373
396
        self.assertEqual(res_dict, expected)
374
397
 
 
398
    def test_volume_index_with_marker(self):
 
399
        def stub_volume_get_all_by_project(context, project_id, marker, limit,
 
400
                                           sort_key, sort_dir):
 
401
            return [
 
402
                stubs.stub_volume(1, display_name='vol1'),
 
403
                stubs.stub_volume(2, display_name='vol2'),
 
404
            ]
 
405
        self.stubs.Set(db, 'volume_get_all_by_project',
 
406
                       stub_volume_get_all_by_project)
 
407
        req = fakes.HTTPRequest.blank('/v2/volumes?marker=1')
 
408
        res_dict = self.controller.index(req)
 
409
        volumes = res_dict['volumes']
 
410
        self.assertEquals(len(volumes), 2)
 
411
        self.assertEquals(volumes[0]['id'], 1)
 
412
        self.assertEquals(volumes[1]['id'], 2)
 
413
 
 
414
    def test_volume_index_limit(self):
 
415
        req = fakes.HTTPRequest.blank('/v2/volumes?limit=1')
 
416
        res_dict = self.controller.index(req)
 
417
        volumes = res_dict['volumes']
 
418
        self.assertEquals(len(volumes), 1)
 
419
 
 
420
    def test_volume_index_limit_negative(self):
 
421
        req = fakes.HTTPRequest.blank('/v2/volumes?limit=-1')
 
422
        self.assertRaises(webob.exc.HTTPBadRequest,
 
423
                          self.controller.index,
 
424
                          req)
 
425
 
 
426
    def test_volume_index_limit_non_int(self):
 
427
        req = fakes.HTTPRequest.blank('/v2/volumes?limit=a')
 
428
        self.assertRaises(webob.exc.HTTPBadRequest,
 
429
                          self.controller.index,
 
430
                          req)
 
431
 
 
432
    def test_volume_index_limit_marker(self):
 
433
        req = fakes.HTTPRequest.blank('/v2/volumes?marker=1&limit=1')
 
434
        res_dict = self.controller.index(req)
 
435
        volumes = res_dict['volumes']
 
436
        self.assertEquals(len(volumes), 1)
 
437
        self.assertEquals(volumes[0]['id'], '1')
 
438
 
 
439
    def test_volume_detail_with_marker(self):
 
440
        def stub_volume_get_all_by_project(context, project_id, marker, limit,
 
441
                                           sort_key, sort_dir):
 
442
            return [
 
443
                stubs.stub_volume(1, display_name='vol1'),
 
444
                stubs.stub_volume(2, display_name='vol2'),
 
445
            ]
 
446
        self.stubs.Set(db, 'volume_get_all_by_project',
 
447
                       stub_volume_get_all_by_project)
 
448
        req = fakes.HTTPRequest.blank('/v2/volumes/detail?marker=1')
 
449
        res_dict = self.controller.index(req)
 
450
        volumes = res_dict['volumes']
 
451
        self.assertEquals(len(volumes), 2)
 
452
        self.assertEquals(volumes[0]['id'], 1)
 
453
        self.assertEquals(volumes[1]['id'], 2)
 
454
 
 
455
    def test_volume_detail_limit(self):
 
456
        req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=1')
 
457
        res_dict = self.controller.index(req)
 
458
        volumes = res_dict['volumes']
 
459
        self.assertEquals(len(volumes), 1)
 
460
 
 
461
    def test_volume_detail_limit_negative(self):
 
462
        req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=-1')
 
463
        self.assertRaises(webob.exc.HTTPBadRequest,
 
464
                          self.controller.index,
 
465
                          req)
 
466
 
 
467
    def test_volume_detail_limit_non_int(self):
 
468
        req = fakes.HTTPRequest.blank('/v2/volumes/detail?limit=a')
 
469
        self.assertRaises(webob.exc.HTTPBadRequest,
 
470
                          self.controller.index,
 
471
                          req)
 
472
 
 
473
    def test_volume_detail_limit_marker(self):
 
474
        req = fakes.HTTPRequest.blank('/v2/volumes/detail?marker=1&limit=1')
 
475
        res_dict = self.controller.index(req)
 
476
        volumes = res_dict['volumes']
 
477
        self.assertEquals(len(volumes), 1)
 
478
        self.assertEquals(volumes[0]['id'], '1')
 
479
 
375
480
    def test_volume_list_by_name(self):
376
 
        def stub_volume_get_all_by_project(context, project_id):
 
481
        def stub_volume_get_all_by_project(context, project_id, marker, limit,
 
482
                                           sort_key, sort_dir):
377
483
            return [
378
 
                fakes.stub_volume(1, display_name='vol1'),
379
 
                fakes.stub_volume(2, display_name='vol2'),
380
 
                fakes.stub_volume(3, display_name='vol3'),
 
484
                stubs.stub_volume(1, display_name='vol1'),
 
485
                stubs.stub_volume(2, display_name='vol2'),
 
486
                stubs.stub_volume(3, display_name='vol3'),
381
487
            ]
382
488
        self.stubs.Set(db, 'volume_get_all_by_project',
383
489
                       stub_volume_get_all_by_project)
384
490
 
385
 
        # no display_name filter
 
491
        # no name filter
386
492
        req = fakes.HTTPRequest.blank('/v2/volumes')
387
493
        resp = self.controller.index(req)
388
494
        self.assertEqual(len(resp['volumes']), 3)
389
 
        # filter on display_name
390
 
        req = fakes.HTTPRequest.blank('/v2/volumes?display_name=vol2')
 
495
        # filter on name
 
496
        req = fakes.HTTPRequest.blank('/v2/volumes?name=vol2')
391
497
        resp = self.controller.index(req)
392
498
        self.assertEqual(len(resp['volumes']), 1)
393
 
        self.assertEqual(resp['volumes'][0]['display_name'], 'vol2')
 
499
        self.assertEqual(resp['volumes'][0]['name'], 'vol2')
394
500
        # filter no match
395
 
        req = fakes.HTTPRequest.blank('/v2/volumes?display_name=vol4')
 
501
        req = fakes.HTTPRequest.blank('/v2/volumes?name=vol4')
396
502
        resp = self.controller.index(req)
397
503
        self.assertEqual(len(resp['volumes']), 0)
398
504
 
399
505
    def test_volume_list_by_status(self):
400
 
        def stub_volume_get_all_by_project(context, project_id):
 
506
        def stub_volume_get_all_by_project(context, project_id, marker, limit,
 
507
                                           sort_key, sort_dir):
401
508
            return [
402
 
                fakes.stub_volume(1, display_name='vol1', status='available'),
403
 
                fakes.stub_volume(2, display_name='vol2', status='available'),
404
 
                fakes.stub_volume(3, display_name='vol3', status='in-use'),
 
509
                stubs.stub_volume(1, display_name='vol1', status='available'),
 
510
                stubs.stub_volume(2, display_name='vol2', status='available'),
 
511
                stubs.stub_volume(3, display_name='vol3', status='in-use'),
405
512
            ]
406
513
        self.stubs.Set(db, 'volume_get_all_by_project',
407
514
                       stub_volume_get_all_by_project)
408
515
        # no status filter
409
 
        req = fakes.HTTPRequest.blank('/v2/volumes')
410
 
        resp = self.controller.index(req)
 
516
        req = fakes.HTTPRequest.blank('/v2/volumes/details')
 
517
        resp = self.controller.detail(req)
411
518
        self.assertEqual(len(resp['volumes']), 3)
412
519
        # single match
413
 
        req = fakes.HTTPRequest.blank('/v2/volumes?status=in-use')
414
 
        resp = self.controller.index(req)
 
520
        req = fakes.HTTPRequest.blank('/v2/volumes/details?status=in-use')
 
521
        resp = self.controller.detail(req)
415
522
        self.assertEqual(len(resp['volumes']), 1)
416
523
        self.assertEqual(resp['volumes'][0]['status'], 'in-use')
417
524
        # multiple match
418
 
        req = fakes.HTTPRequest.blank('/v2/volumes?status=available')
419
 
        resp = self.controller.index(req)
 
525
        req = fakes.HTTPRequest.blank('/v2/volumes/details/?status=available')
 
526
        resp = self.controller.detail(req)
420
527
        self.assertEqual(len(resp['volumes']), 2)
421
528
        for volume in resp['volumes']:
422
529
            self.assertEqual(volume['status'], 'available')
423
530
        # multiple filters
424
 
        req = fakes.HTTPRequest.blank('/v2/volumes?status=available&'
425
 
                                      'display_name=vol1')
426
 
        resp = self.controller.index(req)
 
531
        req = fakes.HTTPRequest.blank('/v2/volumes/details/?status=available&'
 
532
                                      'name=vol1')
 
533
        resp = self.controller.detail(req)
427
534
        self.assertEqual(len(resp['volumes']), 1)
428
 
        self.assertEqual(resp['volumes'][0]['display_name'], 'vol1')
 
535
        self.assertEqual(resp['volumes'][0]['name'], 'vol1')
429
536
        self.assertEqual(resp['volumes'][0]['status'], 'available')
430
537
        # no match
431
 
        req = fakes.HTTPRequest.blank('/v2/volumes?status=in-use&'
432
 
                                      'display_name=vol1')
433
 
        resp = self.controller.index(req)
 
538
        req = fakes.HTTPRequest.blank('/v2/volumes/details?status=in-use&'
 
539
                                      'name=vol1')
 
540
        resp = self.controller.detail(req)
434
541
        self.assertEqual(len(resp['volumes']), 0)
435
542
 
436
543
    def test_volume_show(self):
441
548
                'status': 'fakestatus',
442
549
                'display_description': 'displaydesc',
443
550
                'availability_zone': 'fakeaz',
444
 
                'display_name': 'displayname',
 
551
                'name': 'displayname',
445
552
                'attachments': [
446
553
                    {
447
554
                        'device': '/',
452
559
                ],
453
560
                'volume_type': 'vol_type_name',
454
561
                'snapshot_id': None,
 
562
                'source_volid': None,
455
563
                'metadata': {},
456
564
                'id': '1',
457
565
                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
458
 
                'size': 1
 
566
                'size': 1,
 
567
                'links': [
 
568
                    {
 
569
                        'href': 'http://localhost/v1/fake/volumes/1',
 
570
                        'rel': 'self'
 
571
                    },
 
572
                    {
 
573
                        'href': 'http://localhost/fake/volumes/1',
 
574
                        'rel': 'bookmark'
 
575
                    }
 
576
                ],
459
577
            }
460
578
        }
461
579
        self.assertEqual(res_dict, expected)
462
580
 
463
581
    def test_volume_show_no_attachments(self):
464
582
        def stub_volume_get(self, context, volume_id):
465
 
            return fakes.stub_volume(volume_id, attach_status='detached')
 
583
            return stubs.stub_volume(volume_id, attach_status='detached')
466
584
 
467
585
        self.stubs.Set(volume_api.API, 'get', stub_volume_get)
468
586
 
473
591
                'status': 'fakestatus',
474
592
                'display_description': 'displaydesc',
475
593
                'availability_zone': 'fakeaz',
476
 
                'display_name': 'displayname',
 
594
                'name': 'displayname',
477
595
                'attachments': [],
478
596
                'volume_type': 'vol_type_name',
479
597
                'snapshot_id': None,
 
598
                'source_volid': None,
480
599
                'metadata': {},
481
600
                'id': '1',
482
601
                'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
483
 
                'size': 1
 
602
                'size': 1,
 
603
                'links': [
 
604
                    {
 
605
                        'href': 'http://localhost/v1/fake/volumes/1',
 
606
                        'rel': 'self'
 
607
                    },
 
608
                    {
 
609
                        'href': 'http://localhost/fake/volumes/1',
 
610
                        'rel': 'bookmark'
 
611
                    }
 
612
                ],
484
613
            }
485
614
        }
 
615
 
486
616
        self.assertEqual(res_dict, expected)
487
617
 
488
618
    def test_volume_show_no_volume(self):
489
 
        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
 
619
        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
490
620
 
491
621
        req = fakes.HTTPRequest.blank('/v2/volumes/1')
492
622
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
498
628
        self.assertEqual(resp.status_int, 202)
499
629
 
500
630
    def test_volume_delete_no_volume(self):
501
 
        self.stubs.Set(volume_api.API, "get", fakes.stub_volume_get_notfound)
 
631
        self.stubs.Set(volume_api.API, "get", stubs.stub_volume_get_notfound)
502
632
 
503
633
        req = fakes.HTTPRequest.blank('/v2/volumes/1')
504
634
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
541
671
        self.assertEqual(tree.tag, NS + 'volume')
542
672
 
543
673
        for attr in ('id', 'status', 'size', 'availability_zone', 'created_at',
544
 
                     'display_name', 'display_description', 'volume_type',
545
 
                     'snapshot_id'):
 
674
                     'name', 'display_description', 'volume_type',
 
675
                     'snapshot_id', 'source_volid'):
546
676
            self.assertEqual(str(vol[attr]), tree.get(attr))
547
677
 
548
678
        for child in tree:
577
707
                    device='/foo'
578
708
                )
579
709
            ],
580
 
            display_name='vol_name',
 
710
            name='vol_name',
581
711
            display_description='vol_desc',
582
712
            volume_type='vol_type',
583
713
            snapshot_id='snap_id',
 
714
            source_volid='source_volid',
584
715
            metadata=dict(
585
716
                foo='bar',
586
717
                baz='quux',
610
741
                        device='/foo1'
611
742
                    )
612
743
                ],
613
 
                display_name='vol1_name',
 
744
                name='vol1_name',
614
745
                display_description='vol1_desc',
615
746
                volume_type='vol1_type',
616
747
                snapshot_id='snap1_id',
617
 
                metadata=dict(
618
 
                            foo='vol1_foo',
619
 
                            bar='vol1_bar',
620
 
                ),
621
 
            ),
 
748
                source_volid=None,
 
749
                metadata=dict(foo='vol1_foo',
 
750
                              bar='vol1_bar', ), ),
622
751
            dict(
623
752
                id='vol2_id',
624
753
                status='vol2_status',
625
754
                size=1024,
626
755
                availability_zone='vol2_availability',
627
756
                created_at=datetime.datetime.now(),
628
 
                attachments=[
629
 
                    dict(
630
 
                        id='vol2_id',
631
 
                        volume_id='vol2_id',
632
 
                        server_id='instance_uuid',
633
 
                        device='/foo2')],
634
 
                display_name='vol2_name',
 
757
                attachments=[dict(id='vol2_id',
 
758
                                  volume_id='vol2_id',
 
759
                                  server_id='instance_uuid',
 
760
                                  device='/foo2')],
 
761
                name='vol2_name',
635
762
                display_description='vol2_desc',
636
763
                volume_type='vol2_type',
637
764
                snapshot_id='snap2_id',
638
 
                metadata=dict(
639
 
                            foo='vol2_foo',
640
 
                            bar='vol2_bar',
641
 
                ),
642
 
            )
643
 
        ]
 
765
                source_volid=None,
 
766
                metadata=dict(foo='vol2_foo',
 
767
                              bar='vol2_bar', ), )]
644
768
        text = serializer.serialize(dict(volumes=raw_volumes))
645
769
 
646
770
        print text
670
794
        }
671
795
        self.assertEquals(request['body'], expected)
672
796
 
673
 
    def test_display_name(self):
 
797
    def test_name(self):
674
798
        self_request = """
675
799
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
676
800
        size="1"
677
 
        display_name="Volume-xml"></volume>"""
 
801
        name="Volume-xml"></volume>"""
678
802
        request = self.deserializer.deserialize(self_request)
679
803
        expected = {
680
804
            "volume": {
681
805
                "size": "1",
682
 
                "display_name": "Volume-xml",
 
806
                "name": "Volume-xml",
683
807
            },
684
808
        }
685
809
        self.assertEquals(request['body'], expected)
688
812
        self_request = """
689
813
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
690
814
        size="1"
691
 
        display_name="Volume-xml"
 
815
        name="Volume-xml"
692
816
        display_description="description"></volume>"""
693
817
        request = self.deserializer.deserialize(self_request)
694
818
        expected = {
695
819
            "volume": {
696
820
                "size": "1",
697
 
                "display_name": "Volume-xml",
 
821
                "name": "Volume-xml",
698
822
                "display_description": "description",
699
823
            },
700
824
        }
704
828
        self_request = """
705
829
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
706
830
        size="1"
707
 
        display_name="Volume-xml"
 
831
        name="Volume-xml"
708
832
        display_description="description"
709
833
        volume_type="289da7f8-6440-407c-9fb4-7db01ec49164"></volume>"""
710
834
        request = self.deserializer.deserialize(self_request)
711
835
        expected = {
712
836
            "volume": {
713
 
                "display_name": "Volume-xml",
 
837
                "name": "Volume-xml",
714
838
                "size": "1",
715
 
                "display_name": "Volume-xml",
 
839
                "name": "Volume-xml",
716
840
                "display_description": "description",
717
841
                "volume_type": "289da7f8-6440-407c-9fb4-7db01ec49164",
718
842
            },
723
847
        self_request = """
724
848
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
725
849
        size="1"
726
 
        display_name="Volume-xml"
 
850
        name="Volume-xml"
727
851
        display_description="description"
728
852
        volume_type="289da7f8-6440-407c-9fb4-7db01ec49164"
729
853
        availability_zone="us-east1"></volume>"""
731
855
        expected = {
732
856
            "volume": {
733
857
                "size": "1",
734
 
                "display_name": "Volume-xml",
 
858
                "name": "Volume-xml",
735
859
                "display_description": "description",
736
860
                "volume_type": "289da7f8-6440-407c-9fb4-7db01ec49164",
737
861
                "availability_zone": "us-east1",
742
866
    def test_metadata(self):
743
867
        self_request = """
744
868
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
745
 
        display_name="Volume-xml"
 
869
        name="Volume-xml"
746
870
        size="1">
747
871
        <metadata><meta key="Type">work</meta></metadata></volume>"""
748
872
        request = self.deserializer.deserialize(self_request)
749
873
        expected = {
750
874
            "volume": {
751
 
                "display_name": "Volume-xml",
 
875
                "name": "Volume-xml",
752
876
                "size": "1",
753
877
                "metadata": {
754
878
                    "Type": "work",
761
885
        self_request = """
762
886
<volume xmlns="http://docs.openstack.org/api/openstack-volume/2.0/content"
763
887
        size="1"
764
 
        display_name="Volume-xml"
 
888
        name="Volume-xml"
765
889
        display_description="description"
766
890
        volume_type="289da7f8-6440-407c-9fb4-7db01ec49164"
767
891
        availability_zone="us-east1">
770
894
        expected = {
771
895
            "volume": {
772
896
                "size": "1",
773
 
                "display_name": "Volume-xml",
 
897
                "name": "Volume-xml",
774
898
                "display_description": "description",
775
899
                "volume_type": "289da7f8-6440-407c-9fb4-7db01ec49164",
776
900
                "availability_zone": "us-east1",