From patchwork Mon Nov 30 05:56:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yolkfull Chow X-Patchwork-Id: 63616 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAU5uK9C006295 for ; Mon, 30 Nov 2009 05:56:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751528AbZK3F4M (ORCPT ); Mon, 30 Nov 2009 00:56:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751434AbZK3F4M (ORCPT ); Mon, 30 Nov 2009 00:56:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751383AbZK3F4L (ORCPT ); Mon, 30 Nov 2009 00:56:11 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAU5uGPL014782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Nov 2009 00:56:17 -0500 Received: from localhost.localdomain (dhcp-65-181.nay.redhat.com [10.66.65.181]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAU5uEQZ027353; Mon, 30 Nov 2009 00:56:15 -0500 From: Yolkfull Chow To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Yolkfull Chow Subject: [PATCH] KVM test: Add a subtest params_verify Date: Mon, 30 Nov 2009 13:56:11 +0800 Message-Id: <1259560571-14488-1-git-send-email-yzhou@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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()