[Libvirt-cim] [PATCH 2 of 4] [TEST] Adding functions to common_util.py to support the verifications of EAFP fields

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Fri Jul 11 12:21:35 UTC 2008


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1215777176 25200
# Node ID 65b1865d10a0570ec785e78affc0f69877bc8189
# Parent  25cd5c474b0797d36d67e200b4f8ed4ffa9cfedc
[TEST] Adding functions to common_util.py to support the verifications of EAFP fields.

Added the following functions:
1) eafp_dpool_cap_reserve_val() to get the DiskPool's Capacity and Reserved field values depending on which libvirt version is present on the machine.
2) eafp_mpool_reserve_val() to get the MemoryPool's Reserved field value.
3) Also, added get_value() function.

Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 25cd5c474b07 -r 65b1865d10a0 suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Fri Jul 11 04:42:09 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py	Fri Jul 11 04:52:56 2008 -0700
@@ -35,7 +35,9 @@
 from XenKvmLib.classes import get_typed_class
 from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE
 from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
-from VirtLib.live import diskpool_list, virsh_version, net_list
+from VirtLib.live import diskpool_list, virsh_version, net_list, \
+active_domain_list, virsh_dominfo_usedmem
+from VirtLib.utils import run_remote
 from XenKvmLib.vxml import PoolXML, NetXML
 
 test_dpath = "foo"
@@ -397,3 +399,66 @@
 
     return PASS 
 
+def get_value(server, cmd, log_msg, fieldname):
+    msg = log_msg % fieldname
+    ret, value = run_remote(server, cmd)
+    if ret != 0:
+        logger.error("%s", log_msg, fieldname)
+        return FAIL, value
+    return PASS, value
+
+def eafp_dpool_cap_reserve_val(server, virt, poolname):
+    libvirt_version = virsh_version(server, virt)
+    capacity = reserved = None
+    if libvirt_version >= '0.4.1':
+        # get the value from pool-info
+        log_msg= "Failed to get the '%s' info from pool-info"
+        dp_name, pname = poolname.split("/")
+
+        cmd = "virsh pool-info %s | awk '/Capacity/ { print \$2}'" \
+              % pname
+        status, cap_val = get_value(server, cmd, log_msg, 'Capacity')
+        if status != PASS:
+           return FAIL, capacity, reserved 
+        cap_val  = float(cap_val)
+        capacity = int(cap_val * 1024 * 1024 * 1024) >> 20
+ 
+        cmd = "virsh pool-info %s | awk '/Allocation/ { print \$2}'" \
+              % pname
+        status, alloc_val = get_value(server, cmd, log_msg, 'Allocation')
+        if status != PASS:
+           return FAIL, capacity, reserved 
+        alloc_val = float(alloc_val)
+        reserved  = int(alloc_val * 1024 * 1024 *1024) >> 20
+
+    else:
+        # get info from stat -filesystem
+        log_msg = "Stat on the '%s' file failed"
+
+        cmd = "stat -f %s | awk '/size/  {print   \$7}'" % disk_file  
+        status, f_bsize = get_value(server, cmd, log_msg, disk_file)
+        if status != PASS:
+           return FAIL, capacity, reserved 
+         
+        cmd = " stat -f %s | awk '/Blocks/  {print   \$3}'" % disk_file
+        status, b_total = get_value(server, cmd, log_msg, disk_file)
+        if status != PASS:
+           return FAIL, capacity, reserved 
+        cap_val = (int(f_bsize) * int(b_total)) 
+        capacity = (int(f_bsize) * int(b_total)) >> 20
+
+        cmd = "stat -f %s | awk '/Blocks/  {print \$5}'" % disk_file
+        status, b_free = get_value(server, cmd, log_msg, disk_file)
+        if status != PASS:
+           return FAIL, capacity, reserved 
+        reserved = (cap_val - (int(f_bsize) * int(b_free))) >> 20
+
+    return PASS, capacity, reserved
+
+def eafp_mpool_reserve_val(server, virt):
+    reserved = 0
+    doms = active_domain_list(server, virt)
+    for dom_name in doms:
+       mem =  virsh_dominfo_usedmem(server, dom_name, virt)
+       reserved += mem  
+    return reserved




More information about the Libvirt-cim mailing list