From patchwork Tue Dec 1 13:50:36 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 63958 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 nB1DouXO005379 for ; Tue, 1 Dec 2009 13:50:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751409AbZLANur (ORCPT ); Tue, 1 Dec 2009 08:50:47 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751400AbZLANur (ORCPT ); Tue, 1 Dec 2009 08:50:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1025 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751366AbZLANuq (ORCPT ); Tue, 1 Dec 2009 08:50:46 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB1DofLN029214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Dec 2009 08:50:41 -0500 Received: from localhost.localdomain (vpn-10-194.rdu.redhat.com [10.11.10.194]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB1DocrL011479; Tue, 1 Dec 2009 08:50:39 -0500 From: Lucas Meneghel Rodrigues To: kvm@vger.kernel.org Cc: autotest@test.kernel.org, skumar@linux.vnet.ibm.com, Lucas Meneghel Rodrigues , Yolkfull Chow Subject: [PATCH] KVM test: Add a subtest physical_resources_check Date: Tue, 1 Dec 2009 11:50:36 -0200 Message-Id: <1259675436-10209-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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()