[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 06:07:50 UTC 2014


on 2014/03/06 13:08, Sheldon wrote:
> Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> 

Thanks very much Sheldon. I just sent a second version, to return "raw"
instead of return empty string.

> 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 = ''
>>           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