Esempio n. 1
0
 def test_save(self, volume_update):
     db_volume = fake_volume.fake_db_volume()
     volume = objects.Volume._from_db_object(self.context,
                                             objects.Volume(), db_volume)
     volume.display_name = 'foobar'
     volume.save()
     volume_update.assert_called_once_with(self.context, volume.id,
                                           {'display_name': 'foobar'})
Esempio n. 2
0
    def test_get_all(self, volume_get_all):
        db_volume = fake_volume.fake_db_volume()
        volume_get_all.return_value = [db_volume]

        volumes = objects.VolumeList.get_all(self.context,
                                             mock.sentinel.marker,
                                             mock.sentinel.limit,
                                             mock.sentinel.sort_key,
                                             mock.sentinel.sort_dir)
        self.assertEqual(1, len(volumes))
        TestVolume._compare(self, db_volume, volumes[0])
    def test_create_from_snapshot_update_failure(self, snapshot_get_by_id):
        fake_db = mock.MagicMock()
        fake_driver = mock.MagicMock()
        fake_manager = create_volume_manager.CreateVolumeFromSpecTask(fake_db, fake_driver)
        volume = fake_volume.fake_db_volume()
        snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctxt)
        snapshot_get_by_id.return_value = snapshot_obj
        fake_db.volume_get.side_effect = exception.CinderException

        self.assertRaises(
            exception.MetadataUpdateFailure, fake_manager._create_from_snapshot, self.ctxt, volume, snapshot_obj.id
        )
        fake_driver.create_volume_from_snapshot.assert_called_once_with(volume, snapshot_obj)
    def test_create_from_snapshot(self, snapshot_get_by_id, handle_bootable):
        fake_db = mock.MagicMock()
        fake_driver = mock.MagicMock()
        fake_manager = create_volume_manager.CreateVolumeFromSpecTask(fake_db, fake_driver)
        volume = fake_volume.fake_db_volume()
        orig_volume_db = mock.MagicMock(id=10, bootable=True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctxt)
        snapshot_get_by_id.return_value = snapshot_obj
        fake_db.volume_get.return_value = orig_volume_db

        fake_manager._create_from_snapshot(self.ctxt, volume, snapshot_obj.id)
        fake_driver.create_volume_from_snapshot.assert_called_once_with(volume, snapshot_obj)
        fake_db.volume_get.assert_called_once_with(self.ctxt, snapshot_obj.volume_id)
        handle_bootable.assert_called_once_with(self.ctxt, volume["id"], snapshot_id=snapshot_obj.id)
Esempio n. 5
0
    def test_create_from_snapshot_update_failure(self, snapshot_get_by_id):
        fake_db = mock.MagicMock()
        fake_driver = mock.MagicMock()
        fake_manager = create_volume_manager.CreateVolumeFromSpecTask(
            fake_db, fake_driver)
        volume = fake_volume.fake_db_volume()
        snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctxt)
        snapshot_get_by_id.return_value = snapshot_obj
        fake_db.volume_get.side_effect = exception.CinderException

        self.assertRaises(exception.MetadataUpdateFailure,
                          fake_manager._create_from_snapshot, self.ctxt,
                          volume, snapshot_obj.id)
        fake_driver.create_volume_from_snapshot.assert_called_once_with(
            volume, snapshot_obj)
Esempio n. 6
0
    def test_create_from_snapshot(self, snapshot_get_by_id, handle_bootable):
        fake_db = mock.MagicMock()
        fake_driver = mock.MagicMock()
        fake_manager = create_volume_manager.CreateVolumeFromSpecTask(
            fake_db, fake_driver)
        volume = fake_volume.fake_db_volume()
        orig_volume_db = mock.MagicMock(id=10, bootable=True)
        snapshot_obj = fake_snapshot.fake_snapshot_obj(self.ctxt)
        snapshot_get_by_id.return_value = snapshot_obj
        fake_db.volume_get.return_value = orig_volume_db

        fake_manager._create_from_snapshot(self.ctxt, volume, snapshot_obj.id)
        fake_driver.create_volume_from_snapshot.assert_called_once_with(
            volume, snapshot_obj)
        fake_db.volume_get.assert_called_once_with(self.ctxt,
                                                   snapshot_obj.volume_id)
        handle_bootable.assert_called_once_with(self.ctxt,
                                                volume['id'],
                                                snapshot_id=snapshot_obj.id)
Esempio n. 7
0
 def test_destroy(self, volume_destroy):
     db_volume = fake_volume.fake_db_volume()
     volume = objects.Volume._from_db_object(self.context,
                                             objects.Volume(), db_volume)
     volume.destroy()
     volume_destroy.assert_called_once_with(self.context, '1')
Esempio n. 8
0
 def test_create(self, volume_create):
     db_volume = fake_volume.fake_db_volume()
     volume_create.return_value = db_volume
     volume = objects.Volume(context=self.context)
     volume.create()
     self.assertEqual(db_volume['id'], volume.id)
Esempio n. 9
0
 def test_get_by_id(self, volume_get):
     db_volume = fake_volume.fake_db_volume()
     volume_get.return_value = db_volume
     volume = objects.Volume.get_by_id(self.context, 1)
     self._compare(self, db_volume, volume)