Zhou Zheng Sheng has uploaded a new change for review.
Change subject: vdsm-tool: unify ad-hoc execCmd implementations
......................................................................
vdsm-tool: unify ad-hoc execCmd implementations
vdsm.utils.execCmd is actually storage.misc.execCmd, and /usr/share/vdsm
is not in PYTHONPATH, so modules of vdsm-tool can not use execCmd and
there are various ad-hoc implementations in the vdsm-tool modules.
This patch adds /usr/share/vdsm to vdsm-tool's PYTHONPATH, and use
vdsm.utils.execCmd as the "official" implementation for all the modules
in vdsm-tool.
Change-Id: I8ca64ec5dbfebe5c5090ec8fac46785a538b79d3
Signed-off-by: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
---
M .gitignore
M lib/vdsm/tool/load_needed_modules.py.in
M lib/vdsm/tool/validate_ovirt_certs.py.in
M vdsm-tool/Makefile.am
A vdsm-tool/vdsm-tool.in
R vdsm-tool/vdsm-tool.py
M vdsm.spec.in
7 files changed, 39 insertions(+), 19 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/17/13917/1
diff --git a/.gitignore b/.gitignore
index 9fcf158..15f3eee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@
tests/run_tests_local.sh
vds_bootstrap/deployUtil.py*
vdsm-*.tar.gz
+vdsm-tool/vdsm-tool
vdsm.spec
vdsm/dsaversion.py
vdsm/dumpStorageTable.py
diff --git a/lib/vdsm/tool/load_needed_modules.py.in
b/lib/vdsm/tool/load_needed_modules.py.in
index 400ff1f..b59f0ae 100644
--- a/lib/vdsm/tool/load_needed_modules.py.in
+++ b/lib/vdsm/tool/load_needed_modules.py.in
@@ -17,10 +17,8 @@
# Refer to the README and COPYING files for full details of the license
#
-
-import subprocess
-
from vdsm.tool import expose
+from vdsm.utils import execCmd
EX_MODPROBE = '@MODPROBE_PATH@'
@@ -30,11 +28,7 @@
"""
This function executes a given shell command.
"""
-
- p = subprocess.Popen(argv, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- out, err = p.communicate()
- rc = p.returncode
+ rc, out, err = execCmd(argv, raw=True)
if rc != 0:
raise Exception("Execute command %s failed: %s" % (argv, err))
diff --git a/lib/vdsm/tool/validate_ovirt_certs.py.in
b/lib/vdsm/tool/validate_ovirt_certs.py.in
index 20569e4..2d99386 100644
--- a/lib/vdsm/tool/validate_ovirt_certs.py.in
+++ b/lib/vdsm/tool/validate_ovirt_certs.py.in
@@ -20,9 +20,9 @@
import os
import pwd
import shutil
-import subprocess
from vdsm.tool import expose
+from vdsm.utils import execCmd
try:
from ovirtnode import ovirtfunctions
@@ -39,8 +39,7 @@
def is_our_cafile(cacert):
cmd = [EX_OPENSSL, 'verify', '-CAfile', cacert, PATH_VDSMCERT]
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out = p.communicate()[0]
+ rc, out, err = execCmd(cmd, raw=True)
return out.rstrip('\n') == '%s: OK' % PATH_VDSMCERT
diff --git a/vdsm-tool/Makefile.am b/vdsm-tool/Makefile.am
index 7be6ec9..180d35a 100644
--- a/vdsm-tool/Makefile.am
+++ b/vdsm-tool/Makefile.am
@@ -19,5 +19,23 @@
include $(top_srcdir)/build-aux/Makefile.subs
-dist_bin_SCRIPTS = \
- vdsm-tool
+nodist_bin_SCRIPTS = \
+ vdsm-tool \
+ $(NULL)
+
+dist_vdsm_PYTHON = \
+ vdsm-tool.py \
+ $(NULL)
+
+EXTRA_DIST = \
+ vdsm-tool.in \
+ $(NULL)
+
+CLEANFILES = \
+ config.log \
+ $(nodist_bin_SCRIPTS) \
+ $(NULL)
+
+all-local: \
+ $(nodist_bin_SCRIPTS) \
+ $(NULL)
diff --git a/vdsm-tool/vdsm-tool.in b/vdsm-tool/vdsm-tool.in
new file mode 100755
index 0000000..f1a1ed6
--- /dev/null
+++ b/vdsm-tool/vdsm-tool.in
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+TOOL="@VDSMDIR(a)/vdsm-tool.py"
+[ -e "$TOOL" ] || TOOL="$TOOL"c
+
+[ -n "$PYTHONPATH" ] && PYTHON_FORMATTED_PATH=":$PYTHONPATH"
+PYTHONPATH="@VDSMDIR@$PYTHON_FORMATTED_PATH" python "$TOOL"
"$@"
diff --git a/vdsm-tool/vdsm-tool b/vdsm-tool/vdsm-tool.py
similarity index 91%
rename from vdsm-tool/vdsm-tool
rename to vdsm-tool/vdsm-tool.py
index 9f75a06..cb51299 100755
--- a/vdsm-tool/vdsm-tool
+++ b/vdsm-tool/vdsm-tool.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
# Copyright 2011 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
@@ -82,9 +81,10 @@
cmd_name = cmd._vdsm_tool["name"]
if cmd_name in tool_command:
- print textwrap.fill(ERROR_SAME_COMMAND %
- (cmd_name, mod_name,
- tool_command[cmd_name]["module"].__name__))
+ print textwrap.fill(
+ ERROR_SAME_COMMAND %
+ (cmd_name, mod_name,
+ tool_command[cmd_name]["module"].__name__))
continue
tool_command[cmd_name] = {"module": module, "command":
cmd}
mod_cmds.append((cmd_name, cmd.__doc__))
@@ -97,7 +97,7 @@
cmd_indent = " " * len(cmd_help)
print textwrap.fill(cmd_docs, initial_indent=cmd_help,
- subsequent_indent=cmd_indent)
+ subsequent_indent=cmd_indent)
def _usage_module(mod_name, mod_desc):
@@ -109,7 +109,7 @@
def usage_and_exit(exit_code):
- print "Usage: %s [options] <action> [arguments]\n" % sys.argv[0]
+ print "Usage: vdsm-tool [options] <action> [arguments]\n"
print "Valid options:"
print " -h, --help"
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 658de19..71567f3 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -753,6 +753,7 @@
%{_datadir}/%{vdsm_name}/vdsm
%{_datadir}/%{vdsm_name}/vdsm-restore-net-config
%{_datadir}/%{vdsm_name}/vdsm-store-net-config
+%{_datadir}/%{vdsm_name}/vdsm-tool.py*
%{_datadir}/%{vdsm_name}/vm.py*
%{_datadir}/%{vdsm_name}/write-net-config
%{_datadir}/%{vdsm_name}/zombieReaper.py*
--
To view, visit
http://gerrit.ovirt.org/13917
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8ca64ec5dbfebe5c5090ec8fac46785a538b79d3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>