commit 4781df175c61917dc3db56c97e3f173eaf840d19
Author: Cole Robinson <crobinso@redhat.com>
Date: Wed Nov 17 15:36:51 2010 -0500
VirtualDisk: Fix detecting format of existing block devices (bz 647241)
diff --git a/tests/testdriver.xml b/tests/testdriver.xml
index 458ada7..83ef22a 100644
--- a/tests/testdriver.xml
+++ b/tests/testdriver.xml
@@ -304,6 +304,41 @@
</volume>
</pool>
+<pool type='iscsi'>
+ <name>iscsi-pool</name>
+ <uuid>abcdead9-388a-cdfe-461a-b8907f6e5aaa</uuid>
+ <capacity>107374182400</capacity>
+ <allocation>0</allocation>
+ <available>107374182400</available>
+ <source>
+ <host name="iscsi.example.com"/>
+ <device path="demo-target"/>
+ <auth type='chap' login='foobar' passwd='frobbar'/>
+ </source>
+ <target>
+ <path>/iscsi-pool</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>10736</owner>
+ <group>10736</group>
+ </permissions>
+ </target>
+
+ <volume>
+ <name>diskvol1</name>
+ <capacity>1000000</capacity>
+ <allocation>50000</allocation>
+ <target>
+ <format type='unknown'/>
+ <permissions>
+ <mode>0700</mode>
+ <owner>10736</owner>
+ <group>10736</group>
+ </permissions>
+ </target>
+ </volume>
+</pool>
+
<pool type='dir'>
<name>full-pool</name>
<uuid>35bb2ad9-388a-cdfe-461a-b8907f6e5555</uuid>
diff --git a/tests/xmlconfig-xml/misc-qemu-driver-type.xml b/tests/xmlconfig-xml/misc-qemu-driver-type.xml
index 14ca346..e1c8ba7 100644
--- a/tests/xmlconfig-xml/misc-qemu-driver-type.xml
+++ b/tests/xmlconfig-xml/misc-qemu-driver-type.xml
@@ -23,6 +23,11 @@
<source file='/tmp/test.img'/>
<target dev='hda' bus='ide'/>
</disk>
+ <disk type='block' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source dev='/iscsi-pool/diskvol1'/>
+ <target dev='hdb' bus='ide'/>
+ </disk>
<disk type='block' device='cdrom'>
<driver name='qemu'/>
<source dev='/dev/loop0'/>
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
index 076dfc3..33e0347 100644
--- a/tests/xmlconfig.py
+++ b/tests/xmlconfig.py
@@ -108,8 +108,8 @@ def get_filedisk(path = None):
path = "/tmp/test.img"
return VirtualDisk(path, size=.0001, conn=conn)
-def get_blkdisk():
- return VirtualDisk("/dev/loop0", conn=conn)
+def get_blkdisk(path="/dev/loop0"):
+ return VirtualDisk(path, conn=conn)
def get_virtual_network():
dev = virtinst.VirtualNetworkInterface()
@@ -522,6 +522,7 @@ class TestXMLConfig(unittest.TestCase):
g = get_basic_fullyvirt_guest()
g.disks.append(get_filedisk())
+ g.disks.append(get_blkdisk("/iscsi-pool/diskvol1"))
fargs = (g, "misc-qemu-driver-type", True)
self.conn_function_wrappers(g, fargs, conn_uri=qemu_uri)
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
index 4f9857f..e11e03e 100644
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -58,14 +58,17 @@ def _vdisk_clone(path, clone):
except OSError:
return False
-def _qemu_sanitize_drvtype(phystype, fmt):
+def _qemu_sanitize_drvtype(phystype, fmt, manual_format=False):
"""
Sanitize libvirt storage volume format to a valid qemu driver type
"""
raw_list = [ "iso" ]
- if phystype == VirtualDisk.TYPE_BLOCK and not fmt:
- return VirtualDisk.DRIVER_QEMU_RAW
+ if phystype == VirtualDisk.TYPE_BLOCK:
+ if not fmt:
+ return VirtualDisk.DRIVER_QEMU_RAW
+ if fmt and not manual_format:
+ return VirtualDisk.DRIVER_QEMU_RAW
if fmt in raw_list:
return VirtualDisk.DRIVER_QEMU_RAW
@@ -956,7 +959,8 @@ class VirtualDisk(VirtualDevice):
if self.format:
if drvname == self.DRIVER_QEMU:
- drvtype = _qemu_sanitize_drvtype(self.type, self.format)
+ drvtype = _qemu_sanitize_drvtype(self.type, self.format,
+ manual_format=True)
elif self.vol_object:
fmt = _util.get_xml_path(self.vol_object.XMLDesc(0),