[Kimchi-devel] [PATCH v2] storage volume: fix xml parsing of logical volume format type

Sheldon shaohef at linux.vnet.ibm.com
Thu Mar 6 13:26:36 UTC 2014


this patch can fix the issue 195
https://github.com/kimchi-project/kimchi/issues/195

On 03/06/2014 02:05 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 'raw' for the format attribute if there is no available format
> information in the XML.
>
> v2
> Return 'raw' instead of return empty string, because the only supported
> volume format of a logical pool is 'raw'.
>
> Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/storagevolumes.py | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
> index 442ff89..6811e15 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -113,7 +113,14 @@ 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. When there is no format information, we assume
> +            # it's 'raw'.
> +            fmt = 'raw'
>           res = dict(type=VOLUME_TYPE_MAP[info[0]],
>                      capacity=info[1],
>                      allocation=info[2],


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list