[test-API][PATCH] Add 2 host node memory API cases

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

 



add 2 host node memory cases and update conf
- node_mem_param: tuning host node memory parameters.
- node_memory: get host node memory info, including host free
memory, node free memory and node memory stats.
- numa_param conf is updated with the 2 new cases

Signed-off-by: Wayne Sun <gsun@xxxxxxxxxx>
---
 cases/numa_param.conf        |   8 ++++
 repos/numa/node_mem_param.py |  86 ++++++++++++++++++++++++++++++++++++
 repos/numa/node_memory.py    | 101 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 repos/numa/node_mem_param.py
 create mode 100644 repos/numa/node_memory.py

diff --git a/cases/numa_param.conf b/cases/numa_param.conf
index 64268a3..515fb1f 100644
--- a/cases/numa_param.conf
+++ b/cases/numa_param.conf
@@ -1,3 +1,11 @@
+numa:node_memory
+
+numa:node_mem_param
+    shm_pages_to_scan
+        200
+    shm_sleep_millisecs
+        20
+
 domain:install_linux_cdrom
     guestname
         $defaultname
diff --git a/repos/numa/node_mem_param.py b/repos/numa/node_mem_param.py
new file mode 100644
index 0000000..ba6f8f4
--- /dev/null
+++ b/repos/numa/node_mem_param.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# Test tuning host node memory parameters
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ()
+optional_params = {"shm_pages_to_scan": 100,
+                   "shm_sleep_millisecs": 20,
+                   "shm_merge_across_nodes": 1
+                  }
+
+KSM_PATH = "/sys/kernel/mm/ksm/"
+
+def node_mem_param(params):
+    """test set host node memory parameters
+    """
+    logger = params['logger']
+    shm_pages_to_scan = params.get('shm_pages_to_scan')
+    shm_sleep_millisecs = params.get('shm_sleep_millisecs')
+    shm_merge_across_nodes = params.get('shm_merge_across_nodes')
+
+    if not shm_pages_to_scan \
+        and not shm_sleep_millisecs \
+        and not shm_merge_across_nodes:
+        logger.error("given param is none")
+        return 1
+
+    param_dict = {}
+    tmp = ('shm_pages_to_scan', 'shm_sleep_millisecs', 'shm_merge_across_nodes')
+    tmp1 = ('pages_to_scan', 'sleep_millisecs', 'merge_across_nodes')
+    for i in tmp:
+        if eval(i):
+            param_dict[i] = int(eval(i))
+
+    logger.info("the given param dict is: %s" % param_dict)
+
+    conn = sharedmod.libvirtobj['conn']
+
+    try:
+        logger.info("get host node memory parameters")
+        mem_pre = conn.getMemoryParameters(0)
+        logger.info("host node memory parameters is: %s" % mem_pre)
+
+        logger.info("set host node memory parameters with given param %s" %
+                    param_dict)
+        conn.setMemoryParameters(param_dict, 0)
+        logger.info("set host node memory parameters done")
+
+        logger.info("get host node memory parameters")
+        mem_pos = conn.getMemoryParameters(0)
+        logger.info("host node memory parameters is: %s" % mem_pos)
+
+        for i in tmp:
+            if eval(i):
+                if not mem_pos[i] == param_dict[i]:
+                    logger.error("%s is not set as expected" % i)
+
+        logger.info("node memory parameters is set as expected")
+
+        logger.info("check tuning detail under %s" % KSM_PATH)
+
+        mem_tmp = {}
+        for i in tmp1:
+            str_tmp = 'shm_%s' % i
+            if eval(str_tmp):
+                path = "%s%s" % (KSM_PATH, i)
+                f = open(path)
+                ret = int(f.read().split('\n')[0])
+                f.close()
+                logger.info("%s value is: %s" % (path, ret))
+                mem_tmp[str_tmp] = ret
+
+        if mem_tmp == param_dict:
+            logger.info("tuning detail under %s is expected" % KSM_PATH)
+        else:
+            logger.error("check with tuning detail under %s failed"  % KSM_PATH)
+            return 1
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0
diff --git a/repos/numa/node_memory.py b/repos/numa/node_memory.py
new file mode 100644
index 0000000..47d3b4a
--- /dev/null
+++ b/repos/numa/node_memory.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+# Test get host node memory info, including host free
+# memory, node free memory and node memory stats.
+
+import math
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ()
+optional_params = {}
+
+CMD = "numastat -m"
+
+def node_memory(params):
+    """test get host node memory info
+    """
+    logger = params['logger']
+
+    cmd = "lscpu|grep 'NUMA node(s)'"
+    ret, output = utils.exec_cmd(cmd, shell=True)
+    node_num = int(output[0].split(' ')[-1])
+    logger.info("host total nodes number is: %s" % node_num)
+
+    conn = sharedmod.libvirtobj['conn']
+
+    try:
+        logger.info("get host total free memory")
+        mem = conn.getFreeMemory()/1048576
+        logger.info("host free memory total is: %s KiB" % mem)
+        ret, out = utils.exec_cmd(CMD, shell=True)
+        mem_total = " ".join(out[5].split()).split()[-1]
+        mem_total = int(eval(mem_total))
+        logger.info("output of '%s' is: %s KiB" % (CMD, mem_total))
+
+        if math.fabs(mem - mem_total) > 1:
+            logger.error("free memory mismatch with result of '%s'" % CMD)
+            return 1
+        else:
+            logger.info("get host free memory succeed")
+
+        logger.info("get free memory of nodes")
+        ret = conn.getCellsFreeMemory(0, node_num)
+        mem = [i/1048576 for i in ret]
+        logger.info("nodes free memory list is: %s" % mem)
+
+        ret, out = utils.exec_cmd(CMD, shell=True)
+        mem_tmp = " ".join(out[5].split()).split()[1:-1]
+        node_mem = [int(eval(i)) for i in mem_tmp]
+        logger.info("output of '%s' is: %s" % (CMD, node_mem))
+
+        for i in range(node_num):
+            if math.fabs(mem[i] - node_mem[i]) > 1:
+                logger.error("node %s free memory mismatch with command '%s'"
+                             % CMD)
+                return 1
+
+        logger.info("get node free memory succeed")
+
+        logger.info("get node memory stats")
+        node_dict = {}
+        for i in range(node_num):
+            ret = conn.getMemoryStats(i, 0)
+            for j in ret.keys():
+                ret[j] = ret[j]/1024
+            node_dict[i] = ret
+            logger.info("node %s memory stats is: %s" % (i, node_dict[i]))
+
+        node_tmp = {}
+        logger.info("get node memory stats with '%s'" % CMD)
+        ret, out = utils.exec_cmd(CMD, shell=True)
+        mem_total_tmp = " ".join(out[4].split()).split()[1:-1]
+        mem_free_tmp = " ".join(out[5].split()).split()[1:-1]
+        for i in range(node_num):
+            dict_tmp = {}
+            dict_tmp['total'] = int(eval(mem_total_tmp[i]))
+            dict_tmp['free'] = int(eval(mem_free_tmp[i]))
+            node_tmp[i] = dict_tmp
+            logger.info("node %s memory stats is: %s" % (i, node_tmp[i]))
+
+        for i in range(node_num):
+            if math.fabs(node_tmp[i]['total'] - node_dict[i]['total']) > 1:
+                logger.error("node %s total memory is mismatch with of '%s'" %
+                             (i, CMD))
+                return 1
+
+            if math.fabs(node_tmp[i]['free'] - node_dict[i]['free']) > 1:
+                logger.error("node %s free memory is mismatch with of '%s'" %
+                             (i, CMD))
+                return 1
+
+        logger.info("get node memory stats succeed")
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0
-- 
1.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]