Change in vdsm[master]: vdsm-tool: unify ad-hoc execCmd implementations
zhshzhou at linux.vnet.ibm.com
zhshzhou at linux.vnet.ibm.com
Wed Apr 24 06:49:22 UTC 2013
Zhou Zheng Sheng has posted comments on this change.
Change subject: vdsm-tool: unify ad-hoc execCmd implementations
......................................................................
Patch Set 2: (5 inline comments)
Thanks Yaniv and Ewoud.
....................................................
File lib/vdsm/tool/__init__.py
Line 50: modules.add(base)
Line 51: return sorted(modules)
Line 52:
Line 53:
Line 54: def load_modules():
Done
Line 55: """
Line 56: Dynamically load the modules present in the tool package.
Line 57:
Line 58: This means that vdsm-tool doesn't need to know in advance the modules
Line 115: for cmd_name, cmd_docs in mod_desc:
Line 116: _usage_command(cmd_name, cmd_docs)
Line 117:
Line 118:
Line 119: def usage_and_exit(exit_code):
Done
Line 120: print "Usage: %s [options] <action> [arguments]\n" % sys.argv[0]
Line 121:
Line 122: print "Valid options:"
Line 123: print " -h, --help"
....................................................
File lib/vdsm/tool/load_needed_modules.py.in
Line 27: def _exec_command(argv):
Line 28: """
Line 29: This function executes a given shell command.
Line 30: """
Line 31: rc, out, err = execCmd(argv, raw=True)
Done
Line 32: if rc != 0:
Line 33: raise Exception("Execute command %s failed: %s" % (argv, err))
Line 34:
Line 35:
....................................................
File vdsm-tool/vdsm-tool.in
Line 1: #!/usr/bin/python
Done
Line 2: import sys
Line 3:
Line 4: from vdsm import tool
Line 5:
Line 2: import sys
Line 3:
Line 4: from vdsm import tool
Line 5:
Line 6: sys.path.append("@VDSMDIR@")
Thanks Ewoud. This is because the code in vdsm.utils.execCmd is as follow.
def execCmd(*args, **kwargs):
# import only after config as been initialized
from storage.misc import execCmd
return execCmd(*args, **kwargs)
It imports storage.misc.execCmd when vdsm.utils.execCmd is called. To make this work, we just append @VDSMDIR@ before anyone can call vdsm.utils.execCmd. So it's OK to place this line after "from vdsm import tool".
The definition of vdsm.utils.execCmd is a hack. This patch is the hack of the hack... I do not want to palce this line before importing vdsm.tool, because this hack of the hack is just to make the vdsm.utils.execCmd to work. If I place this line before importing vdsm.tool, it covers too much. Suppose someone mistakenly import some modules in @VDSMDIR@ at vdsm module, python should fail and report error to us when we import vdsm.tool, while we want vdsm.utils.execCmd succeed. So I put "sys.path.append("@VDSMDIR@")" after from vdsm import tool.
--
To view, visit http://gerrit.ovirt.org/13917
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I8ca64ec5dbfebe5c5090ec8fac46785a538b79d3
Gerrit-PatchSet: 2
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Douglas Schilling Landgraf <dougsland at redhat.com>
Gerrit-Reviewer: Ewoud Kohl van Wijngaarden <ewoud at kohlvanwijngaarden.nl>
Gerrit-Reviewer: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Mark Wu <wudxw at linux.vnet.ibm.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
More information about the vdsm-patches
mailing list