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

Re: [libvirt] [test-API][PATCH] Add 7 memory API related cases



On 02/18/2013 03:36 PM, Wayne Sun wrote:
add 7 new cases using domain memory related API
add 1 conf for domain memory testing

7 new cases are:
memory_params_config: test set memory params with config flag
memory_params_live: test set memory params with live flag
memory_peek: test memory peek
memory_stats: test get memory stats
set_maxmem_config: test set maximum memory with config flag
set_memory_config: test set current memory with config flag
set_memory_live: test set current memory with live flag

diff --git a/repos/domain/memory_params_live.py b/repos/domain/memory_params_live.py
new file mode 100644
index 0000000..68a71b2
--- /dev/null
+++ b/repos/domain/memory_params_live.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+# Test set domain memory parameters with flag
+# VIR_DOMAIN_AFFECT_LIVE
+
+import os
+import math
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('guestname', 'hard_limit', 'soft_limit', 'swap_hard_limit', )
+optional_params = {}
+
+UNLIMITED = 9007199254740991
+CGROUP_PATH = "/cgroup/memory/libvirt/qemu"
+
+def get_cgroup_setting(guestname):
+    """get domain memory parameters in cgroup
+    """
+    if os.path.exists(CGROUP_PATH):
+        cgroup_path = "%s/%s" % (CGROUP_PATH, guestname)
+    else:
+        cgroup_path = "/sys/fs%s/%s" % (CGROUP_PATH, guestname)
+
+    f = open("%s/memory.limit_in_bytes" % cgroup_path)
+    hard = int(f.read())
+    logger.info("memory.limit_in_bytes value is %s" % hard)
+
+    f = open("%s/memory.soft_limit_in_bytes" % cgroup_path)
+    soft = int(f.read())
+    logger.info("memory.soft_limit_in_bytes value is %s" % soft)
+
+    f = open("%s/memory.memsw.limit_in_bytes" % cgroup_path)
+    swap = int(f.read())
+    logger.info("memory.memsw.limit_in_bytes value is %s" % swap)

        you need to close these file descriptors with f.close()


diff --git a/repos/domain/memory_stats.py b/repos/domain/memory_stats.py
new file mode 100644
index 0000000..5de4028
--- /dev/null
+++ b/repos/domain/memory_stats.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# Test get domain memory stats
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('guestname', )
+optional_params = {}
+
+VIRSH = "virsh qemu-monitor-command"
+
+def get_memory_actual(guestname):
+    """get memory stats with virsh commands
+    """
+    qmp_actual = -1
+    cmd ="%s %s '{ \"execute\": \"query-balloon\" }'" % (VIRSH, guestname)
+    logger.info("check memory stats with virsh command: %s" % cmd)
+    ret, out = utils.exec_cmd(cmd, shell=True)
+    out_dict = eval(out[0])
+    if out_dict.has_key('return'):
+        if out_dict['return'].has_key('actual'):
+            qmp_actual = out_dict['return']['actual']
+    else:
+        return False
+
+    if qmp_actual == -1:
+        return False
+
+    logger.info("the memory actal is: %s" % qmp_actual)

      s/actal/actual

      The rest of testcases are fine.

      Guannan



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