Esempio n. 1
0
 def test_qcow2_compat_invalid(self):
     with self.assertRaises(ValueError):
         qemuimg.convert('image',
                         'dst',
                         dstFormat='qcow2',
                         backing='bak',
                         backingFormat='qcow2',
                         dstQcow2Compat='1.11')
Esempio n. 2
0
    def test_no_format(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-t', 'none', 'src', 'dst']
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with MonkeyPatchScope([(utils, 'watchCmd', convert)]):
            qemuimg.convert('src', 'dst', True)
Esempio n. 3
0
    def test_no_format(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', '-T', 'none',
                        'src', 'dst']
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst')
Esempio n. 4
0
    def test_no_format(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-t', 'none', 'src', 'dst']
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with FakeCmd(utils, 'watchCmd', convert):
            qemuimg.convert('src', 'dst', True)
Esempio n. 5
0
    def test_no_format(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', '-T', 'none',
                        'src', 'dst']
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst')
Esempio n. 6
0
    def test_qcow2_no_backing_file(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', '-T', 'none',
                        'src', '-O', 'qcow2', '-o', 'compat=0.10', 'dst']
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, 'config', CONFIG),
                               (qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst', dstFormat='qcow2')
Esempio n. 7
0
    def test_qcow2_no_backing_file(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', '-T', 'none',
                        'src', '-O', 'qcow2', '-o', 'compat=0.10', 'dst']
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, 'config', CONFIG),
                               (qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst', dstFormat='qcow2')
Esempio n. 8
0
    def test_qcow2_no_backing_file(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-t', 'none', 'src', '-O',
                        'qcow2', '-o', 'compat=0.10', 'dst']
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with FakeCmd(utils, 'execCmd', self.qcow2_compat_supported):
            with FakeCmd(utils, 'watchCmd', convert):
                qemuimg.convert('src', 'dst', None, dstFormat='qcow2')
Esempio n. 9
0
    def test_qcow2_compat_unsupported(self):
        def convert(cmd, **kw):
            expected = [
                QEMU_IMG, 'convert', '-t', 'none', 'src', '-O', 'qcow2', 'dst'
            ]
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
                                self.supported('convert', False)),
                               (utils, 'watchCmd', convert)]):
            qemuimg.convert('src', 'dst', True, dstFormat='qcow2')
Esempio n. 10
0
    def test_qcow2_no_backing_file(self):
        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-p', '-t', 'none', 'src',
                        '-O', 'qcow2', '-o', 'compat=0.10', 'dst']
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
                                self.supported('convert', True)),
                               (qemuimg, '_supports_src_cache',
                                self.supported('convert', False)),
                               (qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst', dstFormat='qcow2')
Esempio n. 11
0
    def test_qcow2_compat_unsupported(self):
        def qcow2_compat_unsupported(cmd, **kw):
            self.check_supports_qcow2_compat(cmd, **kw)
            return 0, 'Supported options:\nsize ...\n', ''

        def convert(cmd, **kw):
            expected = [QEMU_IMG, 'convert', '-t', 'none', 'src', '-O',
                        'qcow2', 'dst']
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with FakeCmd(utils, 'execCmd', qcow2_compat_unsupported):
            with FakeCmd(utils, 'watchCmd', convert):
                qemuimg.convert('src', 'dst', True, dstFormat='qcow2')
Esempio n. 12
0
    def test_qcow2_backing_file(self):
        def convert(cmd, **kw):
            expected = [
                QEMU_IMG, 'convert', '-p', '-t', 'none', 'src', '-O', 'qcow2',
                '-o', 'compat=0.10,backing_file=bak', 'dst'
            ]
            self.assertEqual(cmd, expected)

        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
                                self.supported('convert', True)),
                               (qemuimg, '_supports_src_cache',
                                self.supported('convert', False)),
                               (qemuimg, 'QemuImgOperation', convert)]):
            qemuimg.convert('src', 'dst', dstFormat='qcow2', backing='bak')
Esempio n. 13
0
    def _run(self):
        with guarded.context(self._source.locks + self._dest.locks):
            with self._source.prepare(), self._dest.prepare():
                # Do not start copying if we have already been aborted
                if self._status == jobs.STATUS.ABORTED:
                    return

                # Workaround for volumes containing VM configuration info that
                # were created with invalid vdsm metadata.
                if self._source.is_invalid_vm_conf_disk():
                    src_format = dst_format = qemuimg.FORMAT.RAW
                else:
                    src_format = self._source.qemu_format
                    dst_format = self._dest.qemu_format

                with self._dest.volume_operation():
                    self._operation = qemuimg.convert(
                        self._source.path,
                        self._dest.path,
                        srcFormat=src_format,
                        dstFormat=dst_format,
                        dstQcow2Compat=self._dest.qcow2_compat,
                        backing=self._dest.backing_path,
                        backingFormat=self._dest.backing_qemu_format)
                    with utils.closing(self._operation):
                        self._operation.wait_for_completion()
Esempio n. 14
0
    def _run(self):
        with guarded.context(self._source.locks + self._dest.locks):
            with self._source.prepare(), self._dest.prepare():
                # Do not start copying if we have already been aborted
                if self._status == jobs.STATUS.ABORTED:
                    return

                # Workaround for volumes containing VM configuration info that
                # were created with invalid vdsm metadata.
                if self._source.is_invalid_vm_conf_disk():
                    src_format = dst_format = qemuimg.FORMAT.RAW
                else:
                    src_format = self._source.qemu_format
                    dst_format = self._dest.qemu_format

                with self._dest.volume_operation():
                    self._operation = qemuimg.convert(
                        self._source.path,
                        self._dest.path,
                        srcFormat=src_format,
                        dstFormat=dst_format,
                        dstQcow2Compat=self._dest.qcow2_compat,
                        backing=self._dest.backing_path,
                        backingFormat=self._dest.backing_qemu_format)
                    with utils.closing(self._operation):
                        self._operation.wait_for_completion()
Esempio n. 15
0
def converted_size(filename, compat):
    converted = filename + ".qcow2"
    operation = qemuimg.convert(filename,
                                converted,
                                srcFormat=qemuimg.FORMAT.RAW,
                                dstFormat=qemuimg.FORMAT.QCOW2,
                                dstQcow2Compat=compat)
    with utils.closing(operation):
        operation.wait_for_completion()
    return os.stat(converted).st_size
Esempio n. 16
0
    def test_qcow2_backing_file_and_format(self):
        def convert(cmd, **kw):
            expected = [
                QEMU_IMG, 'convert', '-t', 'none', 'src', '-O', 'qcow2', '-o',
                'compat=0.10,backing_file=bak,'
                'backing_fmt=qcow2', 'dst'
            ]
            self.assertEqual(cmd, expected)
            return 0, '', ''

        with MonkeyPatchScope([(qemuimg, '_supports_qcow2_compat',
                                self.supported('convert', True)),
                               (utils, 'watchCmd', convert)]):
            qemuimg.convert('src',
                            'dst',
                            None,
                            dstFormat='qcow2',
                            backing='bak',
                            backingFormat='qcow2')
Esempio n. 17
0
def converted_size(filename, compat):
    converted = filename + ".qcow2"
    operation = qemuimg.convert(filename,
                                converted,
                                srcFormat=qemuimg.FORMAT.RAW,
                                dstFormat=qemuimg.FORMAT.QCOW2,
                                dstQcow2Compat=compat)
    with utils.closing(operation):
        operation.wait_for_completion()
    return os.stat(converted).st_size
Esempio n. 18
0
    def _run(self):
        # TODO: LOCKING!
        with self._source.prepare(), self._dest.prepare(writable=True):
            # Do not start copying if we have already been aborted
            if self._status == jobs.STATUS.ABORTED:
                return

            self._operation = qemuimg.convert(
                self._source.path,
                self._dest.path,
                srcFormat=self._source.qemu_format,
                dstFormat=self._dest.qemu_format,
                backing=self._dest.backing_path,
                backingFormat=self._dest.backing_qemu_format)
            self._operation.wait_for_completion()
Esempio n. 19
0
 def test_qcow2_compat_invalid(self):
     with self.assertRaises(ValueError):
         qemuimg.convert('image', 'dst', dstFormat='qcow2',
                         backing='bak', backingFormat='qcow2',
                         dstQcow2Compat='1.11')