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

« back to all changes in this revision

Viewing changes to cinder/tests/test_volume.py

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from cinder import db
32
32
from cinder import exception
33
33
from cinder import flags
 
34
from cinder.image import image_utils
34
35
from cinder.openstack.common import importutils
35
36
from cinder.openstack.common.notifier import api as notifier_api
36
37
from cinder.openstack.common.notifier import test_notifier
85
86
        vol['availability_zone'] = FLAGS.storage_availability_zone
86
87
        vol['status'] = "creating"
87
88
        vol['attach_status'] = "detached"
 
89
        vol['host'] = FLAGS.host
88
90
        if metadata is not None:
89
91
            vol['metadata'] = metadata
90
92
        return db.volume_create(context.get_admin_context(), vol)
200
202
        self.volume.create_volume(self.context, volume_id)
201
203
 
202
204
        self.mox.StubOutWithMock(self.volume.driver, 'delete_volume')
203
 
        self.volume.driver.delete_volume(mox.IgnoreArg()) \
204
 
                                              .AndRaise(exception.VolumeIsBusy)
 
205
        self.volume.driver.delete_volume(
 
206
            mox.IgnoreArg()).AndRaise(exception.VolumeIsBusy(
 
207
                                      volume_name='fake'))
205
208
        self.mox.ReplayAll()
206
209
        res = self.volume.delete_volume(self.context, volume_id)
207
210
        self.assertEqual(True, res)
225
228
                         db.volume_get(
226
229
                             context.get_admin_context(),
227
230
                             volume_dst['id']).id)
228
 
        self.assertEqual(snapshot_id, db.volume_get(
229
 
                context.get_admin_context(),
230
 
                volume_dst['id']).snapshot_id)
 
231
        self.assertEqual(snapshot_id,
 
232
                         db.volume_get(context.get_admin_context(),
 
233
                                       volume_dst['id']).snapshot_id)
231
234
 
232
235
        self.volume.delete_volume(self.context, volume_dst['id'])
233
236
        self.volume.delete_snapshot(self.context, snapshot_id)
273
276
                          self.context,
274
277
                          volume_id)
275
278
 
 
279
    def test_preattach_status_volume(self):
 
280
        """Ensure volume goes into pre-attaching state"""
 
281
        instance_uuid = '12345678-1234-5678-1234-567812345678'
 
282
        mountpoint = "/dev/sdf"
 
283
        volume = db.volume_create(self.context, {'size': 1,
 
284
                                                 'status': 'available'})
 
285
        volume_id = volume['id']
 
286
 
 
287
        volume_api = cinder.volume.api.API()
 
288
        volume_api.attach(self.context, volume, instance_uuid, mountpoint)
 
289
 
 
290
        vol = db.volume_get(self.context, volume_id)
 
291
        self.assertEqual(vol['status'], "available")
 
292
        self.assertEqual(vol['attach_status'], None)
 
293
        self.assertEqual(vol['instance_uuid'], None)
 
294
 
276
295
    def test_concurrent_volumes_get_different_targets(self):
277
296
        """Ensure multiple concurrent volumes get different targets."""
278
297
        volume_ids = []
453
472
        self.volume.create_snapshot(self.context, volume_id, snapshot_id)
454
473
 
455
474
        self.mox.StubOutWithMock(self.volume.driver, 'delete_snapshot')
456
 
        self.volume.driver.delete_snapshot(mox.IgnoreArg()) \
457
 
                                            .AndRaise(exception.SnapshotIsBusy)
 
475
        self.volume.driver.delete_snapshot(
 
476
            mox.IgnoreArg()).AndRaise(
 
477
                exception.SnapshotIsBusy(snapshot_name='fake'))
458
478
        self.mox.ReplayAll()
459
479
        self.volume.delete_snapshot(self.context, snapshot_id)
460
480
        snapshot_ref = db.snapshot_get(self.context, snapshot_id)
475
495
        def fake_copy_image_to_volume(context, volume, image_id):
476
496
            pass
477
497
 
 
498
        def fake_fetch_to_raw(context, image_service, image_id, vol_path):
 
499
            pass
 
500
 
478
501
        dst_fd, dst_path = tempfile.mkstemp()
479
502
        os.close(dst_fd)
480
503
        self.stubs.Set(self.volume.driver, 'local_path', fake_local_path)
 
504
        self.stubs.Set(image_utils, 'fetch_to_raw', fake_fetch_to_raw)
481
505
        if fakeout_copy_image_to_volume:
482
506
            self.stubs.Set(self.volume, '_copy_image_to_volume',
483
507
                           fake_copy_image_to_volume)
485
509
        image_id = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
486
510
        volume_id = 1
487
511
        # creating volume testdata
488
 
        db.volume_create(self.context, {'id': volume_id,
489
 
                            'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
490
 
                            'display_description': 'Test Desc',
491
 
                            'size': 20,
492
 
                            'status': 'creating',
493
 
                            'instance_uuid': None,
494
 
                            'host': 'dummy'})
 
512
        db.volume_create(self.context,
 
513
                         {'id': volume_id,
 
514
                          'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
515
                          'display_description': 'Test Desc',
 
516
                          'size': 20,
 
517
                          'status': 'creating',
 
518
                          'instance_uuid': None,
 
519
                          'host': 'dummy'})
495
520
        try:
496
521
            self.volume.create_volume(self.context,
497
522
                                      volume_id,
525
550
        image_id = 'aaaaaaaa-0000-0000-0000-000000000000'
526
551
        # creating volume testdata
527
552
        volume_id = 1
528
 
        db.volume_create(self.context, {'id': volume_id,
529
 
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
530
 
                             'display_description': 'Test Desc',
531
 
                             'size': 20,
532
 
                             'status': 'creating',
533
 
                             'host': 'dummy'})
 
553
        db.volume_create(self.context,
 
554
                         {'id': volume_id,
 
555
                          'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
556
                          'display_description': 'Test Desc',
 
557
                          'size': 20,
 
558
                          'status': 'creating',
 
559
                          'host': 'dummy'})
534
560
 
535
561
        self.assertRaises(exception.ImageNotFound,
536
562
                          self.volume.create_volume,
556
582
        image_id = '70a599e0-31e7-49b7-b260-868f441e862b'
557
583
        # creating volume testdata
558
584
        volume_id = 1
559
 
        db.volume_create(self.context, {'id': volume_id,
560
 
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
561
 
                             'display_description': 'Test Desc',
562
 
                             'size': 20,
563
 
                             'status': 'uploading',
564
 
                             'instance_uuid': None,
565
 
                             'host': 'dummy'})
 
585
        db.volume_create(self.context,
 
586
                         {'id': volume_id,
 
587
                          'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
588
                          'display_description': 'Test Desc',
 
589
                          'size': 20,
 
590
                          'status': 'uploading',
 
591
                          'instance_uuid': None,
 
592
                          'host': 'dummy'})
566
593
 
567
594
        try:
568
595
            # start test
569
596
            self.volume.copy_volume_to_image(self.context,
570
 
                                                volume_id,
571
 
                                                image_id)
 
597
                                             volume_id,
 
598
                                             image_id)
572
599
 
573
600
            volume = db.volume_get(self.context, volume_id)
574
601
            self.assertEqual(volume['status'], 'available')
590
617
        image_id = 'a440c04b-79fa-479c-bed1-0b816eaec379'
591
618
        # creating volume testdata
592
619
        volume_id = 1
593
 
        db.volume_create(self.context,
594
 
                         {'id': volume_id,
595
 
                         'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
596
 
                         'display_description': 'Test Desc',
597
 
                         'size': 20,
598
 
                         'status': 'uploading',
599
 
                         'instance_uuid':
600
 
                            'b21f957d-a72f-4b93-b5a5-45b1161abb02',
601
 
                         'host': 'dummy'})
 
620
        db.volume_create(
 
621
            self.context,
 
622
            {'id': volume_id,
 
623
             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
624
             'display_description': 'Test Desc',
 
625
             'size': 20,
 
626
             'status': 'uploading',
 
627
             'instance_uuid': 'b21f957d-a72f-4b93-b5a5-45b1161abb02',
 
628
             'host': 'dummy'})
602
629
 
603
630
        try:
604
631
            # start test
605
632
            self.volume.copy_volume_to_image(self.context,
606
 
                                                volume_id,
607
 
                                                image_id)
 
633
                                             volume_id,
 
634
                                             image_id)
608
635
 
609
636
            volume = db.volume_get(self.context, volume_id)
610
637
            self.assertEqual(volume['status'], 'in-use')
625
652
        image_id = 'aaaaaaaa-0000-0000-0000-000000000000'
626
653
        # creating volume testdata
627
654
        volume_id = 1
628
 
        db.volume_create(self.context, {'id': volume_id,
629
 
                             'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
630
 
                             'display_description': 'Test Desc',
631
 
                             'size': 20,
632
 
                             'status': 'in-use',
633
 
                             'host': 'dummy'})
 
655
        db.volume_create(self.context,
 
656
                         {'id': volume_id,
 
657
                          'updated_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
658
                          'display_description': 'Test Desc',
 
659
                          'size': 20,
 
660
                          'status': 'in-use',
 
661
                          'host': 'dummy'})
634
662
 
635
663
        try:
636
664
            # start test
662
690
        try:
663
691
            volume_id = None
664
692
            volume_api = cinder.volume.api.API(
665
 
                                            image_service=_FakeImageService())
 
693
                image_service=_FakeImageService())
666
694
            volume = volume_api.create(self.context, 2, 'name', 'description',
667
695
                                       image_id=1)
668
696
            volume_id = volume['id']