diff mbox

KVM test: Add a subtest params_verify

Message ID 1259560571-14488-1-git-send-email-yzhou@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yolkfull Chow Nov. 30, 2009, 5:56 a.m. UTC
None
diff mbox

Patch

diff --git a/client/bin/harness_standalone.py b/client/bin/harness_standalone.py
index 4ec7cd2..c70c09b 100644
--- a/client/bin/harness_standalone.py
+++ b/client/bin/harness_standalone.py
@@ -36,7 +36,7 @@  class harness_standalone(harness.harness):
         if os.path.exists('/etc/event.d'):
             # NB: assuming current runlevel is default
             initdefault = utils.system_output('/sbin/runlevel').split()[1]
-        else if os.path.exists('/etc/inittab'):
+        elif os.path.exists('/etc/inittab'):
             initdefault = utils.system_output('grep :initdefault: /etc/inittab')
             initdefault = initdefault.split(':')[1]
         else:
diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index feffb8d..94763c5 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -243,6 +243,10 @@  variants:
         kill_vm = yes
         kill_vm_gracefully = no
 
+    - params_verify:
+        type = params_verify
+        catch_uuid_cmd = dmidecode | awk -F: '/UUID/ {print $2}'
+
 
 # NICs
 variants:
@@ -269,6 +273,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:
@@ -542,6 +548,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
@@ -583,6 +592,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
+        params_verify:
+            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/params_verify.py b/client/tests/kvm/tests/params_verify.py
new file mode 100644
index 0000000..a30a91d
--- /dev/null
+++ b/client/tests/kvm/tests/params_verify.py
@@ -0,0 +1,110 @@ 
+import re, string, logging
+from autotest_lib.client.common_lib import error
+import kvm_test_utils, kvm_utils
+
+def run_params_verify(test, params, env):
+    """
+    Verify all parameters in KVM command line:
+    1) Log into the guest
+    2) Verify whether cpu counts ,memory size, nics' model,
+       count and drives' format & count, drive_serial, UUID
+    3) Verify all nic cards' macaddr
+
+    @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)
+
+    # Check cpu count
+    expected_cpu_nr = int(params.get("smp"))
+    actual_cpu_nr = vm.get_cpu_count()
+    if expected_cpu_nr != actual_cpu_nr:
+        raise error.TestFail("VM's CPU count [%d] mismatch with assigned [%d]"
+                                           % (actual_cpu_nr, expected_cpu_nr))
+
+    # Check memory size
+    expected_mem = int(params.get("mem"))
+    actual_mem = vm.get_memory_size()
+    if actual_mem != expected_mem:
+        raise error.TestFail("Memory size mismatch; Actual: %s; Expected: %d" %
+                                                    (actual_mem, expected_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:
+            raise error.TestError("Send monitor command failed: %s" % cmd)
+
+        actual_num = string.count(o, str)
+        if expected_num != actual_num:
+            raise error.TestFail("%s number mismatch;expected:%d; actual:%d" %
+                                          (devices, expected_num, actual_num))
+        return expected_num
+
+    # Check hard drives' count
+    drives_num = check_num("images", "info block", "type=hd")
+
+    # Check NIC cards' count
+    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:
+                raise error.TestError("Send monitor command failed: %s" % cmd)
+
+            founded_device = re.findall(str, o)
+            logging.info("Founded devices:%s" % founded_device)
+            found = False
+            for fm in founded_device:
+                if expected in fm:
+                    found = True
+
+            if not found:
+                raise error.TestFail("Not found expected format(model): %s; "
+                                     "VM has: %s" % (expected, founded_device))
+
+    # Verify nics' model
+    chk_fmt_model("nics", "nic_model", "info network", "model=(.*),")
+
+    # Verify drives' format
+    chk_fmt_model("images", "drive_format", "info block", "(.*)\: type=hd")
+
+    # Verify nics' macaddr
+    s, o = vm.send_monitor_cmd("info network")
+    if s != 0:
+        raise error.TestError("Send monitor command failed: %s" % cmd)
+    founded_macaddrs = re.findall("macaddr=(.*)", o)
+    logging.info("Founded macaddr: %s" % founded_macaddrs)
+
+    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 founded_macaddrs:
+            raise error.TestFail("Assigned MAC %s is not found in VM" % 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:
+                raise error.TestFail("%s mismatch; Expected:%s; Actual: %s" %
+                                     (name, string.upper(expect), actual))
+
+    # Verify UUID
+    if vm.get_uuid():
+        verify_device(vm.get_uuid(), "UUID", params.get("catch_uuid_cmd"))
+
+    # Verify Hard Disk's serial Number
+    catch_serial_cmd = params.get("catch_serial_cmd")
+    verify_device(params.get("drive_serial"), "Serial", catch_serial_cmd)
+
+    session.close()