[Libvirt-cim] [PATCH] [TEST] Adding create_diskpool() function

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed May 14 21:02:40 UTC 2008


Deepti B. Kalakeri wrote:
> # HG changeset patch
> # User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
> # Date 1210765549 25200
> # Node ID 6671b339cc8fd7c2cc7cada2ac15bc93635fbe4b
> # Parent  63c2d5e576bd750c0ba0975424a72ac24105c6f7
> [TEST] Adding create_diskpool() function.
> Modified vxml to get the poolname and networkname .
> To create the storage pool on machine with libvirt >= 0.4.1
> 
> Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
> 
> diff -r 63c2d5e576bd -r 6671b339cc8f suites/libvirt-cim/lib/XenKvmLib/common_util.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Wed May 14 04:36:40 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Wed May 14 04:45:49 2008 -0700
> @@ -1,3 +1,4 @@
> +#!/usr/bin/python
>  #
>  # Copyright 2008 IBM Corp.
>  #
> @@ -33,6 +34,8 @@ from CimTest.Globals import logger, log_
>  from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE
>  from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
>  from XenKvmLib.const import CIM_REV
> +from VirtLib.live import diskpool_list, virsh_version, net_list
> +from XenKvmLib.vxml import PoolXML, NetXML
> 
>  test_dpath = "foo"
>  diskpoolconf_rev = 558
> @@ -294,3 +297,53 @@ def create_diskpool_file():
>      
>      return conf_file()
> 
> +def create_diskpool(server, virt='KVM'):
> +    status = PASS
> +    try:
> +        dpool_list = diskpool_list(server, virt='KVM')
> +        if len(dpool_list) > 0:
> +            dpoolname=dpool_list[0]
> +        else:
> +            diskxml = PoolXML(server, virt=virt)
> +            ret = diskxml.create_vpool()
> +            if not ret:
> +                logger.error('Failed to create the disk pool "%s"',
> +                         dpoolname)
> +                status = FAIL
> +            dpoolname=diskxml.xml_get_diskpool_name()

You'll want to include this line in an else. If you are unable to get 
create the diskpool, then you'll be unable to get the name using 
xml_get_diskpool_name().

> +    except Exception, detail:
> +        logger.error("Exception: In fn create_diskpool(): %s", detail)
> +        status=FAIL
> +    return status, dpoolname

Before the try, you'll want to declare dpoolname = None or something 
similar. If you encounter an exception before dpoolname is assigned, 
then you'll hit a python error because you're referencing dpoolname 
before its assigned.
> +
> +def create_diskpool_conf(server, virt):
> +    libvirt_version = virsh_version(server, virt)
> +    if virt == 'KVM' and libvirt_version >= '0.4.1' and \
> +       CIM_REV > diskpoolconf_rev:

I missed during the last review - the diskpool isn't specific to KVM. 
KVM, Xen, and XenFV will use a diskpool if the version of libvirt is >= 
0.4.1.

> +        status, dpoolname = create_diskpool(server, virt=virt)
> +        diskid = "%s/%s" % ("DiskPool", dpoolname)
> +    else:
> +        status = create_diskpool_file()
> +        diskid = "%s/%s" % ("DiskPool", test_dpath)
> +
> +    return status, diskid
> +
> +
> +def create_netpool_conf(server, virt):
> +    status = PASS
> +    try:
> +        vir_network = net_list(server, virt)
> +        if len(vir_network) > 0:
> +            test_network = vir_network[0]
> +        else:
> +            netxml = NetXML(server, virt=virt)
> +            ret = netxml.create_vnet()
> +            if not ret:
> +                logger.error("Failed to create Virtual Network '%s'",
> +                              test_network)
> +                status = FAIL
> +            test_network = netxml.xml_get_netpool_name()
> +    except Exception, detail:
> +        logger.error("Exception: In fn create_netpool_conf(): %s", detail)
> +        status=FAIL
> +    return status, test_network

You'll want to define test_network before the try, otherwise 
test_network won't be defined if you encounter an exception.

-- 
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list