From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lucas Meneghel Rodrigues Subject: Re: [PATCH][KVM-AUTOTEST] Make code to remove kvm modules more robust Date: Mon, 25 May 2009 10:41:33 -0300 Message-ID: <1243258893.2838.18.camel@localhost.localdomain> References: <1242849851-8029-1-git-send-email-mburns@redhat.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, ulublin@redhat.com, dhuff@redhat.com To: Mike Burns Return-path: Received: from mx2.redhat.com ([66.187.237.31]:40792 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751551AbZEYNlg (ORCPT ); Mon, 25 May 2009 09:41:36 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4PDfdfd012844 for ; Mon, 25 May 2009 09:41:39 -0400 In-Reply-To: <1242849851-8029-1-git-send-email-mburns@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Hi Mike, On Wed, 2009-05-20 at 16:04 -0400, Mike Burns wrote: > + > +def __unload_modules(module): > + lsmod = os.popen("lsmod | grep \"^%s \"" % module) > + line_parts = lsmod.readline().split() > + if len(line_parts) == 0: > + kvm_log.info("%s not loaded." % module) > + else: > + kvm_log.info("Found module %s, checking for dependecies..." %module) > + if len(line_parts) == 4: > + submodules = line_parts[3].split(",") > + for submodule in submodules: > + __unload_modules(submodule) > + else: > + kvm_log.info("No modules dependent on %s" % module ) > + > + kvm_log.info("Removing module: %s" % module) > + utils.system("/sbin/modprobe -r %s" % module, ignore_status=False) ignore_status is False by default, so no need to do explicitly pass it to the function. Also, as we are putting something that can throw an exception, you can wrap it in a try/except module that throws a error.TestError exception in case our module removal still fails. Other than that, I agree with Avi that we should avoid adding commented lines, and prefer python constructs over shell ones. -- Lucas Meneghel Rodrigues Software Engineer (QE) Red Hat - Emerging Technologies