From patchwork Wed Dec 29 22:37:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 440111 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBUMBElW000490 for ; Thu, 30 Dec 2010 22:12:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754102Ab0L2Whv (ORCPT ); Wed, 29 Dec 2010 17:37:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40782 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754089Ab0L2Wht (ORCPT ); Wed, 29 Dec 2010 17:37:49 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBTMbmkt013437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 29 Dec 2010 17:37:48 -0500 Received: from freedom.redhat.com (vpn-8-145.rdu.redhat.com [10.11.8.145]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBTMbWj0012882; Wed, 29 Dec 2010 17:37:47 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Eduardo Habkost Subject: [PATCH 8/8] KVM test: test/module_probe: use installer object to load modules Date: Wed, 29 Dec 2010 20:37:30 -0200 Message-Id: <1293662250-18292-9-git-send-email-lmr@redhat.com> In-Reply-To: <1293662250-18292-1-git-send-email-lmr@redhat.com> References: <1293662250-18292-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 30 Dec 2010 22:12:00 +0000 (UTC) diff --git a/client/tests/kvm/tests/module_probe.py b/client/tests/kvm/tests/module_probe.py index 727dcc2..c370c4d 100644 --- a/client/tests/kvm/tests/module_probe.py +++ b/client/tests/kvm/tests/module_probe.py @@ -1,55 +1,56 @@ import re, commands, logging, os -from autotest_lib.client.common_lib import error -import kvm_subprocess, kvm_test_utils, kvm_utils +from autotest_lib.client.common_lib import error, utils +import kvm_subprocess, kvm_test_utils, kvm_utils, installer + def run_module_probe(test, params, env): """ - load/unload kvm modules several times. + load/unload KVM modules several times. + + The test can run in two modes: - Module load/unload Test: - 1) check host cpu module - 2) get module info - 3) unload modules if they exist, else load them + - based on previous 'build' test: in case KVM modules were installed by a + 'build' test, we used the modules installed by the previous test. - @param test: Kvm test object - @param params: Dictionary with the test parameters - @param env: Dictionary with test environment. + - based on own params: if no previous 'build' test was run, + we assume a pre-installed KVM module. Some parameters that + work for the 'build' can be used, then, such as 'extra_modules'. """ - def module_probe(name_list, arg=""): - for name in name_list: - cmd = "modprobe %s %s" % (arg, name) - logging.debug(cmd) - s, o = commands.getstatusoutput(cmd) - if s != 0: - logging.error("Failed to load/unload modules %s" % o) - return False - return True - - #Check host cpu module - flags = file("/proc/cpuinfo").read() - arch_check = re.findall("%s\s" % "vmx", flags) - if arch_check: - arch = "kvm_intel" + installer_object = env.previous_installer() + if installer_object is None: + installer_object = installer.PreInstalledKvm() + installer_object.set_install_params(test, params) + + logging.debug('installer object: %r', installer_object) + + mod_str = params.get("mod_list") + if mod_str: + mod_list = re.split("[, ]", mod_str) + logging.debug("mod list will be: %r", mod_list) else: - arch = "kvm_amd" + mod_list = installer_object.full_module_list() + logging.debug("mod list from installer: %r", mod_list) - #Check whether ksm module exist - mod_str = "" - if os.path.exists("/sys/module/ksm"): - mod_str = "ksm," - mod_str += "%s, kvm" % arch + # unload the modules before starting: + installer_object._unload_modules(mod_list) - mod_str = params.get("mod_list", mod_str) - mod_list = re.split(",", mod_str) - logging.debug(mod_list) load_count = int(params.get("load_count", 100)) - try: for i in range(load_count): - if not module_probe(mod_list): - raise error.TestFail("Failed to load module %s" % mod_list) - if not module_probe(mod_list, "-r"): - raise error.TestFail("Failed to remove module %s" % mod_list) + try: + installer_object.load_modules(mod_list) + except Exception,e: + raise error.TestFail("Failed to load modules [%r]: %s" % + (installer_object.full_module_list, e)) + + # unload using rmmod directly because utils.unload_module() (used by + # installer) does too much (runs lsmod, checks for dependencies), + # and we want to run the loop as fast as possible. + for mod in reversed(mod_list): + r = utils.system("rmmod %s" % (mod), ignore_status=True) + if r <> 0: + raise error.TestFail("Failed to unload module %s. " + "exit status: %d" % (mod, r)) finally: - module_probe(mod_list) + installer_object.load_modules()