예제 #1
0
    def test_copy_volume_from_snapshot(self):
        (mox, drv) = self._mox, self._driver

        mox.StubOutWithMock(image_utils, 'convert_image')
        mox.StubOutWithMock(drv, '_read_info_file')
        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        mox.StubOutWithMock(drv, '_set_rw_permissions_for_all')

        dest_volume = self._simple_volume(
            'c1073000-0000-0000-0000-0000000c1073')
        src_volume = self._simple_volume()

        vol_dir = os.path.join(self.TEST_MNT_POINT_BASE,
                               drv._get_hash_str(self.TEST_QUOBYTE_VOLUME))
        src_vol_path = os.path.join(vol_dir, src_volume['name'])
        dest_vol_path = os.path.join(vol_dir, dest_volume['name'])
        info_path = os.path.join(vol_dir, src_volume['name']) + '.info'

        snapshot = {
            'volume_name': src_volume['name'],
            'name': 'clone-snap-%s' % src_volume['id'],
            'size': src_volume['size'],
            'volume_size': src_volume['size'],
            'volume_id': src_volume['id'],
            'id': 'tmp-snap-%s' % src_volume['id'],
            'volume': src_volume
        }

        snap_file = dest_volume['name'] + '.' + snapshot['id']
        snap_path = os.path.join(vol_dir, snap_file)

        size = dest_volume['size']

        drv._read_info_file(info_path).AndReturn({
            'active': snap_file,
            snapshot['id']: snap_file
        })

        qemu_img_output = """image: %s
        file format: raw
        virtual size: 1.0G (1073741824 bytes)
        disk size: 173K
        backing file: %s
        """ % (snap_file, src_volume['name'])
        img_info = imageutils.QemuImgInfo(qemu_img_output)

        image_utils.qemu_img_info(snap_path).AndReturn(img_info)

        image_utils.convert_image(src_vol_path,
                                  dest_vol_path,
                                  'raw',
                                  run_as_root=self.execute_as_root)

        drv._set_rw_permissions_for_all(dest_vol_path)

        mox.ReplayAll()

        drv._copy_volume_from_snapshot(snapshot, dest_volume, size)

        mox.VerifyAll()
예제 #2
0
    def test_initialize_connection(self):
        (mox, drv) = self._mox, self._driver

        volume = self._simple_volume()
        vol_dir = os.path.join(self.TEST_MNT_POINT_BASE,
                               drv._get_hash_str(self.TEST_QUOBYTE_VOLUME))
        vol_path = os.path.join(vol_dir, volume['name'])

        qemu_img_output = """image: %s
        file format: raw
        virtual size: 1.0G (1073741824 bytes)
        disk size: 173K
        """ % volume['name']
        img_info = imageutils.QemuImgInfo(qemu_img_output)

        mox.StubOutWithMock(drv, 'get_active_image_from_info')
        mox.StubOutWithMock(image_utils, 'qemu_img_info')

        drv.get_active_image_from_info(volume).AndReturn(volume['name'])
        image_utils.qemu_img_info(vol_path).AndReturn(img_info)

        mox.ReplayAll()

        conn_info = drv.initialize_connection(volume, None)

        mox.VerifyAll()

        self.assertEqual(conn_info['data']['format'], 'raw')
        self.assertEqual(conn_info['driver_volume_type'], 'quobyte')
        self.assertEqual(conn_info['data']['name'], volume['name'])
        self.assertEqual(conn_info['mount_point_base'],
                         self.TEST_MNT_POINT_BASE)
예제 #3
0
    def test_extend_volume(self):
        (mox, drv) = self._mox, self._driver

        volume = self._simple_volume()

        volume_path = '%s/%s/volume-%s' % (
            self.TEST_MNT_POINT_BASE,
            drv._get_hash_str(self.TEST_QUOBYTE_VOLUME), self.VOLUME_UUID)

        qemu_img_info_output = """image: volume-%s
        file format: qcow2
        virtual size: 1.0G (1073741824 bytes)
        disk size: 473K
        """ % self.VOLUME_UUID

        img_info = imageutils.QemuImgInfo(qemu_img_info_output)

        mox.StubOutWithMock(drv, '_execute')
        mox.StubOutWithMock(drv, 'get_active_image_from_info')
        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        mox.StubOutWithMock(image_utils, 'resize_image')

        drv.get_active_image_from_info(volume).AndReturn(volume['name'])

        image_utils.qemu_img_info(volume_path).AndReturn(img_info)

        image_utils.resize_image(volume_path, 3)

        mox.ReplayAll()

        drv.extend_volume(volume, 3)

        mox.VerifyAll()
예제 #4
0
    def test_copy_volume_from_snapshot(self, mock_qemu_img_info,
                                       mock_convert_image, mock_resize_image):

        new_volume = {'name': 'volume-3fa63b02-1fe5-11e5-b492-abf97a8fb23b',
                      'id': '3fa63b02-1fe5-11e5-b492-abf97a8fb23b',
                      'provider_location': 'fake_share'}
        new_vol_path = os.path.join(_FAKE_VOL_BASEDIR, new_volume['name'])

        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        info.backing_file = _FAKE_VOL_PATH
        mock_qemu_img_info.return_value = info

        with mock.patch.object(self.drv, '_read_info_file') as \
                mock_read_info_file, \
                mock.patch.object(self.drv, '_set_rw_permissions_for_all') as \
                mock_set_rw_permissions:
            self.drv._copy_volume_from_snapshot(_FAKE_SNAPSHOT,
                                                new_volume, 1)

        mock_read_info_file.assert_called_once_with("%s.info" % _FAKE_VOL_PATH)
        mock_convert_image.assert_called_once_with(_FAKE_VOL_PATH,
                                                   new_vol_path, 'raw',
                                                   run_as_root=True)
        mock_set_rw_permissions.assert_called_once_with(new_vol_path)
        mock_resize_image.assert_called_once_with(new_vol_path, 1)
예제 #5
0
    def test_create_from_image_cache_miss_error_downloading(
            self, mock_qemu_info, mock_get_internal_context,
            mock_create_from_img_dl, mock_create_from_src,
            mock_handle_bootable, mock_fetch_img):
        mock_fetch_img.return_value = mock.MagicMock()
        image_info = imageutils.QemuImgInfo()
        image_info.virtual_size = '2147483648'
        mock_qemu_info.return_value = image_info
        self.mock_driver.clone_image.return_value = (None, False)
        self.mock_cache.get_entry.return_value = None

        volume = fake_volume.fake_volume_obj(self.ctxt,
                                             size=10,
                                             host='foo@bar#pool')
        image_volume = fake_volume.fake_db_volume(size=2)
        self.mock_db.volume_create.return_value = image_volume

        mock_create_from_img_dl.side_effect = exception.CinderException()

        def update_volume(ctxt, id, updates):
            volume.update(updates)
            return volume

        self.mock_db.volume_update.side_effect = update_volume

        image_location = 'someImageLocationStr'
        image_id = 'c7a8b8d4-e519-46c7-a0df-ddf1b9b9fff2'
        image_meta = mock.MagicMock()

        manager = create_volume_manager.CreateVolumeFromSpecTask(
            self.mock_volume_manager,
            self.mock_db,
            self.mock_driver,
            image_volume_cache=self.mock_cache)

        self.assertRaises(exception.CinderException,
                          manager._create_from_image, self.ctxt, volume,
                          image_location, image_id, image_meta,
                          self.mock_image_service)

        # Make sure clone_image is always called
        self.assertTrue(self.mock_driver.clone_image.called)

        # The image download should happen if clone fails and
        # we get a cache miss
        mock_create_from_img_dl.assert_called_once_with(
            self.ctxt, mock.ANY, image_location, image_id,
            self.mock_image_service)

        # The volume size should be reduced to virtual_size and then put back,
        # especially if there is an exception while creating the volume.
        self.assertEqual(2, self.mock_db.volume_update.call_count)
        self.mock_db.volume_update.assert_any_call(self.ctxt, volume['id'],
                                                   {'size': 2})
        self.mock_db.volume_update.assert_any_call(self.ctxt, volume['id'],
                                                   {'size': 10})

        # Make sure we didn't try and create a cache entry
        self.assertFalse(self.mock_cache.ensure_space.called)
        self.assertFalse(self.mock_cache.create_cache_entry.called)
예제 #6
0
    def test_initialize_connection(self):
        drv = self._driver

        volume = self._simple_volume()
        vol_dir = os.path.join(self.TEST_MNT_POINT_BASE,
                               drv._get_hash_str(self.TEST_QUOBYTE_VOLUME))
        vol_path = os.path.join(vol_dir, volume['name'])

        qemu_img_output = """image: %s
        file format: raw
        virtual size: 1.0G (1073741824 bytes)
        disk size: 173K
        """ % volume['name']
        img_info = imageutils.QemuImgInfo(qemu_img_output)

        drv.get_active_image_from_info = mock.Mock(return_value=volume['name'])
        image_utils.qemu_img_info = mock.Mock(return_value=img_info)

        conn_info = drv.initialize_connection(volume, None)

        drv.get_active_image_from_info.assert_called_once_with(volume)
        image_utils.qemu_img_info.assert_called_once_with(vol_path)

        self.assertEqual('raw', conn_info['data']['format'])
        self.assertEqual('quobyte', conn_info['driver_volume_type'])
        self.assertEqual(volume['name'], conn_info['data']['name'])
        self.assertEqual(self.TEST_MNT_POINT_BASE,
                         conn_info['mount_point_base'])
예제 #7
0
    def test_extend_volume_with_invalid_format(self, mock_qemu_img_info):
        info = imageutils.QemuImgInfo()
        info.file_format = 'vmdk'
        mock_qemu_img_info.return_value = info

        self.assertRaises(exception.InvalidVolume,
                          self.drv.extend_volume, _FAKE_VOLUME, 2)
예제 #8
0
    def test_backup_volume(self):
        self.mox.StubOutWithMock(self._driver, 'db')
        self.mox.StubOutWithMock(self._driver.db, 'volume_get')

        volume = {'id': '2', 'name': self.TEST_VOLNAME}
        self._driver.db.volume_get(context, volume['id']).AndReturn(volume)

        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        self.mox.StubOutWithMock(image_utils, 'qemu_img_info')
        image_utils.qemu_img_info(self.TEST_VOLPATH).AndReturn(info)

        self.mox.StubOutWithMock(utils, 'temporary_chown')
        mock_tempchown = self.mox.CreateMockAnything()
        utils.temporary_chown(self.TEST_VOLPATH).AndReturn(mock_tempchown)
        mock_tempchown.__enter__()
        mock_tempchown.__exit__(None, None, None)

        self.mox.StubOutWithMock(fileutils, 'file_open')
        mock_fileopen = self.mox.CreateMockAnything()
        fileutils.file_open(self.TEST_VOLPATH).AndReturn(mock_fileopen)
        mock_fileopen.__enter__()
        mock_fileopen.__exit__(None, None, None)

        backup = {'volume_id': volume['id']}
        mock_servicebackup = self.mox.CreateMockAnything()
        mock_servicebackup.backup(backup, mox_lib.IgnoreArg())

        self.mox.ReplayAll()
        self._driver.backup_volume(context, backup, mock_servicebackup)
        self.mox.VerifyAll()
예제 #9
0
    def test_initialize_connection(self, mock_qemu_img_info):
        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        info.image = _FAKE_VOLUME['name']
        mock_qemu_img_info.return_value = info

        with mock.patch.object(self.drv, 'get_active_image_from_info') as \
                mock_get_active_image_from_info:

            mock_get_active_image_from_info.return_value = _FAKE_VOLUME['name']
            conn_info = self.drv.initialize_connection(_FAKE_VOLUME, None)

        expected_conn_info = {
            'driver_volume_type': driver.ScalityDriver.driver_volume_type,
            'mount_point_base': _FAKE_MNT_POINT,
            'data': {
                'export': _FAKE_VOLUME['provider_location'],
                'name': _FAKE_VOLUME['name'],
                'sofs_path': 'cinder/volumes/00/' + _FAKE_VOLUME['name'],
                'format': 'raw'
            }
        }
        self.assertEqual(expected_conn_info, conn_info)
        mock_get_active_image_from_info.assert_called_once_with(_FAKE_VOLUME)
        mock_qemu_img_info.assert_called_once_with(_FAKE_VOL_PATH)
예제 #10
0
def qemu_img_info(path):
    """Return an object containing the parsed output from qemu-img info."""
    cmd = ('env', 'LC_ALL=C', 'qemu-img', 'info', path)
    if os.name == 'nt':
        cmd = cmd[2:]
    out, err = utils.execute(*cmd, run_as_root=True)
    return imageutils.QemuImgInfo(out)
예제 #11
0
    def test_extend_volume(self):
        drv = self._driver

        volume = self._simple_volume()

        volume_path = '%s/%s/volume-%s' % (
            self.TEST_MNT_POINT_BASE,
            drv._get_hash_str(self.TEST_QUOBYTE_VOLUME), self.VOLUME_UUID)

        qemu_img_info_output = """image: volume-%s
        file format: qcow2
        virtual size: 1.0G (1073741824 bytes)
        disk size: 473K
        """ % self.VOLUME_UUID

        img_info = imageutils.QemuImgInfo(qemu_img_info_output)

        drv.get_active_image_from_info = mock.Mock(return_value=volume['name'])
        image_utils.qemu_img_info = mock.Mock(return_value=img_info)
        image_utils.resize_image = mock.Mock()

        drv.extend_volume(volume, 3)

        drv.get_active_image_from_info.assert_called_once_with(volume)
        image_utils.qemu_img_info.assert_called_once_with(volume_path)
        image_utils.resize_image.assert_called_once_with(volume_path, 3)
예제 #12
0
    def test_copy_volume_from_snapshot(self):
        drv = self._driver

        # lots of test vars to be prepared at first
        dest_volume = self._simple_volume(
            'c1073000-0000-0000-0000-0000000c1073')
        src_volume = self._simple_volume()

        vol_dir = os.path.join(self.TEST_MNT_POINT_BASE,
                               drv._get_hash_str(self.TEST_QUOBYTE_VOLUME))
        src_vol_path = os.path.join(vol_dir, src_volume['name'])
        dest_vol_path = os.path.join(vol_dir, dest_volume['name'])
        info_path = os.path.join(vol_dir, src_volume['name']) + '.info'

        snapshot = {
            'volume_name': src_volume['name'],
            'name': 'clone-snap-%s' % src_volume['id'],
            'size': src_volume['size'],
            'volume_size': src_volume['size'],
            'volume_id': src_volume['id'],
            'id': 'tmp-snap-%s' % src_volume['id'],
            'volume': src_volume
        }

        snap_file = dest_volume['name'] + '.' + snapshot['id']
        snap_path = os.path.join(vol_dir, snap_file)

        size = dest_volume['size']

        qemu_img_output = """image: %s
        file format: raw
        virtual size: 1.0G (1073741824 bytes)
        disk size: 173K
        backing file: %s
        """ % (snap_file, src_volume['name'])
        img_info = imageutils.QemuImgInfo(qemu_img_output)

        # mocking and testing starts here
        image_utils.convert_image = mock.Mock()
        drv._read_info_file = mock.Mock(return_value={
            'active': snap_file,
            snapshot['id']: snap_file
        })
        image_utils.qemu_img_info = mock.Mock(return_value=img_info)
        drv._set_rw_permissions_for_all = mock.Mock()

        drv._copy_volume_from_snapshot(snapshot, dest_volume, size)

        drv._read_info_file.assert_called_once_with(info_path)
        image_utils.qemu_img_info.assert_called_once_with(snap_path)
        (image_utils.convert_image.assert_called_once_with(
            src_vol_path,
            dest_vol_path,
            'raw',
            run_as_root=self._driver._execute_as_root))
        drv._set_rw_permissions_for_all.assert_called_once_with(dest_vol_path)
예제 #13
0
    def test_extend_volume(self, mock_qemu_img_info, mock_resize_image):
        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        mock_qemu_img_info.return_value = info

        self.drv.extend_volume(_FAKE_VOLUME, 2)

        mock_qemu_img_info.assert_called_once_with(_FAKE_VOL_PATH)

        mock_resize_image.assert_called_once_with(_FAKE_VOL_PATH, 2)
예제 #14
0
    def test_backup_volume_with_non_raw_volume(self, mock_qemu_img_info):

        info = imageutils.QemuImgInfo()
        info.file_format = 'qcow2'
        mock_qemu_img_info.return_value = info

        self.drv.db.volume_get.return_value = _FAKE_VOLUME

        self.assertRaises(exception.InvalidVolume, self.drv.backup_volume,
                          context, _FAKE_BACKUP, mock.MagicMock())

        mock_qemu_img_info.assert_called_once_with(_FAKE_VOL_PATH)
예제 #15
0
    def test_create_from_image_cache_miss(
            self, mock_qemu_info, mock_volume_get, mock_volume_update,
            mock_get_internal_context, mock_create_from_img_dl,
            mock_create_from_src, mock_handle_bootable, mock_fetch_img):
        mock_get_internal_context.return_value = self.ctxt
        mock_fetch_img.return_value = mock.MagicMock(
            spec=utils.get_file_spec())
        image_info = imageutils.QemuImgInfo()
        image_info.virtual_size = '2147483648'
        mock_qemu_info.return_value = image_info
        self.mock_driver.clone_image.return_value = (None, False)
        self.mock_cache.get_entry.return_value = None

        volume = fake_volume.fake_volume_obj(self.ctxt,
                                             size=10,
                                             host='foo@bar#pool')
        mock_volume_get.return_value = volume

        image_location = 'someImageLocationStr'
        image_id = 'c7a8b8d4-e519-46c7-a0df-ddf1b9b9fff2'
        image_meta = mock.MagicMock()

        manager = create_volume_manager.CreateVolumeFromSpecTask(
            self.mock_volume_manager,
            self.mock_db,
            self.mock_driver,
            image_volume_cache=self.mock_cache)

        manager._create_from_image(self.ctxt, volume, image_location, image_id,
                                   image_meta, self.mock_image_service)

        # Make sure clone_image is always called
        self.assertTrue(self.mock_driver.clone_image.called)

        # The image download should happen if clone fails and
        # we get a cache miss
        mock_create_from_img_dl.assert_called_once_with(
            self.ctxt, mock.ANY, image_location, image_id,
            self.mock_image_service)

        # The volume size should be reduced to virtual_size and then put back
        mock_volume_update.assert_any_call(self.ctxt, volume.id, {'size': 2})
        mock_volume_update.assert_any_call(self.ctxt, volume.id, {'size': 10})

        # Make sure created a new cache entry
        (self.mock_volume_manager._create_image_cache_volume_entry.
         assert_called_once_with(self.ctxt, volume, image_id, image_meta))

        mock_handle_bootable.assert_called_once_with(self.ctxt,
                                                     volume['id'],
                                                     image_id=image_id,
                                                     image_meta=image_meta)
예제 #16
0
    def test_backup_volume_with_backing_file(self, mock_qemu_img_info):

        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        info.backing_file = 'fake.img'
        mock_qemu_img_info.return_value = info

        backup = {'volume_id': _FAKE_VOLUME['id']}
        self.drv.db.volume_get.return_value = _FAKE_VOLUME

        self.assertRaises(exception.InvalidVolume, self.drv.backup_volume,
                          context, backup, mock.MagicMock())

        mock_qemu_img_info.assert_called_once_with(_FAKE_VOL_PATH)
예제 #17
0
    def test_copy_volume_to_image_snapshot_exists(self):
        """Upload an active snapshot which has to be converted to raw first."""
        drv = self._driver

        volume = self._simple_volume()
        volume_path = '%s/volume-%s' % (self.TEST_MNT_POINT, self.VOLUME_UUID)
        volume_filename = 'volume-%s' % self.VOLUME_UUID
        image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}

        with mock.patch.object(drv, 'get_active_image_from_info') as \
                mock_get_active_image_from_info, \
                mock.patch.object(drv, '_local_volume_dir') as \
                mock_local_volume_dir, \
                mock.patch.object(image_utils, 'qemu_img_info') as \
                mock_qemu_img_info, \
                mock.patch.object(image_utils, 'convert_image') as \
                mock_convert_image, \
                mock.patch.object(image_utils, 'upload_volume') as \
                mock_upload_volume, \
                mock.patch.object(image_utils, 'create_temporary_file') as \
                mock_create_temporary_file:
            mock_get_active_image_from_info.return_value = volume['name']

            mock_local_volume_dir.return_value = self.TEST_MNT_POINT

            mock_create_temporary_file.return_value = self.TEST_TMP_FILE

            qemu_img_output = """image: volume-%s.%s
            file format: qcow2
            virtual size: 1.0G (1073741824 bytes)
            disk size: 173K
            backing file: %s
            """ % (self.VOLUME_UUID, self.SNAP_UUID, volume_filename)
            img_info = imageutils.QemuImgInfo(qemu_img_output)
            mock_qemu_img_info.return_value = img_info

            upload_path = self.TEST_TMP_FILE

            drv.copy_volume_to_image(mock.ANY, volume, mock.ANY, image_meta)

            mock_get_active_image_from_info.assert_called_once_with(volume)
            mock_local_volume_dir.assert_called_with(volume)
            mock_qemu_img_info.assert_called_once_with(volume_path)
            mock_convert_image.assert_called_once_with(volume_path,
                                                       upload_path, 'raw')
            mock_upload_volume.assert_called_once_with(mock.ANY, mock.ANY,
                                                       mock.ANY, upload_path)
            self.assertTrue(mock_create_temporary_file.called)
예제 #18
0
    def test_resize_volume(self):
        new_vol_size = 15
        new_vol_size_bytes = new_vol_size * units.GiB
        volume = test_utils.create_volume(self.context, host=CONF.host)
        volpath = os.path.join(self.volumes_path, volume['name'])

        qemu_img_info_output = """image: %s
        file format: raw
        virtual size: %sG (%s bytes)
        backing file: %s
        """ % (volume['name'], new_vol_size, new_vol_size_bytes, volpath)
        img_info = imageutils.QemuImgInfo(qemu_img_info_output)

        with mock.patch('cinder.image.image_utils.resize_image'):
            with mock.patch('cinder.image.image_utils.qemu_img_info') as info:
                info.return_value = img_info
                rv = self.driver._resize_volume_file(volume, new_vol_size)
                self.assertEqual(rv, new_vol_size_bytes)
예제 #19
0
    def test_copy_volume_to_image_qcow2_image(self):
        """Upload a qcow2 image file which has to be converted to raw first."""
        drv = self._driver

        volume = self._simple_volume()
        volume_path = '%s/%s' % (self.TEST_MNT_POINT, volume['name'])
        image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}

        with contextlib.nested(
                mock.patch.object(drv, 'get_active_image_from_info'),
                mock.patch.object(drv, '_local_volume_dir'),
                mock.patch.object(image_utils, 'qemu_img_info'),
                mock.patch.object(image_utils, 'convert_image'),
                mock.patch.object(image_utils, 'upload_volume'),
                mock.patch.object(image_utils, 'create_temporary_file')) as (
                    mock_get_active_image_from_info, mock_local_volume_dir,
                    mock_qemu_img_info, mock_convert_image, mock_upload_volume,
                    mock_create_temporary_file):
            mock_get_active_image_from_info.return_value = volume['name']

            mock_local_volume_dir.return_value = self.TEST_MNT_POINT

            mock_create_temporary_file.return_value = self.TEST_TMP_FILE

            qemu_img_output = """image: %s
            file format: qcow2
            virtual size: 1.0G (1073741824 bytes)
            disk size: 173K
            """ % volume['name']
            img_info = imageutils.QemuImgInfo(qemu_img_output)
            mock_qemu_img_info.return_value = img_info

            upload_path = self.TEST_TMP_FILE

            drv.copy_volume_to_image(mock.ANY, volume, mock.ANY, image_meta)

            mock_get_active_image_from_info.assert_called_once_with(volume)
            mock_local_volume_dir.assert_called_with(volume)
            mock_qemu_img_info.assert_called_once_with(volume_path)
            mock_convert_image.assert_called_once_with(volume_path,
                                                       upload_path, 'raw')
            mock_upload_volume.assert_called_once_with(mock.ANY, mock.ANY,
                                                       mock.ANY, upload_path)
            mock_create_temporary_file.assert_once_called_with()
예제 #20
0
    def test_create_from_image_cache_miss_error_size_invalid(
            self, mock_qemu_info, mock_get_internal_context,
            mock_create_from_img_dl, mock_create_from_src,
            mock_handle_bootable, mock_fetch_img):
        mock_fetch_img.return_value = mock.MagicMock()
        image_info = imageutils.QemuImgInfo()
        image_info.virtual_size = '2147483648'
        mock_qemu_info.return_value = image_info
        self.mock_driver.clone_image.return_value = (None, False)
        self.mock_cache.get_entry.return_value = None

        volume = fake_volume.fake_volume_obj(self.ctxt, size=1,
                                             host='foo@bar#pool')
        image_volume = fake_volume.fake_db_volume(size=2)
        self.mock_db.volume_create.return_value = image_volume

        image_location = 'someImageLocationStr'
        image_id = 'c7a8b8d4-e519-46c7-a0df-ddf1b9b9fff2'
        image_meta = mock.MagicMock()

        manager = create_volume_manager.CreateVolumeFromSpecTask(
            self.mock_volume_manager,
            self.mock_db,
            self.mock_driver,
            image_volume_cache=self.mock_cache
        )

        self.assertRaises(
            exception.ImageUnacceptable,
            manager._create_from_image,
            self.ctxt,
            volume,
            image_location,
            image_id,
            image_meta,
            self.mock_image_service
        )

        # The volume size should NOT be changed when in this case
        self.assertFalse(self.mock_db.volume_update.called)

        # Make sure we didn't try and create a cache entry
        self.assertFalse(self.mock_cache.ensure_space.called)
        self.assertFalse(self.mock_cache.create_cache_entry.called)
예제 #21
0
    def test_backup_volume(self, mock_open, mock_temporary_chown,
                           mock_qemu_img_info):
        """Backup a volume with no snapshots."""

        info = imageutils.QemuImgInfo()
        info.file_format = 'raw'
        mock_qemu_img_info.return_value = info

        backup = {'volume_id': _FAKE_VOLUME['id']}
        mock_backup_service = mock.MagicMock()
        self.drv.db.volume_get.return_value = _FAKE_VOLUME

        self.drv.backup_volume(context, backup, mock_backup_service)

        mock_qemu_img_info.assert_called_once_with(_FAKE_VOL_PATH)
        mock_temporary_chown.assert_called_once_with(_FAKE_VOL_PATH)
        mock_open.assert_called_once_with(_FAKE_VOL_PATH)
        mock_backup_service.backup.assert_called_once_with(
            backup, mock_open().__enter__())
예제 #22
0
    def test_copy_volume_to_image_raw_image(self):
        drv = self._driver

        volume = self._simple_volume()
        volume_path = '%s/%s' % (self.TEST_MNT_POINT, volume['name'])
        image_meta = {'id': '10958016-e196-42e3-9e7f-5d8927ae3099'}

        with mock.patch.object(drv, 'get_active_image_from_info') as \
                mock_get_active_image_from_info, \
                mock.patch.object(drv, '_local_volume_dir') as \
                mock_local_volume_dir, \
                mock.patch.object(image_utils, 'qemu_img_info') as \
                mock_qemu_img_info, \
                mock.patch.object(image_utils, 'upload_volume') as \
                mock_upload_volume, \
                mock.patch.object(image_utils, 'create_temporary_file') as \
                mock_create_temporary_file:
            mock_get_active_image_from_info.return_value = volume['name']

            mock_local_volume_dir.return_value = self.TEST_MNT_POINT

            mock_create_temporary_file.return_value = self.TEST_TMP_FILE

            qemu_img_output = """image: %s
            file format: raw
            virtual size: 1.0G (1073741824 bytes)
            disk size: 173K
            """ % volume['name']
            img_info = imageutils.QemuImgInfo(qemu_img_output)
            mock_qemu_img_info.return_value = img_info

            upload_path = volume_path

            drv.copy_volume_to_image(mock.ANY, volume, mock.ANY, image_meta)

            mock_get_active_image_from_info.assert_called_once_with(volume)
            mock_local_volume_dir.assert_called_once_with(volume)
            mock_qemu_img_info.assert_called_once_with(volume_path)
            mock_upload_volume.assert_called_once_with(mock.ANY, mock.ANY,
                                                       mock.ANY, upload_path)
            self.assertTrue(mock_create_temporary_file.called)
예제 #23
0
    def test_extend_volume(self):
        new_vol_size = 15
        mox = mox_lib.Mox()
        volume = test_utils.create_volume(self.context, host=CONF.host)
        volpath = os.path.join(self.volumes_path, volume['name'])

        qemu_img_info_output = """image: %s
        file format: raw
        virtual size: %sG (%s bytes)
        backing file: %s
        """ % (volume['name'], new_vol_size, new_vol_size * units.GiB, volpath)
        mox.StubOutWithMock(image_utils, 'resize_image')
        image_utils.resize_image(volpath, new_vol_size)

        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        img_info = imageutils.QemuImgInfo(qemu_img_info_output)
        image_utils.qemu_img_info(volpath).AndReturn(img_info)
        mox.ReplayAll()

        self.driver.extend_volume(volume, new_vol_size)
        mox.VerifyAll()