[libvirt] [libvirt-test-API][PATCH 3/3] Modify the case to cover two new APIs

hongming honzhang at redhat.com
Wed Apr 29 07:01:28 UTC 2015


ACK and Pushed

Thanks
Hongming

On 04/23/2015 03:37 PM, jiahu wrote:
> Check two new APIs in this case:
> storagePoolLookupByUUIDString/storagePoolLookupByUUID
> ---
>   repos/storage/pool_uuid.py | 49 +++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/repos/storage/pool_uuid.py b/repos/storage/pool_uuid.py
> index bb6bf63..2f371eb 100644
> --- a/repos/storage/pool_uuid.py
> +++ b/repos/storage/pool_uuid.py
> @@ -1,4 +1,8 @@
>   #!/usr/bin/env python
> +#To test "virsh pool-uuid" command and related APIs
> +#To test 2 APIs in this case:
> +#    storagePoolLookupByUUID
> +#    storagePoolLookupByUUIDString
>   
>   import os
>   import sys
> @@ -6,7 +10,10 @@ import re
>   import time
>   import commands
>   
> +import binascii
>   import libvirt
> +
> +from xml.dom import minidom
>   from libvirt import libvirtError
>   
>   from src import sharedmod
> @@ -15,6 +22,7 @@ required_params = ('poolname',)
>   optional_params = {}
>   
>   VIRSH_POOLUUID = "virsh pool-uuid"
> +POOLPATH = "/etc/libvirt/storage/"
>   
>   def check_pool_uuid(poolname, UUIDString, logger):
>       """ check UUID String of a pool """
> @@ -32,10 +40,25 @@ def check_pool_uuid(poolname, UUIDString, logger):
>           else:
>               return False
>   
> +def checking_uuid(logger,poolname,pooluuid):
> +    """check two uuid of pool which are from API and pool's XML"""
> +    global POOLPATH
> +    POOLPATH = POOLPATH + poolname + ".xml"
> +    xml = minidom.parse(POOLPATH)
> +    pool = xml.getElementsByTagName('pool')[0]
> +    uuid = pool.getElementsByTagName('uuid')[0].childNodes[0].data
> +    if uuid == pooluuid:
> +        return True
> +    else:
> +       return False
> +
>   def pool_uuid(params):
> -    """ call appropriate API to generate the UUIDStirng
> +    """ 1. call appropriate API to generate the UUIDStirng
>           of a pool , then compared to the output of command
>           virsh pool-uuid
> +        2. check 2 APIs in the case:
> +               storagePoolLookupByUUID
> +               storagePoolLookupByUUIDString
>       """
>       logger = params['logger']
>       poolname = params['poolname']
> @@ -53,6 +76,30 @@ def pool_uuid(params):
>       try:
>           UUIDString = poolobj.UUIDString()
>           logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString))
> +
> +        #For a transient pool, set another path
> +        if not poolobj.isPersistent() == 1:
> +            logger.info("Can not check a transient pool by now.")
> +            return 0
> +        #allowing '-' and ' ' anywhere between character pairs,just check
> +        #one of them
> +        UUIDString1 = UUIDString.replace("-"," ")
> +        pool1 = conn.storagePoolLookupByUUIDString(UUIDString1)
> +        pool_name1 = pool1.name()
> +        logger.debug("The given UUID is \"%s\", the pool is \"%s\" using\
> + storagePoolLookupByUUIDString" %(UUIDString1,pool_name1))
> +
> +        UUIDString2 = UUIDString.replace("-","")
> +        UUID_ascii = binascii.a2b_hex(UUIDString2)
> +        pool2 = conn.storagePoolLookupByUUID(UUID_ascii)
> +        pool_name2 = pool2.name()
> +        logger.debug("The given UUID is \"%s\", the pool is \"%s\" using \
> +storagePoolLookupByUUID" %(UUIDString2,pool_name2))
> +
> +        if pool_name1 == pool_name2 and checking_uuid(logger,pool_name1,UUIDString):
> +            logger.info("Successed to get pool name \"%s\" using \"%s\""\
> + %(pool_name1,UUIDString))
> +
>           if check_pool_uuid(poolname, UUIDString, logger):
>               logger.info(VIRSH_POOLUUID + " test succeeded.")
>               return 0




More information about the libvir-list mailing list