public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][KVM-AUTOTEST] Make code to remove kvm modules more robust
@ 2009-05-20 20:04 Mike Burns
  2009-05-24 15:36 ` Avi Kivity
  2009-05-25 13:41 ` Lucas Meneghel Rodrigues
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Burns @ 2009-05-20 20:04 UTC (permalink / raw)
  To: kvm; +Cc: lmr, ulublin, dhuff, Mike Burns


Signed-off-by: Mike Burns <mburns@redhat.com>
---
 client/tests/kvm_runtest_2/kvm_install.py |   56 ++++++++++++++++++++++++----
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/client/tests/kvm_runtest_2/kvm_install.py b/client/tests/kvm_runtest_2/kvm_install.py
index 5429a65..d1aceb2 100755
--- a/client/tests/kvm_runtest_2/kvm_install.py
+++ b/client/tests/kvm_runtest_2/kvm_install.py
@@ -86,11 +86,11 @@ def run_kvm_install(test, params, env):
             kvm_log.error(message)
             raise error.TestError, message
         for k in params.keys():
-            kvm_log.info("Adding KVM_INSTALL_%s to Environment" % (k))
-            os.putenv("KVM_INSTALL_%s" % (k), str(params[k]))
-        kvm_log.info("Running " + script + " to install kvm")
+	  kvm_log.info("Adding KVM_INSTALL_%s to Environment" % (k))
+          os.putenv("KVM_INSTALL_%s" % (k), str(params[k]))
+	kvm_log.info("Running " + script + " to install kvm")
         os.system("cd %s; %s" % (test.bindir, script))
-        kvm_log.info("Completed %s" % (script))
+	kvm_log.info("Completed %s" % (script))
 
     # invalid installation mode
     else:
@@ -215,11 +215,11 @@ def __load_kvm_modules():
     kvm_log.info("Unloading loaded KVM modules (if present)...")
     #utils.system("pkill qemu 1>/dev/null 2>&1", ignore_status=True)
     utils.system("pkill qemu", ignore_status=True)
-    #if utils.system("grep kvm_%s /proc/modules 1>/dev/null" % vendor, ignore_status=True) == 0:
-    utils.system("/sbin/rmmod kvm_%s" % vendor, ignore_status=True)
-    #if utils.system("grep kvm /proc/modules 1>/dev/null", ignore_status=True) == 0:
-    utils.system("/sbin/rmmod kvm", ignore_status=True)
 
+    # Remove existing modules
+    kvm_log.info("Checking KVM module")
+    __unload_modules("kvm")
+        
     if utils.system("grep kvm /proc/modules 1>/dev/null", ignore_status=True) == 0:
         message = "Failed to remove old KVM modules"
         kvm_log.error(message)
@@ -241,6 +241,46 @@ def __load_kvm_modules():
         kvm_log.error(message)
         raise error.TestError, message
 
+
+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)
+    
+    
+
+  #line_count = os.popen("lsmod | grep \"^%s \" | wc -l" % module)
+  #if line_count > 0:
+    #kvm_log.info("Found module %s, checking for dependecies..." %module)
+    #dependencies = os.popen("lsmod | grep \"^%s \" | awk '{print $4}'" % module).readline()
+    #submodules = dependencies.split(",")
+    #for submodule in submodules:
+      #__unload_modules(submodule)
+#
+    #
+  #kvm_log.info("Found module %s" % module)
+  #dependencies = os.popen("lsmod | grep \"^%s \" | awk '{print $4}'" % module)
+  #for line in dependencies.readlines():
+    #print "Line: %s" % line
+    #submodules = line.split(",")
+##    for submodule in submodules:
+##      __unload_modules(submodule)
+    #raise error.TestError, "Aborting..."
+    #kvm_log.info("Deleting Module %s" % module)
+    #utils.system("/sbin/modprobe -r %s" % module)
+
 def __install_kvm(test, srcdir):
     # create destination dir
 
-- 
1.5.5.6


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-05-26  4:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-20 20:04 [PATCH][KVM-AUTOTEST] Make code to remove kvm modules more robust Mike Burns
2009-05-24 15:36 ` Avi Kivity
2009-05-25 13:41 ` Lucas Meneghel Rodrigues
2009-05-25 16:40   ` Avi Kivity
2009-05-26  4:43     ` Lucas Meneghel Rodrigues

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox