Change in vdsm[ovirt-3.3]: vdsm-tool: handle error during module loading

ybronhei at redhat.com ybronhei at redhat.com
Sun Mar 2 12:56:31 UTC 2014


Hello Dan Kenigsberg, Zhou Zheng Sheng,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/25238

to review the following change.

Change subject: vdsm-tool: handle error during module loading
......................................................................

vdsm-tool: handle error during module loading

While vdsm-tool initiates it loads all python modules under tool folder.
If one of them throws exception vdsm-tool fails to run. This patch
handles such exception and reports it to syslog.

Change-Id: I023ad390723617d10664f9bf5b8d1460131efef2
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
Reviewed-on: http://gerrit.ovirt.org/23456
Reviewed-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
Reviewed-by: Dan Kenigsberg <danken at redhat.com>
---
M vdsm-tool/vdsm-tool
1 file changed, 11 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/38/25238/1

diff --git a/vdsm-tool/vdsm-tool b/vdsm-tool/vdsm-tool
index 9f75a06..8336de4 100755
--- a/vdsm-tool/vdsm-tool
+++ b/vdsm-tool/vdsm-tool
@@ -23,6 +23,8 @@
 import imp
 import getopt
 import textwrap
+import syslog
+import traceback
 
 import vdsm.tool
 
@@ -65,13 +67,21 @@
     global tool_modules, tool_command
 
     mod_path = os.path.dirname(vdsm.tool.__file__)
+    package_name = vdsm.tool.__name__
 
     for mod_name in _listPathModules(mod_path):
         if mod_name.startswith("_"):
             continue
 
         mod_fobj, mod_absp, mod_desc = imp.find_module(mod_name, [mod_path])
-        module = imp.load_module(mod_name, mod_fobj, mod_absp, mod_desc)
+        try:
+            module = imp.load_module(package_name + '.' + mod_name, mod_fobj,
+                                     mod_absp, mod_desc)
+        except Exception:
+            # py module was failed to load. report to syslog and continue
+            syslog.syslog("module %s could not load to vdsm-tool: %s" %
+                          (mod_name, traceback.format_exc()))
+            continue
 
         mod_cmds = []
 


-- 
To view, visit http://gerrit.ovirt.org/25238
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I023ad390723617d10664f9bf5b8d1460131efef2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.3
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list