[libvirt] [libvirt-test-API][PATCH 0/3] Modify the existing cases to cover 4 new APIs

Modify the existing cases to cover below 4 new APIs: networkLookupByUUIDString/networkLookupByUUID storagePoolLookupByUUIDString/storagePoolLookupByUUID jiahu (3): Add two testing cases to test_connection.conf Modify the case to cover two new APIs Modify the case to cover two new APIs cases/test_connection.conf | 8 +++++ repos/network/network_uuid.py | 68 ++++++++++++++++++++++++++++++++++++------- repos/storage/pool_uuid.py | 49 ++++++++++++++++++++++++++++++- 3 files changed, 114 insertions(+), 11 deletions(-) -- 1.8.3.1

Below 4 new APIs will be tested networkLookupByUUIDString/networkLookupByUUID storagePoolLookupByUUIDString/storagePoolLookupByUUID --- cases/test_connection.conf | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cases/test_connection.conf b/cases/test_connection.conf index 5719937..5317d72 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -57,3 +57,11 @@ virconn:connection_getDomainCapabilities pc-i440fx-rhel7.0.0 virttype kvm + +network:network_uuid + networkname + default + +storage:pool_uuid + poolname + default -- 1.8.3.1

Test below 2 APIs in this case: networkLookupByUUIDString/networkLookupByUUID --- repos/network/network_uuid.py | 68 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/repos/network/network_uuid.py b/repos/network/network_uuid.py index 02a104c..8f2ca83 100644 --- a/repos/network/network_uuid.py +++ b/repos/network/network_uuid.py @@ -1,13 +1,18 @@ #!/usr/bin/env python -# To test "virsh net-uuid" command +#To test "virsh net-uuid" command and related APIs +#To test 2 APIs in this case: +# networkLookupByUUIDString +# networkLookupByUUID import os import sys import re import commands - +import binascii import libvirt + from libvirt import libvirtError +from xml.dom import minidom from src import sharedmod @@ -15,6 +20,7 @@ required_params = ('networkname',) optional_params = {} VIRSH_NETUUID = "virsh net-uuid" +NWPATH = "/etc/libvirt/qemu/networks/" def check_network_exists(conn, networkname, logger): """ check if the network exists, may or may not be active """ @@ -29,25 +35,43 @@ def check_network_exists(conn, networkname, logger): def check_network_uuid(networkname, UUIDString, logger): """ check UUID String of a network """ - status, ret = commands.getstatusoutput(VIRSH_NETUUID + ' %s' % networkname) + status, ret = commands.getstatusoutput(VIRSH_NETUUID + ' %s' \ +% networkname) if status: - logger.error("executing "+ "\"" + VIRSH_NETUUID + ' %s' % networkname + "\"" + " failed") + logger.error("executing "+ "\"" + VIRSH_NETUUID + ' %s' % networkname\ + + "\"" + " failed") logger.error(ret) return False else: UUIDString_virsh = ret[:-1] logger.debug("UUIDString from API is %s" % UUIDString) - logger.debug("UUIDString from " + "\"" + VIRSH_NETUUID + "\"" " is %s" % UUIDString_virsh) + logger.debug("UUIDString from " + "\"" + VIRSH_NETUUID + "\"" " is %s"\ + % UUIDString_virsh) if UUIDString_virsh == UUIDString: return True else: return False +def checking_uuid(logger,nwname,nwuuid): + """ compare two UUIDs, one is from API, another is from network XML""" + global NWPATH + NWPATH = NWPATH + nwname + ".xml" + xml = minidom.parse(NWPATH) + network = xml.getElementsByTagName('network')[0] + uuid = network.getElementsByTagName('uuid')[0].childNodes[0].data + if uuid == nwuuid: + return True + else: + return False -def netuuid(params): - """ call appropriate API to generate the UUIDStirng - of a network , then compared to the output of command - virsh net-uuid +def network_uuid(params): + """ 1.call appropriate API to generate the UUIDStirng + of a network , then compared to the output of command + virsh net-uuid + 2.check below 2 new APIs: + networkLookupByUUIDString + networkLookupByUUID """ + global NWPATH logger = params['logger'] networkname = params['networkname'] @@ -61,7 +85,31 @@ def netuuid(params): try: UUIDString = netobj.UUIDString() - logger.info("the UUID string of network %s is %s" % (networkname, UUIDString)) + + #For a transient network, set another path + if not netobj.isPersistent() == 1: + NWPATH = "/var/run/libvirt/network/" + + logger.info("the UUID string of network \"%s\" is \"%s\""\ + % (networkname, UUIDString)) + #allowing '-' and ' ' anywhere between character pairs, just + #check one of them. + UUIDString1 = UUIDString.replace("-"," ") + network1 = conn.networkLookupByUUIDString(UUIDString1) + nw_name1 = network1.name() + logger.debug("The given UUID is \"%s\", the network is \"%s\" using\ + networkLookupByUUIDString" %(UUIDString1,nw_name1)) + + UUIDString2 = UUIDString.replace("-","") + UUID_ascii = binascii.a2b_hex(UUIDString2) + network2 = conn.networkLookupByUUID(UUID_ascii) + nw_name2 = network2.name() + logger.debug("The given UUID is \"%s\", the network is \"%s\" using \ +networkLookupByUUID" %(UUIDString2,nw_name2)) + + if nw_name1 == nw_name2 and checking_uuid(logger,nw_name1,UUIDString): + logger.info("Successed to get network name \"%s\" using \"%s\""\ + %(nw_name1,UUIDString)) if check_network_uuid(networkname, UUIDString, logger): logger.info(VIRSH_NETUUID + " test succeeded.") -- 1.8.3.1

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 -- 1.8.3.1

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
participants (2)
-
hongming
-
jiahu