[Kimchi-devel] [PATCH] storage volume: fix xml parsing of logical volume format type
Zhou Zheng Sheng
zhshzhou at linux.vnet.ibm.com
Thu Mar 6 05:55:17 UTC 2014
on 2014/03/06 13:38, Mark Wu wrote:
> On 03/06/2014 12:53 PM, zhshzhou at linux.vnet.ibm.com wrote:
>> From: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
>>
>> Not all types of libvirt storage volume provide format information.
>> Particularly, the volume in logical pool doesn't have format information
>> in the dumped XML description. StorageVolumeModel.lookup assumes there
>> is a format tag, but for logical pool volumes it does not exist. So an
>> exception is raised when it lookup a logical volume.
>>
>> To trigger this problem, firstly create a guest using a logical pool.
>> Then
>> click the logical pool from the "storage" tab, and it would fail to list
>> the volumes.
>>
>> This patch catches the exception when parsing the format tag, and
>> returns an empty string for the format attribute if there is no available
>> format information in the XML.
>>
>> Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
>> ---
>> src/kimchi/model/storagevolumes.py | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/kimchi/model/storagevolumes.py
>> b/src/kimchi/model/storagevolumes.py
>> index 442ff89..6d0e884 100644
>> --- a/src/kimchi/model/storagevolumes.py
>> +++ b/src/kimchi/model/storagevolumes.py
>> @@ -113,7 +113,13 @@ class StorageVolumeModel(object):
>> path = vol.path()
>> info = vol.info()
>> xml = vol.XMLDesc(0)
>> - fmt = xmlutils.xpath_get_text(xml,
>> "/volume/target/format/@type")[0]
>> + try:
>> + fmt = xmlutils.xpath_get_text(
>> + xml, "/volume/target/format/@type")[0]
>> + except IndexError:
>> + # Not all types of libvirt storage can provide volume format
>> + # infomation.
>> + fmt = ''
> I think we should return 'raw' instead of an empty string here. I assume
> the reason why libvirt doesn't provide volume format for the volumes in
> logical pool is the volumes in logical pool could not be in any other
> formats except 'raw' without external tool intervene.
I agree. Though the documentation says "logical volume pool does not use
the volume format type element", it's actually "raw". I'm sending a
second version.
>> res = dict(type=VOLUME_TYPE_MAP[info[0]],
>> capacity=info[1],
>> allocation=info[2],
>
--
Thanks and best regards!
Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou at linux.vnet.ibm.com
Telephone: 86-10-82454397
More information about the Kimchi-devel
mailing list