コード例 #1
0
def create_cow_image(backing_file, path, size=None):
    """Create COW image

    Creates a COW image with the given backing file

    :param backing_file: Existing image on which to base the COW image
    :param path: Desired location of the COW image
    """
    base_cmd = ['qemu-img', 'create', '-f', 'qcow2']
    cow_opts = []
    if backing_file:
        cow_opts += ['backing_file=%s' % backing_file]
        base_details = images.qemu_img_info(backing_file)
    else:
        base_details = None
    # Explicitly inherit the value of 'cluster_size' property of a qcow2
    # overlay image from its backing file. This can be useful in cases
    # when people create a base image with a non-default 'cluster_size'
    # value or cases when images were created with very old QEMU
    # versions which had a different default 'cluster_size'.
    if base_details and base_details.cluster_size is not None:
        cow_opts += ['cluster_size=%s' % base_details.cluster_size]
    if size is not None:
        cow_opts += ['size=%s' % size]
    if cow_opts:
        # Format as a comma separated list
        csv_opts = ",".join(cow_opts)
        cow_opts = ['-o', csv_opts]
    cmd = base_cmd + cow_opts + [path]
    execute(*cmd)
コード例 #2
0
ファイル: test_utils.py プロジェクト: bralike/zero
    def test_qemu_backing_file_actual(self,
                                      mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1     d9a9784a500742a7bb95627bb3aace38      0 2012-08-20 10:52:46 00:00:00.000
backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(1, len(image_info.snapshots))
        self.assertEqual('/b/3a988059e51a_2',
                         image_info.backing_file)
コード例 #3
0
ファイル: utils.py プロジェクト: pnavarro/nova
def create_cow_image(backing_file, path):
    """Create COW image

    Creates a COW image with the given backing file

    :param backing_file: Existing image on which to base the COW image
    :param path: Desired location of the COW image
    """
    base_cmd = ['qemu-img', 'create', '-f', 'qcow2']
    cow_opts = []
    if backing_file:
        cow_opts += ['backing_file=%s' % backing_file]
        base_details = images.qemu_img_info(backing_file)
    else:
        base_details = None
    # This doesn't seem to get inherited so force it to...
    # http://paste.ubuntu.com/1213295/
    # TODO(harlowja) probably file a bug against qemu-img/qemu
    if base_details and base_details.cluster_size is not None:
        cow_opts += ['cluster_size=%s' % base_details.cluster_size]
    # For now don't inherit this due the following discussion...
    # See: http://www.gossamer-threads.com/lists/openstack/dev/10592
    # if 'preallocation' in base_details:
    #     cow_opts += ['preallocation=%s' % base_details['preallocation']]
    if base_details and base_details.encryption:
        cow_opts += ['encryption=%s' % base_details.encryption]
    if cow_opts:
        # Format as a comma separated list
        csv_opts = ",".join(cow_opts)
        cow_opts = ['-o', csv_opts]
    cmd = base_cmd + cow_opts + [path]
    execute(*cmd)
コード例 #4
0
ファイル: test_image_utils.py プロジェクト: Acidburn0zzz/nova
    def test_qemu_backing_file_actual(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1     d9a9784a500742a7bb95627bb3aace38      0 2012-08-20 10:52:46 00:00:00.000
backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
"""
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(utils, 'execute')
        os.path.exists(path).AndReturn(True)
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(1, len(image_info.snapshots))
        self.assertEqual('/b/3a988059e51a_2',
                         image_info.backing_file)
コード例 #5
0
ファイル: api.py プロジェクト: mahak/nova
def get_disk_info(path):
    """Get QEMU info of a disk image

    :param path: Path to the disk image
    :returns: oslo_utils.imageutils.QemuImgInfo object for the image.
    """
    return images.qemu_img_info(path)
コード例 #6
0
ファイル: api.py プロジェクト: mahak/nova
def get_allocated_disk_size(path):
    """Get the allocated size of a disk image

    :param path: Path to the disk image
    :returns: Size (in bytes) of the given disk image as allocated on the
              filesystem
    """
    return images.qemu_img_info(path).disk_size
コード例 #7
0
ファイル: utils.py プロジェクト: fabian4/nova
def get_disk_type(path):
    """Retrieve disk type (raw, qcow2, lvm) for given file."""
    if path.startswith('/dev'):
        return 'lvm'
    elif path.startswith('rbd:'):
        return 'rbd'

    return images.qemu_img_info(path).file_format
コード例 #8
0
ファイル: utils.py プロジェクト: jettang/icehouse
def get_disk_type(path):
    """Retrieve disk type (raw, qcow2, lvm) for given file."""
    if path.startswith("/dev"):
        return "lvm"
    elif path.startswith("rbd:"):
        return "rbd"

    return images.qemu_img_info(path).file_format
コード例 #9
0
ファイル: api.py プロジェクト: runt18/nova
def get_disk_size(path):
    """Get the (virtual) size of a disk image

    :param path: Path to the disk image
    :returns: Size (in bytes) of the given disk image as it would be seen
              by a virtual machine.
    """
    return images.qemu_img_info(path).virtual_size
コード例 #10
0
ファイル: imagebackend.py プロジェクト: cyx1231st/nova
 def _get_driver_format(self):
     try:
         data = images.qemu_img_info(self.path)
         return data.file_format
     except exception.InvalidDiskInfo as e:
         LOG.info(
             _LI("Failed to get image info from path %(path)s; " "error: %(error)s"), {"path": self.path, "error": e}
         )
         return "raw"
コード例 #11
0
ファイル: imagebackend.py プロジェクト: klmitch/nova
 def _get_driver_format(self):
     try:
         data = images.qemu_img_info(self.path)
         return data.file_format
     except exception.InvalidDiskInfo as e:
         LOG.info('Failed to get image info from path %(path)s; '
                  'error: %(error)s',
                  {'path': self.path, 'error': e})
         return 'raw'
コード例 #12
0
ファイル: utils.py プロジェクト: bhuvan/nova
def get_disk_size(path):
    """Get the (virtual) size of a disk image

    :param path: Path to the disk image
    :returns: Size (in bytes) of the given disk image as it would be seen
              by a virtual machine.
    """
    size = images.qemu_img_info(path)['virtual size']
    size = size.split('(')[1].split()[0]
    return int(size)
コード例 #13
0
ファイル: sio_utils.py プロジェクト: cloudscaling/nova
    def import_image(self, source, dest):
        """Import glance image onto actual ScaleIO block device.

        :param source: Glance image source
        :param dest: Target ScaleIO block device
        :return: Nothing
        """
        info = images.qemu_img_info(source)
        images.convert_image(source, dest, info.file_format, 'raw',
                             run_as_root=True)
コード例 #14
0
ファイル: utils.py プロジェクト: yizhongyin/OpenstackLiberty
def get_disk_size(path, format=None):
    """Get the (virtual) size of a disk image

    :param path: Path to the disk image
    :param format: the on-disk format of path
    :returns: Size (in bytes) of the given disk image as it would be seen
              by a virtual machine.
    """
    size = images.qemu_img_info(path, format).virtual_size
    return int(size)
コード例 #15
0
def get_disk_backing_file(path, basename=True):
    """Get the backing file of a disk image

    :param path: Path to the disk image
    :returns: a path to the image's backing store
    """
    backing_file = images.qemu_img_info(path).backing_file
    if backing_file and basename:
        backing_file = os.path.basename(backing_file)

    return backing_file
コード例 #16
0
def get_disk_backing_file(path, basename=True):
    """Get the backing file of a disk image

    :param path: Path to the disk image
    :returns: a path to the image's backing store
    """
    backing_file = images.qemu_img_info(path).backing_file
    if backing_file and basename:
        backing_file = os.path.basename(backing_file)

    return backing_file
コード例 #17
0
ファイル: utils.py プロジェクト: apporc/nova
def get_disk_type(path):
    """Retrieve disk type (raw, qcow2, lvm, ploop) for given file."""
    if path.startswith('/dev'):
        return 'lvm'
    elif path.startswith('rbd:'):
        return 'rbd'
    elif (os.path.isdir(path) and
          os.path.exists(os.path.join(path, "DiskDescriptor.xml"))):
        return 'ploop'

    return images.qemu_img_info(path).file_format
コード例 #18
0
 def _get_driver_format(self):
     try:
         data = images.qemu_img_info(self.path)
         return data.file_format
     except exception.InvalidDiskInfo as e:
         LOG.info(
             _LI('Failed to get image info from path %(path)s; '
                 'error: %(error)s'), {
                     'path': self.path,
                     'error': e
                 })
         return 'raw'
コード例 #19
0
ファイル: utils.py プロジェクト: irfanullakhan/nova
def get_disk_backing_file(
    path: str, basename: bool = True, format: ty.Optional[str] = None,
) -> ty.Optional[str]:
    """Get the backing file of a disk image

    :param path: Path to the disk image
    :returns: a path to the image's backing store
    """
    backing_file = images.qemu_img_info(path, format).backing_file
    if backing_file and basename:
        backing_file = os.path.basename(backing_file)

    return backing_file
コード例 #20
0
    def import_image(self, source, dest):
        """Import glance image onto actual ScaleIO block device.

        :param source: Glance image source
        :param dest: Target ScaleIO block device
        :return: Nothing
        """
        info = images.qemu_img_info(source)
        images.convert_image(source,
                             dest,
                             info.file_format,
                             'raw',
                             run_as_root=True)
コード例 #21
0
ファイル: utils.py プロジェクト: bhuvan/nova
def get_disk_backing_file(path):
    """Get the backing file of a disk image

    :param path: Path to the disk image
    :returns: a path to the image's backing store
    """
    backing_file = images.qemu_img_info(path).get('backing file')

    if backing_file:
        if 'actual path: ' in backing_file:
            backing_file = backing_file.split('actual path: ')[1][:-1]
        backing_file = os.path.basename(backing_file)

    return backing_file
コード例 #22
0
def get_disk_backing_file(path):
    """Get the backing file of a disk image

    :param path: Path to the disk image
    :returns: a path to the image's backing store
    """
    backing_file = images.qemu_img_info(path).get('backing file')

    if backing_file:
        if 'actual path: ' in backing_file:
            backing_file = backing_file.split('actual path: ')[1][:-1]
        backing_file = os.path.basename(backing_file)

    return backing_file
コード例 #23
0
def get_disk_size(path, format=None):
    """Get the (virtual) size of a disk image

    :param path: Path to the disk image
    :param format: the on-disk format of path
    :returns: Size (in bytes) of the given disk image as it would be seen
              by a virtual machine.
    """
    # PF9 begin
    size = 0
    try:
        size = images.qemu_img_info(path, format).virtual_size
    except exception.InvalidDiskInfo as dinfo:
        LOG.error(_('Error reading disk size: %s') % dinfo)
    return int(size) if size else 0
コード例 #24
0
ファイル: imagebackend.py プロジェクト: mahak/nova
 def _remove_non_raw_cache_image(base):
     # NOTE(boxiang): If the cache image file exists, we will check
     # the format of it. Only raw format image is compatible for
     # RBD image backend. If format is not raw, we will remove it
     # at first. We limit force_raw_images to True this time. So
     # the format of new cache image must be raw.
     # We can remove this in 'U' version later.
     if not os.path.exists(base):
         return True
     image_format = images.qemu_img_info(base)
     if image_format.file_format != 'raw':
         try:
             os.remove(base)
         except OSError as e:
             LOG.warning("Ignoring failure to remove %(path)s: "
                         "%(error)s", {'path': base, 'error': e})
コード例 #25
0
 def _remove_non_raw_cache_image(base):
     # NOTE(boxiang): If the cache image file exists, we will check
     # the format of it. Only raw format image is compatible for
     # RBD image backend. If format is not raw, we will remove it
     # at first. We limit force_raw_images to True this time. So
     # the format of new cache image must be raw.
     # We can remove this in 'U' version later.
     if not os.path.exists(base):
         return True
     image_format = images.qemu_img_info(base)
     if image_format.file_format != 'raw':
         try:
             os.remove(base)
         except OSError as e:
             LOG.warning("Ignoring failure to remove %(path)s: "
                         "%(error)s", {'path': base, 'error': e})
コード例 #26
0
ファイル: test_utils.py プロジェクト: hanbaoying/nova
    def test_qemu_info_canon(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        mock_execute.return_value = (example_output, "")
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual("disk.config", image_info.image)
        self.assertEqual("raw", image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #27
0
ファイル: test_image_utils.py プロジェクト: EE-NovRain/nova
    def test_qemu_info_canon(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEquals('disk.config', image_info.image)
        self.assertEquals('raw', image_info.file_format)
        self.assertEquals(67108864, image_info.virtual_size)
        self.assertEquals(98304, image_info.disk_size)
        self.assertEquals(65536, image_info.cluster_size)
コード例 #28
0
    def test_qemu_info_canon(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #29
0
ファイル: test_utils.py プロジェクト: hanbaoying/nova
    def test_qemu_info_canon2(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        mock_execute.return_value = (example_output, "")
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual("disk.config", image_info.image)
        self.assertEqual("qcow2", image_info.file_format)
        self.assertEqual(67108844, image_info.virtual_size)
        self.assertEqual(963434, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
        self.assertEqual("/var/lib/nova/a328c7998805951a_2", image_info.backing_file)
コード例 #30
0
ファイル: test_image_utils.py プロジェクト: rmk40/nova
    def test_qemu_info(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        self.mox.StubOutWithMock(utils, "execute")
        utils.execute("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path).AndReturn((example_output, ""))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEquals("disk.config", image_info["image"])
        self.assertEquals("raw", image_info["file format"])
        self.assertEquals("64M (67108864 bytes)", image_info["virtual size"])
        self.assertEquals("96K", image_info["disk size"])
        self.assertEquals("bb", image_info["blah blah"])
        self.assertEquals("65536", image_info["cluster_size"])
コード例 #31
0
ファイル: test_utils.py プロジェクト: cloudscaling/nova
    def test_qemu_info_canon(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path,
                                             prlimit=images.QEMU_IMG_LIMITS)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #32
0
ファイル: test_image_utils.py プロジェクト: paulmathews/nova
    def test_qemu_info(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
                      path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEquals('disk.config', image_info['image'])
        self.assertEquals('raw', image_info['file format'])
        self.assertEquals('64M (67108864 bytes)', image_info['virtual size'])
        self.assertEquals('96K', image_info['disk size'])
        self.assertEquals('bb', image_info['blah blah'])
        self.assertEquals("65536", image_info['cluster_size'])
コード例 #33
0
ファイル: test_utils.py プロジェクト: VinceOnGit/nova
    def test_qemu_info_canon(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        self.mox.StubOutWithMock(os.path, "exists")
        self.mox.StubOutWithMock(utils, "execute")
        os.path.exists(path).AndReturn(True)
        utils.execute("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path).AndReturn((example_output, ""))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual("disk.config", image_info.image)
        self.assertEqual("raw", image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #34
0
ファイル: test_utils.py プロジェクト: VinceOnGit/nova
    def test_qemu_info_canon2(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        self.mox.StubOutWithMock(os.path, "exists")
        self.mox.StubOutWithMock(utils, "execute")
        os.path.exists(path).AndReturn(True)
        utils.execute("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path).AndReturn((example_output, ""))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual("disk.config", image_info.image)
        self.assertEqual("qcow2", image_info.file_format)
        self.assertEqual(67108844, image_info.virtual_size)
        self.assertEqual(963434, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
        self.assertEqual("/var/lib/nova/a328c7998805951a_2", image_info.backing_file)
コード例 #35
0
ファイル: test_utils.py プロジェクト: hanbaoying/nova
    def test_qemu_info_snaps(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
"""
        mock_execute.return_value = (example_output, "")
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with("env", "LC_ALL=C", "LANG=C", "qemu-img", "info", path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual("disk.config", image_info.image)
        self.assertEqual("raw", image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(3, len(image_info.snapshots))
コード例 #36
0
    def test_qemu_info_canon(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(utils, 'execute')
        os.path.exists(path).AndReturn(True)
        utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
                      path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #37
0
ファイル: test_image_utils.py プロジェクト: EE-NovRain/nova
    def test_qemu_info_canon2(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('env', 'LC_ALL=C', 'LANG=C',
                      'qemu-img', 'info', path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEquals('disk.config', image_info.image)
        self.assertEquals('qcow2', image_info.file_format)
        self.assertEquals(67108844, image_info.virtual_size)
        self.assertEquals(963434, image_info.disk_size)
        self.assertEquals(65536, image_info.cluster_size)
        self.assertEquals('/var/lib/nova/a328c7998805951a_2',
                          image_info.backing_file)
コード例 #38
0
    def test_qemu_info_canon2(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('qcow2', image_info.file_format)
        self.assertEqual(67108844, image_info.virtual_size)
        self.assertEqual(963434, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
        self.assertEqual('/var/lib/nova/a328c7998805951a_2',
                         image_info.backing_file)
コード例 #39
0
ファイル: test_utils.py プロジェクト: yuanchunzhang/nova
    def test_qemu_info_canon_qemu_2_10(self, mock_execute, mock_exists):
        images.QEMU_VERSION = nova.privsep.qemu.QEMU_VERSION_REQ_SHARED
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
blah BLAH: bb
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
            '--force-share', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #40
0
ファイル: test_utils.py プロジェクト: yuanchunzhang/nova
    def test_qemu_img_info_json(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """{
    "virtual-size": 67108864,
    "filename": "disk.config",
    "cluster-size": 65536,
    "format": "raw",
    "actual-size": 98304
}
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path, output_format='json')
        mock_execute.assert_called_once_with(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path,
            '--output=json', prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
コード例 #41
0
ファイル: test_utils.py プロジェクト: cloudscaling/nova
    def test_qemu_info_canon2(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path,
                                             prlimit=images.QEMU_IMG_LIMITS)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('qcow2', image_info.file_format)
        self.assertEqual(67108844, image_info.virtual_size)
        self.assertEqual(963434, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
        self.assertEqual('/var/lib/nova/a328c7998805951a_2',
                         image_info.backing_file)
コード例 #42
0
ファイル: test_utils.py プロジェクト: cloudscaling/nova
    def test_qemu_info_ploop(self, mock_execute, mock_isdir, mock_exists):
        path = "/var/lib/nova"
        example_output = """image: root.hds
file format: parallels
virtual size: 3.0G (3221225472 bytes)
disk size: 706M
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info',
                                             os.path.join(path, 'root.hds'),
                                             prlimit=images.QEMU_IMG_LIMITS)
        mock_isdir.assert_called_once_with(path)
        self.assertEqual(2, mock_exists.call_count)
        self.assertEqual(path, mock_exists.call_args_list[0][0][0])
        self.assertEqual(os.path.join(path, 'DiskDescriptor.xml'),
                             mock_exists.call_args_list[1][0][0])
        self.assertEqual('root.hds', image_info.image)
        self.assertEqual('parallels', image_info.file_format)
        self.assertEqual(3221225472, image_info.virtual_size)
        self.assertEqual(740294656, image_info.disk_size)
コード例 #43
0
ファイル: test_utils.py プロジェクト: yuanchunzhang/nova
    def test_qemu_info_ploop(self, mock_execute, mock_isdir, mock_exists):
        path = "/var/lib/nova"
        example_output = """image: root.hds
file format: parallels
virtual size: 3.0G (3221225472 bytes)
disk size: 706M
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
            os.path.join(path, 'root.hds'),
            prlimit=nova.privsep.qemu.QEMU_IMG_LIMITS)
        mock_isdir.assert_called_once_with(path)
        self.assertEqual(2, mock_exists.call_count)
        self.assertEqual(path, mock_exists.call_args_list[0][0][0])
        self.assertEqual(os.path.join(path, 'DiskDescriptor.xml'),
                             mock_exists.call_args_list[1][0][0])
        self.assertEqual('root.hds', image_info.image)
        self.assertEqual('parallels', image_info.file_format)
        self.assertEqual(3221225472, image_info.virtual_size)
        self.assertEqual(740294656, image_info.disk_size)
コード例 #44
0
    def test_qemu_info_snaps(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(3, len(image_info.snapshots))
コード例 #45
0
ファイル: test_utils.py プロジェクト: bralike/zero
    def test_qemu_info_convert(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
junk stuff: bbb
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
コード例 #46
0
    def test_qemu_backing_file_actual(self, mock_execute, mock_exists):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
cluster_size: 65536
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1     d9a9784a500742a7bb95627bb3aace38      0 2012-08-20 10:52:46 00:00:00.000
backing file: /var/lib/nova/a328c7998805951a_2 (actual path: /b/3a988059e51a_2)
"""
        mock_execute.return_value = (example_output, '')
        image_info = images.qemu_img_info(path)
        mock_execute.assert_called_once_with('env', 'LC_ALL=C', 'LANG=C',
                                             'qemu-img', 'info', path)
        mock_exists.assert_called_once_with(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(1, len(image_info.snapshots))
        self.assertEqual('/b/3a988059e51a_2', image_info.backing_file)
コード例 #47
0
    def test_qemu_info_canon2(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: QCOW2
virtual size: 67108844
cluster_size: 65536
disk size: 963434
backing file: /var/lib/nova/a328c7998805951a_2
"""
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(utils, 'execute')
        os.path.exists(path).AndReturn(True)
        utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
                      path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('qcow2', image_info.file_format)
        self.assertEqual(67108844, image_info.virtual_size)
        self.assertEqual(963434, image_info.disk_size)
        self.assertEqual(65536, image_info.cluster_size)
        self.assertEqual('/var/lib/nova/a328c7998805951a_2',
                         image_info.backing_file)
コード例 #48
0
    def test_qemu_info_snaps(self):
        path = "disk.config"
        example_output = """image: disk.config
file format: raw
virtual size: 64M (67108864 bytes)
disk size: 96K
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
3        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
4        d9a9784a500742a7bb95627bb3aace38    0 2012-08-20 10:52:46 00:00:00.000
"""
        self.mox.StubOutWithMock(os.path, 'exists')
        self.mox.StubOutWithMock(utils, 'execute')
        os.path.exists(path).AndReturn(True)
        utils.execute('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
                      path).AndReturn((example_output, ''))
        self.mox.ReplayAll()
        image_info = images.qemu_img_info(path)
        self.assertEqual('disk.config', image_info.image)
        self.assertEqual('raw', image_info.file_format)
        self.assertEqual(67108864, image_info.virtual_size)
        self.assertEqual(98304, image_info.disk_size)
        self.assertEqual(3, len(image_info.snapshots))
コード例 #49
0
ファイル: test_images.py プロジェクト: ykwon8651/project-e
 def test_qemu_info_with_bad_path(self):
     image_info = images.qemu_img_info("/path/that/does/not/exist")
     self.assertTrue(image_info)
     self.assertTrue(str(image_info))
コード例 #50
0
 def test_qemu_info_with_no_errors(self, path_exists, utils_execute):
     image_info = images.qemu_img_info('/fake/path')
     self.assertTrue(image_info)
     self.assertTrue(str(image_info))
コード例 #51
0
 def test_qemu_info_with_rbd_path(self, utils_execute):
     # Assert that the use of a RBD URI as the path doesn't raise
     # exception.DiskNotFound
     image_info = images.qemu_img_info('rbd:volume/pool')
     self.assertTrue(image_info)
     self.assertTrue(str(image_info))
コード例 #52
0
 def correct_format(self):
     if os.path.exists(self.path):
         data = images.qemu_img_info(self.path)
         self.driver_format = data.file_format or 'raw'
コード例 #53
0
 def _get_driver_format(self):
     data = images.qemu_img_info(self.path)
     return data.file_format or 'raw'
コード例 #54
0
def get_disk_type(path):
    """Retrieve disk type (raw, qcow2, lvm) for given file."""
    if path.startswith('/dev'):
        return 'lvm'

    return images.qemu_img_info(path).file_format