[PATCH] KVM test: Add a subtest physical_resources_check

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

 



This test will test following parameters of a VM:
1) count of CPU, hard disks and NICs
2) memory size
3) model of hard disks and NICs
4) NICs' mac address
5) UUID and serial number (if defined the command in config file)

Signed-off-by: Yolkfull Chow <yzhou@xxxxxxxxxx>
---
 client/tests/kvm/kvm_tests.cfg.sample              |   11 ++
 client/tests/kvm/kvm_vm.py                         |   39 ++++++
 client/tests/kvm/tests/physical_resources_check.py |  140 ++++++++++++++++++++
 3 files changed, 190 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/physical_resources_check.py

diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index 5e15b30..9fb1ba8 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -255,6 +255,10 @@ variants:
         kill_vm_gracefully_vm2 = no
         address_index_vm2 = 1
 
+    - physical_resources_check: install setup unattended_install
+        type = physical_resources_check
+        catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}'
+
 # NICs
 variants:
     - @rtl8139:
@@ -280,6 +284,8 @@ variants:
         shell_port = 22
         file_transfer_client = scp
         file_transfer_port = 22
+        mem_chk_cmd = dmidecode -t 17 | awk -F: '/Size/ {print $2}'
+        cpu_chk_cmd = grep -c processor /proc/cpuinfo
 
         variants:
             - Fedora:
@@ -553,6 +559,9 @@ variants:
         # This ISO will be used for all tests except install:
         cdrom = windows/winutils.iso
 
+        cpu_chk_cmd = echo %NUMBER_OF_PROCESSORS%
+        mem_chk_cmd = wmic memphysical
+
         migrate:
             migration_test_command = ver && vol
             migration_bg_command = start ping -t localhost
@@ -594,6 +603,8 @@ variants:
             reference_cmd = wmic diskdrive list brief
             find_pci_cmd = wmic diskdrive list brief
             pci_test_cmd = echo select disk 1 > dt && echo online >> dt && echo detail disk >> dt && echo exit >> dt && diskpart /s dt
+        physical_resources_check:
+            catch_uuid_cmd = 
 
         variants:
             - Win2000:
diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index 100b567..cc314d4 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -821,3 +821,42 @@ class VM:
             return self.uuid
         else:
             return self.params.get("uuid", None)
+
+
+    def get_cpu_count(self):
+        """
+        Get the cpu count of the VM.
+        """
+        try:
+            session = self.remote_login()
+            if session:
+                cmd = self.params.get("cpu_chk_cmd")
+                s, count = session.get_command_status_output(cmd)
+                if s == 0:
+                    return int(count)
+            return None
+        finally:
+            session.close()
+
+
+    def get_memory_size(self):
+        """
+        Get memory size of the VM.
+        """
+        try:
+            session = self.remote_login()
+            if session:
+                cmd = self.params.get("mem_chk_cmd")
+                s, mem_str = session.get_command_status_output(cmd)
+                if s != 0:
+                    return None
+                mem = re.findall("([0-9][0-9][0-9]+)", mem_str)
+                mem_size = 0
+                for m in mem:
+                    mem_size += int(m)
+                if not "MB" in mem_str:
+                    mem_size /= 1024
+                return int(mem_size)
+            return None
+        finally:
+            session.close()
diff --git a/client/tests/kvm/tests/physical_resources_check.py b/client/tests/kvm/tests/physical_resources_check.py
new file mode 100644
index 0000000..ce36627
--- /dev/null
+++ b/client/tests/kvm/tests/physical_resources_check.py
@@ -0,0 +1,140 @@
+import re, string, logging
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+
+def run_physical_resources_check(test, params, env):
+    """
+    Check physical resources assigned to KVM virtual machines:
+    1) Log into the guest
+    2) Verify whether cpu counts ,memory size, nics' model,
+       count and drives' format & count, drive_serial, UUID
+       reported by the guest OS matches what has been assigned
+       to the VM (qemu command line)
+    3) Verify all MAC addresses for guest NICs
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+
+    logging.info("Starting physical resources check test")
+    logging.info("Values assigned to VM are the values we expect "
+                 "to see reported by the Operating System")
+    # Define a failure counter, as we want to check all physical
+    # resources to know which checks passed and which ones failed
+    nfail = 0
+
+    # Check cpu count
+    logging.info("CPU count check")
+    expected_cpu_nr = int(params.get("smp"))
+    actual_cpu_nr = vm.get_cpu_count()
+    if expected_cpu_nr != actual_cpu_nr:
+        nfail += 1
+        logging.error("CPU count mismatch:")
+        logging.error("    Assigned to VM: %s" % expected_cpu_nr)
+        logging.error("    Reported by OS: %s" % actual_cpu_nr)
+
+    # Check memory size
+    logging.info("Memory size check")
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        nfail += 1
+        logging.error("Memory size mismatch:")
+        logging.error("    Assigned to VM: %s" % expected_mem)
+        logging.error("    Reported by OS: %s" % actual_mem)
+
+    # Define a function for checking number of hard drivers & NICs
+    def check_num(devices, cmd, str):
+        expected_num = kvm_utils.get_sub_dict_names(params, devices).__len__()
+        s, o = vm.send_monitor_cmd(cmd)
+        if s != 0:
+            nfail += 1
+            logging.error("qemu monitor command failed: %s" % cmd)
+
+        actual_num = string.count(o, str)
+        if expected_num != actual_num:
+            logging.error("%s number mismatch:")
+            logging.error("    Assigned to VM: %d" % expected_num)
+            logging.error("    Reported by OS: %d" % actual_num)
+        return expected_num
+
+    logging.info("Hard drive count check")
+    drives_num = check_num("images", "info block", "type=hd")
+
+    logging.info("NIC count check")
+    nics_num = check_num("nics", "info network", "model=")
+
+    # Define a function for checking hard drives & NICs' model
+    def chk_fmt_model(device, fmt_model, cmd, str):
+        devices = kvm_utils.get_sub_dict_names(params, device)
+        for chk_device in devices:
+            expected = kvm_utils.get_sub_dict(params, chk_device).get(fmt_model)
+            if not expected:
+                expected = "rtl8139"
+            s, o = vm.send_monitor_cmd(cmd)
+            if s != 0:
+                nfail += 1
+                logging.error("qemu monitor command failed: %s" % cmd)
+
+            device_found = re.findall(str, o)
+            logging.debug("Found devices: %s" % device_found)
+            found = False
+            for fm in device_found:
+                if expected in fm:
+                    found = True
+
+            if not found:
+                nfail += 1
+                logging.error("%s model mismatch:")
+                logging.error("    Assigned to VM: %s" % expected)
+                logging.error("    Reported by OS: %s" % device_found)
+
+    logging.info("NICs model check")
+    chk_fmt_model("nics", "nic_model", "info network", "model=(.*),")
+
+    logging.info("Drive format check")
+    chk_fmt_model("images", "drive_format", "info block", "(.*)\: type=hd")
+
+    logging.info("Network card MAC check")
+    s, o = vm.send_monitor_cmd("info network")
+    if s != 0:
+        nfail += 1
+        logging.error("qemu monitor command failed: %s" % cmd)
+    found_mac_addresses = re.findall("macaddr=(.*)", o)
+    logging.debug("Found MAC adresses: %s" % found_mac_addresses)
+
+    for nic_name in kvm_utils.get_sub_dict_names(params, "nics"):
+        nic_params = kvm_utils.get_sub_dict(params, nic_name)
+        mac, ip = kvm_utils.get_mac_ip_pair_from_dict(nic_params)
+        if not string.lower(mac) in found_mac_addresses:
+            nfail += 1
+            logging.error("MAC address mismatch:")
+            logging.error("    Assigned to VM (not found): %s" % mac)
+
+    # Define a function to verify UUID & Serial number
+    def verify_device(expect, name, verify_cmd):
+        if verify_cmd:
+            actual = session.get_command_output(verify_cmd)
+            if not string.upper(expect) in actual:
+                nfail += 1
+                logging.error("%s mismatch:")
+                logging.error("    Assigned to VM: %s" % string.upper(expect))
+                logging.error("    Reported by OS: %s" % actual)
+
+    logging.info("UUID check")
+    if vm.get_uuid():
+        verify_device(vm.get_uuid(), "UUID", params.get("catch_uuid_cmd"))
+
+    logging.info("Hard Disk serial number check")
+    catch_serial_cmd = params.get("catch_serial_cmd")
+    verify_device(params.get("drive_serial"), "Serial", catch_serial_cmd)
+
+    if nfail != 0:
+        raise error.TestFail("Physical resources check test reported %s "
+                             "failures. Please verify the test logs." % nfail)
+
+    session.close()
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux