From: Satheesh Rajendran <[email protected]>

Signed-off-by: Satheesh Rajendran <[email protected]>
---
 client/tests/libvirt/tests/virsh_nodememstats.py |  106 ++++++++++++++++++++++
 1 files changed, 106 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/libvirt/tests/virsh_nodememstats.py

diff --git a/client/tests/libvirt/tests/virsh_nodememstats.py 
b/client/tests/libvirt/tests/virsh_nodememstats.py
new file mode 100644
index 0000000..93cc39b
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_nodememstats.py
@@ -0,0 +1,106 @@
+import logging
+from autotest.client.shared import error
+from autotest.client.virt import libvirt_vm
+from autotest.client import *
+
+def run_virsh_nodememstats(test, params, env):
+    """
+    Test the command virsh nodememstats
+
+    (1) Call the virsh nodememstats command
+    (2) Get the output
+    (3) Check the against /proc/meminfo output
+    (4) Call the virsh nodememstats command with an unexpected option
+    (5) Call the virsh nodememstats command with libvirtd service stop
+    """
+
+    # Initialize the variables
+    deltas = []
+    name_stats = ['Total', 'Free', 'Buffers', 'Cached']
+    itr = int(params.get("itr"))
+
+    def virsh_check_nodememtats(actual_stats, expected_stats, delta):
+        """
+        Check the acual nodememstats output value with
+        """
+
+        delta_stats = []
+
+        for i in range(4):
+            delta_stats.append(abs(actual_stats[i] - expected_stats[i]))
+            if i == 0:
+                if not delta_stats[i] == 0:
+                    raise error.TestFail("Command 'virsh nodememstats' not 
succeeded"
+                                          "as the value for %s is deviated by 
%d\n"
+                                           "The total memory value is 
deviating-check"
+                                            % (name_stats[i], delta_stats[i]))
+            else:
+                if delta_stats[i] > delta:
+                    raise error.TestFail("Command 'virsh nodememstats' not 
succeeded"
+                                          "as the value for %s is deviated by 
%d"
+                                            % (name_stats[i], delta_stats[i]))
+        return delta_stats
+
+
+    # Prepare libvirtd service
+    check_libvirtd = params.has_key("libvirtd")
+    if check_libvirtd:
+        libvirtd = params.get("libvirtd")
+        if libvirtd == "off":
+            libvirt_vm.service_libvirtd_control("stop")
+
+
+    # Run test case for 10 iterations (default can be changed in subtests.cfg 
file)
+    # and print the final statistics
+    for i in range(itr):
+        option = params.get("virsh_nodememstats_options")
+        output = libvirt_vm.virsh_nodememstats(ignore_status=True, 
extra=option)
+        expected_stats = output.stdout.strip().split()
+        status = output.exit_status
+
+        # Check status_error
+        status_error = params.get("status_error")
+        if status_error == "yes":
+            if status == 0:
+                if libvirtd == "off":
+                    raise error.TestFail("Command 'virsh nodememstats' 
succeeded "
+                                     "with libvirtd service stopped, 
incorrect")
+                else:
+                    raise error.TestFail("Command 'virsh nodememstats %s' 
succeeded"
+                                     "(incorrect command)" % option)
+
+        elif status_error == "no":
+            if status == 0:
+                # Normalise to MBs
+                ex_total = int(expected_stats[2]) / 1024
+                ex_free = int(expected_stats[6]) / 1024
+                ex_buffer = int(expected_stats[9]) / 1024
+                ex_cache = int(expected_stats[13]) /1024
+                expected = [ex_total, ex_free, ex_buffer, ex_cache]
+
+                # Get the actual value from /proc/meminfo and normalise to MBs
+                at_total = int(utils.memtotal()) / 1024
+                at_free = int(utils.freememtotal()) / 1024
+                at_buffer = int(utils.read_from_meminfo('Buffers')) / 1024
+                at_cache = int(utils.read_from_meminfo('Cached')) / 1024
+                actual = [at_total, at_free, at_buffer, at_cache]
+
+                # Currently the delta value is kept at 150 MB this can be 
tuned based on the accuracy
+                # Needs a review on this value
+                delta = int(params.get("delta"))
+                output = virsh_check_nodememtats(actual, expected, delta)
+                deltas.append(output)
+            else:
+                raise error.TestFail("Command 'virsh nodememstats %s' not 
succeeded")
+
+    # Recover libvirtd service start
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("start")
+
+    if status_error == "no":
+        logging.info("The following is the deviations from the 
actual(/proc/meminfo)"
+                        " and expected value(output of virsh nodememstats)")
+        logging.info("itr  %s in MBs", name_stats)
+
+        for i in range(itr):
+            logging.info("itr %d   %s", i, deltas[i])
-- 
1.7.1

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to