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

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

 



On 02/19/2013 05:59 PM, Wayne Sun wrote:
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')

It'd better to get optional parameters directly from dict params that
           would save code to check its value again.
           I will fix the framework to make it work.


+
+    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')

          These two temple looks similar in logic.
          we can do some magics to make it simpler.

+    for i in tmp:
+        if eval(i):
+            param_dict[i] = int(eval(i))

After we can get optional parameters directly from params, the code will be not necessary.


+
+    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"
+

numastat is not installed commonly, can we check whether it exists or not before using it.


+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]

      The readability of above code is not good, can we filter code using
      keyword rather than the position, so are the following codes.
        Guannan Ren

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