[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [libvirt-test-api][PATCH 2/3] Add getCellsFreeMemory test case



It is hard to check if the free memory for each node is right, because
memory change too fast in most machine (even machine in low load).
Get this free memory 1000 times and get the Standard Deviation via
get_standard_deviation().

177 is a expectations get from 1000 times test in a low load machine,
so this case may still get fail in some big machine.

Signed-off-by: Luyao Huang <lhuang redhat com>
---
 cases/test_connection.conf                     |  4 ++
 repos/virconn/connection_getCellsFreeMemory.py | 53 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 repos/virconn/connection_getCellsFreeMemory.py

diff --git a/cases/test_connection.conf b/cases/test_connection.conf
index 5719937..1dc98e7 100644
--- a/cases/test_connection.conf
+++ b/cases/test_connection.conf
@@ -57,3 +57,7 @@ virconn:connection_getDomainCapabilities
         pc-i440fx-rhel7.0.0
     virttype
         kvm
+
+virconn:connection_getCellsFreeMemory
+    conn
+        qemu:///system
diff --git a/repos/virconn/connection_getCellsFreeMemory.py b/repos/virconn/connection_getCellsFreeMemory.py
new file mode 100644
index 0000000..a14e5aa
--- /dev/null
+++ b/repos/virconn/connection_getCellsFreeMemory.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+import libvirt
+from libvirt import libvirtError
+from  utils import utils
+
+required_params = ()
+optional_params = {'conn': ''}
+
+NODE_ONLINE = '/sys/devices/system/node/online'
+
+def getnodemem(path):
+    return open(path).read().splitlines()[1].split()[3]
+
+def virtgetmem(a):
+    return a[0].getCellsFreeMemory(a[1], a[1] + 1)[0]/1024
+
+def connection_getCellsFreeMemory(params):
+    """
+       test API for getCellsFreeMemory in class virConnect
+    """
+    logger = params['logger']
+    fail=0
+
+    nodeset = utils.file_read(NODE_ONLINE)
+    logger.info("host exist node is %s" % nodeset)
+
+    node_tuple = utils.param_to_tuple_nolength(nodeset)
+    if not node_tuple:
+        logger.info("error in function param_to_tuple_nolength")
+        return 1
+
+    try:
+        conn=libvirt.open(params['conn'])
+
+        logger.info("get connection cells free memory")
+        for n in range(len(node_tuple)):
+            if not node_tuple[n]:
+                continue
+
+            D = utils.get_standard_deviation(getnodemem, virtgetmem, \
+                '/sys/devices/system/node/node%d/meminfo' % n, [conn,n])
+            logger.info("Standard Deviation for node %d is %d" % (n, D))
+
+            """ expectations 177 is a average collected in a x86_64 low load machine"""
+            if D > 177*5:
+                fail=1
+                logger.info("FAIL: Standard Deviation is too big \
+                             (biger than %d) for node %d" % (177*5, n))
+
+    except libvirtError, e:
+        logger.error("API error message: %s" % e.message)
+        fail=1
+    return fail
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]