Change in vdsm[master]: trivial: Using 'bonding/slaves' to get bonding's slaves
by wudxw@linux.vnet.ibm.com
Mark Wu has uploaded a new change for review.
Change subject: trivial: Using 'bonding/slaves' to get bonding's slaves
......................................................................
trivial: Using 'bonding/slaves' to get bonding's slaves
Compared with using glob, it could make the code simple and clean.
Change-Id: I87d25636685f75b8c429860a041494698febead0
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
M lib/vdsm/netinfo.py
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/06/13506/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 03ea1e5..25bcae0 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -108,8 +108,8 @@
def slaves(bonding):
- return [b.split('/')[-1].split('_', 1)[-1] for b in
- glob.glob('/sys/class/net/' + bonding + '/slave_*')]
+ return file('/sys/class/net/' + bonding +
+ '/bonding/slaves').readline().split()
def ports(bridge):
--
To view, visit http://gerrit.ovirt.org/13506
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I87d25636685f75b8c429860a041494698febead0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw(a)linux.vnet.ibm.com>
10 years, 5 months
Change in vdsm[master]: vdsmapi: vdsmapi support for gluster vdsm verbs
by avishwan@redhat.com
Aravinda VK has uploaded a new change for review.
Change subject: vdsmapi: vdsmapi support for gluster vdsm verbs
......................................................................
vdsmapi: vdsmapi support for gluster vdsm verbs
Reads vdsmapi-gluster-schema.json from gluster directory if
vdsm-gluster is installed.
Change-Id: Id10b51a41d103afcf81cb76c460f3b9821238317
Signed-off-by: Aravinda VK <avishwan(a)redhat.com>
---
M vdsm.spec.in
M vdsm/gluster/Makefile.am
A vdsm/gluster/vdsmapi-gluster-schema.json
M vdsm_api/vdsmapi.py
4 files changed, 27 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/21/13921/1
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 658de19..4f26c94 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1160,6 +1160,7 @@
%dir %{_datadir}/%{vdsm_name}/gluster
%doc COPYING
%{_datadir}/%{vdsm_name}/gluster/api.py*
+%{_datadir}/%{vdsm_name}/gluster/vdsmapi-gluster-schema.json
%endif
%changelog
diff --git a/vdsm/gluster/Makefile.am b/vdsm/gluster/Makefile.am
index abecfff..2dd3933 100644
--- a/vdsm/gluster/Makefile.am
+++ b/vdsm/gluster/Makefile.am
@@ -27,3 +27,7 @@
cli.py \
exception.py \
hostname.py
+
+dist_vdsmgluster_DATA = \
+ vdsmapi-gluster-schema.json \
+ $(NULL)
diff --git a/vdsm/gluster/vdsmapi-gluster-schema.json b/vdsm/gluster/vdsmapi-gluster-schema.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vdsm/gluster/vdsmapi-gluster-schema.json
diff --git a/vdsm_api/vdsmapi.py b/vdsm_api/vdsmapi.py
index f154e99..7c190a3 100644
--- a/vdsm_api/vdsmapi.py
+++ b/vdsm_api/vdsmapi.py
@@ -127,6 +127,19 @@
localpath, installedpath)
+def find_gluster_schema():
+ """
+ Find the API schema file in gluster dir
+ from an installed location
+ """
+ installedpath = os.path.join(constants.P_VDSM, 'gluster')
+ path = os.path.join(installedpath, 'vdsmapi-gluster-schema.json')
+ if os.access(path, os.R_OK):
+ return path
+ else:
+ return None
+
+
_api_info = None
@@ -177,13 +190,22 @@
to which the source type may be cast.
"""
global _api_info
+ gluster_schema = None
info_key = schema
if schema is None:
schema = find_schema()
+ gluster_schema = find_gluster_schema()
+
with open(schema) as f:
symbols = parse_schema(f)
+ # If gluster schema file present inside gluster directory then read and
+ # parse, append to symbols
+ if gluster_schema:
+ with open(gluster_schema) as f:
+ symbols += parse_schema(f)
+
info = {'types': {}, 'enums': {}, 'aliases': {}, 'maps': {},
'commands': {}, 'unions': {}}
--
To view, visit http://gerrit.ovirt.org/13921
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id10b51a41d103afcf81cb76c460f3b9821238317
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Aravinda VK <avishwan(a)redhat.com>
10 years, 5 months
Change in vdsm[master]: vdsm.spec.in: update raw_version_revision
by Douglas Schilling Landgraf
Douglas Schilling Landgraf has uploaded a new change for review.
Change subject: vdsm.spec.in: update raw_version_revision
......................................................................
vdsm.spec.in: update raw_version_revision
The raw_version_revision from dsaversion.py should be updated with the
version/release of RPM removing the git stuff.
Change-Id: I8dc1e514ef8fd626018167e1dd13bc58100d5d7b
Signed-off-by: Douglas Schilling Landgraf <dougsland(a)redhat.com>
---
M vdsm.spec.in
1 file changed, 2 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/11/14011/1
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 7db32b3..a22976f 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -493,7 +493,9 @@
# Setting software_version and software_revision in dsaversion.py
baserelease=`echo "%{release}" | sed 's/\([0-9]\+\(\.[0-9]\+\)\?\).*/\1/'`
baseversion=`echo "%{version}" | sed 's/\([0-9]\+\(\.[0-9]\+\)\?\).*/\1/'`
+fullversion=%{version}.${baserelease}
sed -i -e 's/^software_version =.*/software_version = "'"${baseversion}"'"/' \
+ -e 's/^raw_version_revision =.*/raw_version_revision = "'"${fullversion}"'"/' \
-e 's/^software_revision =.*/software_revision = "'"${baserelease}"'"/' vdsm/dsaversion.py
%install
--
To view, visit http://gerrit.ovirt.org/14011
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8dc1e514ef8fd626018167e1dd13bc58100d5d7b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland(a)redhat.com>
10 years, 5 months
Change in vdsm[master]: vdsmd.init.in: simplify system services management by using ...
by zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has uploaded a new change for review.
Change subject: vdsmd.init.in: simplify system services management by using vdsm-tool
......................................................................
vdsmd.init.in: simplify system services management by using vdsm-tool
In vdsm-tool there is a module implemented the service management
utilities that covers systemd, upstart and sysv.
Change-Id: I57a89d969b8ff4eba57daa893dc29840358c30e7
Signed-off-by: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
---
M vdsm/vdsmd.init.in
1 file changed, 9 insertions(+), 50 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/02/13702/1
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index c804ce8..b1ed4ff 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -122,21 +122,17 @@
for srv in $CONFLICTING_SERVICES
do
- /sbin/chkconfig $srv off
- if /sbin/service $srv status > /dev/null 2>&1;
+ /usr/bin/vdsm-tool service_disable $srv
+ if /usr/bin/vdsm-tool service_status $srv > /dev/null 2>&1;
then
if [ "$srv" == "libvirt-guests" ]; then
/bin/rm -f /var/lock/subsys/libvirt-guests
else
- /sbin/service $srv stop
+ /usr/bin/vdsm-tool service_stop $srv
fi
fi
done
return 0
-}
-
-libvirt_should_use_upstart() {
- [[ -x /sbin/initctl ]]
}
start_needed_srv() {
@@ -145,10 +141,10 @@
for srv in $NEEDED_SERVICES
do
- if ! /sbin/service $srv status > /dev/null 2>&1;
+ if ! /usr/bin/vdsm-tool service_status $srv > /dev/null 2>&1;
then
echo "Starting $srv..."
- /sbin/service $srv start
+ /usr/bin/vdsm-tool service_start $srv
ret_val=$?
if [ $ret_val -ne 0 ]
then
@@ -157,8 +153,6 @@
fi
fi
done
-
- /sbin/service iscsid force-start
}
test_lo() {
@@ -362,11 +356,7 @@
ovirt_store_config "$lconf" "$qconf" "$ldconf" "$llogr"
- if libvirt_should_use_upstart; then
- /sbin/initctl restart libvirtd 2>/dev/null || :
- else
- /bin/systemctl restart libvirtd.service
- fi
+ /usr/bin/vdsm-tool service_restart libvirtd
#
# finished reconfiguration, do not trigger
@@ -394,41 +384,10 @@
configure_libvirt $args
}
-stop_libvirtd_sysv() {
- # stop libvirt SysV service if we intend to configure upstart
-
- if libvirt_should_use_upstart && ! [[ -f /etc/init/libvirtd.conf ]]; then
- /sbin/chkconfig libvirtd off
- /sbin/service libvirtd stop
- fi
-}
-
start_libvirtd() {
- local packaged target
- local startout
-
- if ! libvirt_should_use_upstart; then
- /sbin/service libvirtd start
- return
- fi
-
- packaged=`/bin/rpm -ql libvirt libvirt-daemon | \
- /bin/grep libvirtd.upstart | /usr/bin/tail -1`
- target=/etc/init/libvirtd.conf
-
- if [[ -f "$packaged" ]] && ! diff -q "$packaged" "$target" >/dev/null;
+ if ! /usr/bin/vdsm-tool service_status libvirtd > /dev/null 2>&1;
then
- /bin/cp -p "$packaged" "$target" || return 1
- /sbin/initctl reload-configuration
- fi
-
- startout=`/sbin/initctl start libvirtd 2>&1`
- if [[ "$?" -eq 0 || "$startout" =~ .*already\ running.* ]];
- then
- return 0
- else
- echo "$startout" >&2
- return 1
+ /usr/bin/vdsm-tool service_start libvirtd
fi
}
@@ -441,7 +400,7 @@
local ret_val
python @VDSMDIR(a)/hooks.pyc before_vdsm_start
- shutdown_conflicting_srv && stop_libvirtd_sysv
+ shutdown_conflicting_srv
if ! @LIBEXECDIR(a)/vdsm-gencerts.sh --check; then
echo -n $"Configuring a self-signed VDSM host certificate: "
--
To view, visit http://gerrit.ovirt.org/13702
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I57a89d969b8ff4eba57daa893dc29840358c30e7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
10 years, 5 months
Change in vdsm[master]: vdsm-tool: add service management utilities
by zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has uploaded a new change for review.
Change subject: vdsm-tool: add service management utilities
......................................................................
vdsm-tool: add service management utilities
Change-Id: Idd1cbcf5fd00bb1ec73c5970be012e294b3b4c55
Signed-off-by: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
---
M lib/vdsm/tool/Makefile.am
A lib/vdsm/tool/service.py
M vdsm.spec.in
3 files changed, 277 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/01/13701/1
diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am
index 49c067c..31704cc 100644
--- a/lib/vdsm/tool/Makefile.am
+++ b/lib/vdsm/tool/Makefile.am
@@ -33,4 +33,5 @@
__init__.py \
passwd.py \
seboolsetup.py \
+ service.py
$(NULL)
diff --git a/lib/vdsm/tool/service.py b/lib/vdsm/tool/service.py
new file mode 100644
index 0000000..c7d705c
--- /dev/null
+++ b/lib/vdsm/tool/service.py
@@ -0,0 +1,275 @@
+# Copyright 2013 IBM, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+'''
+System service management utlities.
+'''
+
+import os
+import subprocess
+import functools
+import re
+
+from vdsm.tool import expose
+from vdsm.utils import CommandPath
+
+
+def execCmd(argv):
+ p = subprocess.Popen(argv, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ rc = p.returncode
+ return (rc, out, err)
+
+
+_SYSTEMCTL = CommandPath("systemctl",
+ "/bin/systemctl",
+ "/usr/bin/systemctl",
+ )
+
+_INITCTL = CommandPath("initctl",
+ "/sbin/initctl",
+ )
+
+_SERVICE = CommandPath("service",
+ "/sbin/service",
+ "/usr/sbin/service",
+ )
+
+_CHKCONFIG = CommandPath("chkconfig",
+ "/sbin/chkconfig",
+ )
+
+_UPDATERC = CommandPath("update-rc.d",
+ "/usr/sbin/update-rc.d",
+ )
+
+_srvStartAlts = []
+_srvStopAlts = []
+_srvStatusAlts = []
+_srvRestartAlts = []
+_srvDisableAlts = []
+
+try:
+ _SYSTEMCTL.cmd
+except OSError:
+ pass
+else:
+ def _systemctlNative(systemctlFun):
+ @functools.wraps(systemctlFun)
+ def wrapper(srvName):
+ cmd = [_SYSTEMCTL.cmd, "--no-pager", "list-unit-files"]
+ rc, out, err = execCmd(cmd)
+ if rc != 0:
+ return (rc, out, err)
+ lines = out.splitlines()
+ for line in lines:
+ if srvName + ".service" == line.split(" ", 1):
+ return systemctlFun(srvName)
+ return (1, "", "%s is not native systemctl service")
+ return wrapper
+
+ @_systemctlNative
+ def _systemctlStart(srvName):
+ cmd = [_SYSTEMCTL.cmd, "start", srvName]
+ return execCmd(cmd)
+
+ @_systemctlNative
+ def _systemctlStop(srvName):
+ cmd = [_SYSTEMCTL.cmd, "stop", srvName]
+ return execCmd(cmd)
+
+ @_systemctlNative
+ def _systemctlStatus(srvName):
+ cmd = [_SYSTEMCTL.cmd, "status", srvName]
+ return execCmd(cmd)
+
+ @_systemctlNative
+ def _systemctlRestart(srvName):
+ cmd = [_SYSTEMCTL.cmd, "restart", srvName]
+ return execCmd(cmd)
+
+ @_systemctlNative
+ def _systemctlDisable(srvName):
+ cmd = [_SYSTEMCTL.cmd, "disable", srvName]
+ return execCmd(cmd)
+
+ _srvStartAlts.append(_systemctlStart)
+ _srvStopAlts.append(_systemctlStop)
+ _srvStatusAlts.append(_systemctlStatus)
+ _srvRestartAlts.append(_systemctlRestart)
+ _srvDisableAlts.append(_systemctlDisable)
+
+
+def _isStopped(message):
+ stopRegex = r"\Wstopped\W|\Wstop\W|\Wwaiting\W|\Wnot running\W"
+ return re.search(stopRegex, message, re.MULTILINE) is not None
+
+try:
+ _INITCTL.cmd
+except OSError:
+ pass
+else:
+ def _initctlStart(srvName):
+ cmd = [_INITCTL.cmd, "start", srvName]
+ return execCmd(cmd)
+
+ def _initctlStop(srvName):
+ cmd = [_INITCTL.cmd, "stop", srvName]
+ return execCmd(cmd)
+
+ def _initctlStatus(srvName):
+ cmd = [_INITCTL.cmd, "status", srvName]
+ rc, out, err = execCmd(cmd)
+ if rc == 0:
+ # initctl rc is 0 even though the service is stopped
+ rc = _isStopped(out)
+ return (rc, out, err)
+
+ def _initctlRestart(srvName):
+ cmd = [_INITCTL.cmd, "restart", srvName]
+ return execCmd(cmd)
+
+ def _initctlDisable(srvName):
+ if not os.path.isfile("/etc/init/%s.conf" % srvName):
+ return 1, "", ""
+ with open("/etc/init/%s.override" % srvName, "a") as f:
+ f.write("manual\n")
+ return 0, "", ""
+
+ _srvStartAlts.append(_initctlStart)
+ _srvStopAlts.append(_initctlStop)
+ _srvStatusAlts.append(_initctlStatus)
+ _srvRestartAlts.append(_initctlRestart)
+ _srvDisableAlts.append(_initctlDisable)
+
+
+try:
+ _SERVICE.cmd
+except OSError:
+ pass
+else:
+ def _serviceStart(srvName):
+ cmd = [_SERVICE.cmd, srvName, "start"]
+ return execCmd(cmd)
+
+ def _serviceStop(srvName):
+ cmd = [_SERVICE.cmd, srvName, "stop"]
+ return execCmd(cmd)
+
+ def _serviceStatus(srvName):
+ cmd = [_SERVICE.cmd, srvName, "status"]
+ rc, out, err = execCmd(cmd)
+ if rc == 0:
+ # certain service rc is 0 even though the service is stopped
+ rc = _isStopped(out)
+ return (rc, out, err)
+
+ def _serviceRestart(srvName):
+ cmd = [_SERVICE.cmd, srvName, "restart"]
+ return execCmd(cmd)
+
+ _srvStartAlts.append(_serviceStart)
+ _srvStopAlts.append(_serviceStop)
+ _srvRestartAlts.append(_serviceRestart)
+ _srvStatusAlts.append(_serviceStatus)
+
+
+try:
+ _CHKCONFIG.cmd
+except OSError:
+ pass
+else:
+ def _chkconfigDisable(srvName):
+ cmd = [_CHKCONFIG.cmd, srvName, "off"]
+ return execCmd(cmd)
+
+ _srvDisableAlts.append(_chkconfigDisable)
+
+
+try:
+ _UPDATERC.cmd
+except OSError:
+ pass
+else:
+ def _updatercDisable(srvName):
+ cmd = [_UPDATERC.cmd, srvName, "disable"]
+ return execCmd(cmd)
+
+ _srvDisableAlts.append(_updatercDisable)
+
+
+def _runAlts(alts, *args, **kwarg):
+ errors = {}
+ for alt in alts:
+ try:
+ rc, out, err = alt(*args, **kwarg)
+ except Exception as e:
+ errors[alt.func_name] = e
+ else:
+ if rc == 0:
+ return
+ else:
+ errors[alt.func_name] = (rc, out, err)
+ raise RuntimeError("Tried all alternatives but failed:\n%s" % errors)
+
+
+@expose("service_start")
+def service_start(srvName):
+ """
+ Start a system service
+ """
+ _runAlts(_srvStartAlts, srvName)
+ return 0
+
+
+@expose("service_stop")
+def service_stop(srvName):
+ """
+ Stop a system service
+ """
+ _runAlts(_srvStopAlts, srvName)
+ return 0
+
+
+@expose("service_status")
+def service_status(srvName):
+ """
+ Get status of a system service
+ """
+ _runAlts(_srvStatusAlts, srvName)
+ return 0
+
+
+@expose("service_restart")
+def service_restart(srvName):
+ """
+ Get status of a system service
+ """
+ _runAlts(_srvRestartAlts, srvName)
+ return 0
+
+
+@expose("service_disable")
+def service_disable(srvName):
+ """
+ Disable a system service
+ """
+ _runAlts(_srvDisableAlts, srvName)
+ return 0
diff --git a/vdsm.spec.in b/vdsm.spec.in
index da2546f..4350140 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -900,6 +900,7 @@
%endif
%{python_sitearch}/%{vdsm_name}/tool/passwd.py*
%{python_sitearch}/%{vdsm_name}/tool/seboolsetup.py*
+%{python_sitearch}/%{vdsm_name}/tool/service.py*
%{python_sitearch}/%{vdsm_name}/tool/validate_ovirt_certs.py*
%files tests
--
To view, visit http://gerrit.ovirt.org/13701
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd1cbcf5fd00bb1ec73c5970be012e294b3b4c55
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
10 years, 5 months
Change in vdsm[master]: vdsm-tool: unify ad-hoc execCmd implementations
by zhshzhou@linux.vnet.ibm.com
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>
10 years, 5 months
Change in vdsm[master]: storage.misc: Move execCmd and its dependencies to vdsm.util...
by zhshzhou@linux.vnet.ibm.com
Zhou Zheng Sheng has uploaded a new change for review.
Change subject: storage.misc: Move execCmd and its dependencies to vdsm.utils
......................................................................
storage.misc: Move execCmd and its dependencies to vdsm.utils
The original vdsm.utils.execCmd actually imports and invokes
storage.misc.execCmd, which means if a process does not have
/usr/share/vdsm in its PYTHONPATH and want to use vdsm.utils.execCmd, it
will fail. Furthermore, lib/vdsm/utils.py should not use anything that
is not present in the python standard library or in a dependency of the
vdsm-python package.
execCmd is very useful for modules in vdsm-tool, currently these modules
use ad-hoc execCmd implementation. This patch moves storage.misc.execCmd
and its dependencies to vdsm.utils, so that other modules can import the
'official' execCmd implementation without adding /usr/share/vdsm to
PYTHONPATH.
Change-Id: Id8fb42035b24bc915aaa700ab128580bdb609d9e
Signed-off-by: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
---
M lib/vdsm/utils.py
M vdsm/storage/misc.py
2 files changed, 314 insertions(+), 314 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/21/14221/1
diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index e398a7e..cfec8cc 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -27,22 +27,35 @@
Contains a reverse dictionary pointing from error string to its error code.
"""
from SimpleXMLRPCServer import SimpleXMLRPCServer
+from StringIO import StringIO
+from weakref import proxy
import SocketServer
-import threading
-import os
-import time
-import logging
import errno
-import subprocess
-import pwd
import fcntl
import functools
-import stat
import glob
+import io
+import logging
+import os
+import pwd
+import select
+import signal
+import stat
+import subprocess
+import threading
+import time
-import constants
+from betterPopen import BetterPopen
from config import config
+import constants
+
+# Buffsize is 1K because I tested it on some use cases and 1k was fastets. If
+# you find this number to be a bottleneck in any way you are welcome to change
+# it
+BUFFSIZE = 1024
+
+SUDO_NON_INTERACTIVE_FLAG = "-n"
_THP_STATE_PATH = '/sys/kernel/mm/transparent_hugepage/enabled'
if not os.path.exists(_THP_STATE_PATH):
@@ -147,10 +160,296 @@
return val
-def execCmd(*args, **kwargs):
- # import only after config as been initialized
- from storage.misc import execCmd
- return execCmd(*args, **kwargs)
+# NOTE: it would be best to try and unify NoIntrCall and NoIntrPoll.
+# We could do so defining a new object that can be used as a placeholer
+# for the changing timeout value in the *args/**kwargs. This would
+# lead us to rebuilding the function arguments at each loop.
+def NoIntrPoll(pollfun, timeout=-1):
+ """
+ This wrapper is used to handle the interrupt exceptions that might
+ occur during a poll system call. The wrapped function must be defined
+ as poll([timeout]) where the special timeout value 0 is used to return
+ immediately and -1 is used to wait indefinitely.
+ """
+ # When the timeout < 0 we shouldn't compute a new timeout after an
+ # interruption.
+ endtime = None if timeout < 0 else time.time() + timeout
+
+ while True:
+ try:
+ return pollfun(timeout)
+ except (IOError, select.error) as e:
+ if e.args[0] != errno.EINTR:
+ raise
+
+ if endtime is not None:
+ timeout = max(0, endtime - time.time())
+
+
+class AsyncProc(object):
+ """
+ AsyncProc is a funky class. It warps a standard subprocess.Popen
+ Object and gives it super powers. Like the power to read from a stream
+ without the fear of deadlock. It does this by always sampling all
+ stream while waiting for data. By doing this the other process can freely
+ write data to all stream without the fear of it getting stuck writing
+ to a full pipe.
+ """
+ class _streamWrapper(io.RawIOBase):
+ def __init__(self, parent, streamToWrap, fd):
+ io.IOBase.__init__(self)
+ self._stream = streamToWrap
+ self._parent = proxy(parent)
+ self._fd = fd
+ self._closed = False
+ self._emptyCounter = 0
+
+ def close(self):
+ if not self._closed:
+ self._closed = True
+ while not self._streamClosed:
+ self._parent._processStreams()
+
+ @property
+ def closed(self):
+ return self._closed
+
+ @property
+ def _streamClosed(self):
+ return (self.fileno() in self._parent._closedfds)
+
+ def fileno(self):
+ return self._fd
+
+ def seekable(self):
+ return False
+
+ def readable(self):
+ return True
+
+ def writable(self):
+ return True
+
+ def read(self, length):
+ hasNewData = (self._stream.len - self._stream.pos)
+ if hasNewData < length and not self._streamClosed:
+ self._parent._processStreams()
+
+ with self._parent._streamLock:
+ res = self._stream.read(length)
+ if self._stream.pos == self._stream.len:
+ if self._streamClosed and res == "":
+ self._emptyCounter += 1
+ if self._emptyCounter > 2:
+ self._closed = True
+
+ self._stream.truncate(0)
+
+ return res
+
+ def readinto(self, b):
+ data = self.read(len(b))
+ bytesRead = len(data)
+ b[:bytesRead] = data
+
+ return bytesRead
+
+ def write(self, data):
+ if hasattr(data, "tobytes"):
+ data = data.tobytes()
+ with self._parent._streamLock:
+ oldPos = self._stream.pos
+ self._stream.pos = self._stream.len
+ self._stream.write(data)
+ self._stream.pos = oldPos
+
+ while self._stream.len > 0 and not self._streamClosed:
+ self._parent._processStreams()
+
+ if self._streamClosed:
+ self._closed = True
+
+ if self._stream.len != 0:
+ raise IOError(errno.EPIPE,
+ "Could not write all data to stream")
+
+ return len(data)
+
+ def __init__(self, popenToWrap):
+ self._streamLock = threading.Lock()
+ self._proc = popenToWrap
+
+ self._stdout = StringIO()
+ self._stderr = StringIO()
+ self._stdin = StringIO()
+
+ fdout = self._proc.stdout.fileno()
+ fderr = self._proc.stderr.fileno()
+ self._fdin = self._proc.stdin.fileno()
+
+ self._closedfds = []
+
+ self._poller = select.epoll()
+ self._poller.register(fdout, select.EPOLLIN | select.EPOLLPRI)
+ self._poller.register(fderr, select.EPOLLIN | select.EPOLLPRI)
+ self._poller.register(self._fdin, 0)
+ self._fdMap = {fdout: self._stdout,
+ fderr: self._stderr,
+ self._fdin: self._stdin}
+
+ self.stdout = io.BufferedReader(self._streamWrapper(self,
+ self._stdout, fdout), BUFFSIZE)
+
+ self.stderr = io.BufferedReader(self._streamWrapper(self,
+ self._stderr, fderr), BUFFSIZE)
+
+ self.stdin = io.BufferedWriter(self._streamWrapper(self,
+ self._stdin, self._fdin), BUFFSIZE)
+
+ self._returncode = None
+
+ def _processStreams(self):
+ if len(self._closedfds) == 3:
+ return
+
+ if not self._streamLock.acquire(False):
+ self._streamLock.acquire()
+ self._streamLock.release()
+ return
+ try:
+ if self._stdin.len > 0 and self._stdin.pos == 0:
+ # Polling stdin is redundant if there is nothing to write
+ # trun on only if data is waiting to be pushed
+ self._poller.modify(self._fdin, select.EPOLLOUT)
+
+ pollres = NoIntrPoll(self._poller.poll, 1)
+
+ for fd, event in pollres:
+ stream = self._fdMap[fd]
+ if event & select.EPOLLOUT and self._stdin.len > 0:
+ buff = self._stdin.read(BUFFSIZE)
+ written = os.write(fd, buff)
+ stream.pos -= len(buff) - written
+ if stream.pos == stream.len:
+ stream.truncate(0)
+ self._poller.modify(fd, 0)
+
+ elif event & (select.EPOLLIN | select.EPOLLPRI):
+ data = os.read(fd, BUFFSIZE)
+ oldpos = stream.pos
+ stream.pos = stream.len
+ stream.write(data)
+ stream.pos = oldpos
+
+ elif event & (select.EPOLLHUP | select.EPOLLERR):
+ self._poller.unregister(fd)
+ self._closedfds.append(fd)
+ # I don't close the fd because the original Popen
+ # will do it.
+
+ if self.stdin.closed and self._fdin not in self._closedfds:
+ self._poller.unregister(self._fdin)
+ self._closedfds.append(self._fdin)
+ self._proc.stdin.close()
+
+ finally:
+ self._streamLock.release()
+
+ @property
+ def pid(self):
+ return self._proc.pid
+
+ @property
+ def returncode(self):
+ if self._returncode is None:
+ self._returncode = self._proc.poll()
+ return self._returncode
+
+ def kill(self):
+ try:
+ self._proc.kill()
+ except OSError as ex:
+ if ex.errno != errno.EPERM:
+ raise
+ execCmd([constants.EXT_KILL, "-%d" % (signal.SIGTERM,),
+ str(self.pid)], sudo=True)
+
+ def wait(self, timeout=None, cond=None):
+ startTime = time.time()
+ while self.returncode is None:
+ if timeout is not None and (time.time() - startTime) > timeout:
+ return False
+ if cond is not None and cond():
+ return False
+ self._processStreams()
+ return True
+
+ def communicate(self, data=None):
+ if data is not None:
+ self.stdin.write(data)
+ self.stdin.flush()
+ self.stdin.close()
+
+ self.wait()
+ return "".join(self.stdout), "".join(self.stderr)
+
+ def __del__(self):
+ self._poller.close()
+
+
+def execCmd(command, sudo=False, cwd=None, data=None, raw=False, logErr=True,
+ printable=None, env=None, sync=True, nice=None, ioclass=None,
+ ioclassdata=None, setsid=False, execCmdLogger=logging.root):
+ """
+ Executes an external command, optionally via sudo.
+ """
+ if ioclass is not None:
+ cmd = command
+ command = [constants.EXT_IONICE, '-c', str(ioclass)]
+ if ioclassdata is not None:
+ command.extend(("-n", str(ioclassdata)))
+
+ command = command + cmd
+
+ if nice is not None:
+ command = [constants.EXT_NICE, '-n', str(nice)] + command
+
+ if setsid:
+ command = [constants.EXT_SETSID] + command
+
+ if sudo:
+ command = [constants.EXT_SUDO, SUDO_NON_INTERACTIVE_FLAG] + command
+
+ if not printable:
+ printable = command
+
+ cmdline = repr(subprocess.list2cmdline(printable))
+ execCmdLogger.debug("%s (cwd %s)", cmdline, cwd)
+
+ p = BetterPopen(command, close_fds=True, cwd=cwd, env=env)
+ p = AsyncProc(p)
+ if not sync:
+ if data is not None:
+ p.stdin.write(data)
+ p.stdin.flush()
+
+ return p
+
+ (out, err) = p.communicate(data)
+
+ if out is None:
+ # Prevent splitlines() from barfing later on
+ out = ""
+
+ execCmdLogger.debug("%s: <err> = %s; <rc> = %d",
+ {True: "SUCCESS", False: "FAILED"}[p.returncode == 0],
+ repr(err), p.returncode)
+
+ if not raw:
+ out = out.splitlines(False)
+ err = err.splitlines(False)
+
+ return (p.returncode, out, err)
def checkPathStat(pathToCheck):
diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py
index ae92b75..bee9daa 100644
--- a/vdsm/storage/misc.py
+++ b/vdsm/storage/misc.py
@@ -31,25 +31,19 @@
from contextlib import contextmanager
from functools import wraps, partial
from itertools import chain, imap
-from StringIO import StringIO
-from weakref import proxy
import contextlib
import errno
import glob
-import io
import logging
import os
import Queue
import random
import re
import select
-import signal
import string
import struct
-import subprocess
import sys
import threading
-import time
import types
import weakref
import fcntl
@@ -58,7 +52,6 @@
from vdsm import constants
from vdsm import utils
import storage_exception as se
-from betterPopen import BetterPopen
import fileUtils
import logUtils
@@ -70,7 +63,6 @@
UUID_HYPHENS = [8, 13, 18, 23]
OVIRT_NODE = False
MEGA = 1 << 20
-SUDO_NON_INTERACTIVE_FLAG = "-n"
UNLIMITED_THREADS = -1
log = logging.getLogger('Storage.Misc')
@@ -86,11 +78,6 @@
logger, logger.__class__)
return logger
-
-# Buffsize is 1K because I tested it on some use cases and 1k was fastets. If
-# you find this number to be a bottleneck in any way you are welcome to change
-# it
-BUFFSIZE = 1024
def stripNewLines(lines):
@@ -193,60 +180,8 @@
LOW = 19
-@logskip("Storage.Misc.excCmd")
-def execCmd(command, sudo=False, cwd=None, data=None, raw=False, logErr=True,
- printable=None, env=None, sync=True, nice=None, ioclass=None,
- ioclassdata=None, setsid=False):
- """
- Executes an external command, optionally via sudo.
- """
- if ioclass is not None:
- cmd = command
- command = [constants.EXT_IONICE, '-c', str(ioclass)]
- if ioclassdata is not None:
- command.extend(("-n", str(ioclassdata)))
-
- command = command + cmd
-
- if nice is not None:
- command = [constants.EXT_NICE, '-n', str(nice)] + command
-
- if setsid:
- command = [constants.EXT_SETSID] + command
-
- if sudo:
- command = [constants.EXT_SUDO, SUDO_NON_INTERACTIVE_FLAG] + command
-
- if not printable:
- printable = command
-
- cmdline = repr(subprocess.list2cmdline(printable))
- execCmdLogger.debug("%s (cwd %s)", cmdline, cwd)
-
- p = BetterPopen(command, close_fds=True, cwd=cwd, env=env)
- p = AsyncProc(p)
- if not sync:
- if data is not None:
- p.stdin.write(data)
- p.stdin.flush()
-
- return p
-
- (out, err) = p.communicate(data)
-
- if out is None:
- # Prevent splitlines() from barfing later on
- out = ""
-
- execCmdLogger.debug("%s: <err> = %s; <rc> = %d",
- {True: "SUCCESS", False: "FAILED"}[p.returncode == 0],
- repr(err), p.returncode)
-
- if not raw:
- out = out.splitlines(False)
- err = err.splitlines(False)
-
- return (p.returncode, out, err)
+execCmd = partial(logskip("Storage.Misc.excCmd")(utils.execCmd),
+ execCmdLogger=execCmdLogger)
def pidExists(pid):
@@ -786,217 +721,6 @@
self._finally.insert(0, (func, args, kwargs))
-class AsyncProc(object):
- """
- AsyncProc is a funky class. It warps a standard subprocess.Popen
- Object and gives it super powers. Like the power to read from a stream
- without the fear of deadlock. It does this by always sampling all
- stream while waiting for data. By doing this the other process can freely
- write data to all stream without the fear of it getting stuck writing
- to a full pipe.
- """
- class _streamWrapper(io.RawIOBase):
- def __init__(self, parent, streamToWrap, fd):
- io.IOBase.__init__(self)
- self._stream = streamToWrap
- self._parent = proxy(parent)
- self._fd = fd
- self._closed = False
- self._emptyCounter = 0
-
- def close(self):
- if not self._closed:
- self._closed = True
- while not self._streamClosed:
- self._parent._processStreams()
-
- @property
- def closed(self):
- return self._closed
-
- @property
- def _streamClosed(self):
- return (self.fileno() in self._parent._closedfds)
-
- def fileno(self):
- return self._fd
-
- def seekable(self):
- return False
-
- def readable(self):
- return True
-
- def writable(self):
- return True
-
- def read(self, length):
- hasNewData = (self._stream.len - self._stream.pos)
- if hasNewData < length and not self._streamClosed:
- self._parent._processStreams()
-
- with self._parent._streamLock:
- res = self._stream.read(length)
- if self._stream.pos == self._stream.len:
- if self._streamClosed and res == "":
- self._emptyCounter += 1
- if self._emptyCounter > 2:
- self._closed = True
-
- self._stream.truncate(0)
-
- return res
-
- def readinto(self, b):
- data = self.read(len(b))
- bytesRead = len(data)
- b[:bytesRead] = data
-
- return bytesRead
-
- def write(self, data):
- if hasattr(data, "tobytes"):
- data = data.tobytes()
- with self._parent._streamLock:
- oldPos = self._stream.pos
- self._stream.pos = self._stream.len
- self._stream.write(data)
- self._stream.pos = oldPos
-
- while self._stream.len > 0 and not self._streamClosed:
- self._parent._processStreams()
-
- if self._streamClosed:
- self._closed = True
-
- if self._stream.len != 0:
- raise IOError(errno.EPIPE,
- "Could not write all data to stream")
-
- return len(data)
-
- def __init__(self, popenToWrap):
- self._streamLock = threading.Lock()
- self._proc = popenToWrap
-
- self._stdout = StringIO()
- self._stderr = StringIO()
- self._stdin = StringIO()
-
- fdout = self._proc.stdout.fileno()
- fderr = self._proc.stderr.fileno()
- self._fdin = self._proc.stdin.fileno()
-
- self._closedfds = []
-
- self._poller = select.epoll()
- self._poller.register(fdout, select.EPOLLIN | select.EPOLLPRI)
- self._poller.register(fderr, select.EPOLLIN | select.EPOLLPRI)
- self._poller.register(self._fdin, 0)
- self._fdMap = {fdout: self._stdout,
- fderr: self._stderr,
- self._fdin: self._stdin}
-
- self.stdout = io.BufferedReader(self._streamWrapper(self,
- self._stdout, fdout), BUFFSIZE)
-
- self.stderr = io.BufferedReader(self._streamWrapper(self,
- self._stderr, fderr), BUFFSIZE)
-
- self.stdin = io.BufferedWriter(self._streamWrapper(self,
- self._stdin, self._fdin), BUFFSIZE)
-
- self._returncode = None
-
- def _processStreams(self):
- if len(self._closedfds) == 3:
- return
-
- if not self._streamLock.acquire(False):
- self._streamLock.acquire()
- self._streamLock.release()
- return
- try:
- if self._stdin.len > 0 and self._stdin.pos == 0:
- # Polling stdin is redundant if there is nothing to write
- # trun on only if data is waiting to be pushed
- self._poller.modify(self._fdin, select.EPOLLOUT)
-
- pollres = NoIntrPoll(self._poller.poll, 1)
-
- for fd, event in pollres:
- stream = self._fdMap[fd]
- if event & select.EPOLLOUT and self._stdin.len > 0:
- buff = self._stdin.read(BUFFSIZE)
- written = os.write(fd, buff)
- stream.pos -= len(buff) - written
- if stream.pos == stream.len:
- stream.truncate(0)
- self._poller.modify(fd, 0)
-
- elif event & (select.EPOLLIN | select.EPOLLPRI):
- data = os.read(fd, BUFFSIZE)
- oldpos = stream.pos
- stream.pos = stream.len
- stream.write(data)
- stream.pos = oldpos
-
- elif event & (select.EPOLLHUP | select.EPOLLERR):
- self._poller.unregister(fd)
- self._closedfds.append(fd)
- # I don't close the fd because the original Popen
- # will do it.
-
- if self.stdin.closed and self._fdin not in self._closedfds:
- self._poller.unregister(self._fdin)
- self._closedfds.append(self._fdin)
- self._proc.stdin.close()
-
- finally:
- self._streamLock.release()
-
- @property
- def pid(self):
- return self._proc.pid
-
- @property
- def returncode(self):
- if self._returncode is None:
- self._returncode = self._proc.poll()
- return self._returncode
-
- def kill(self):
- try:
- self._proc.kill()
- except OSError as ex:
- if ex.errno != errno.EPERM:
- raise
- execCmd([constants.EXT_KILL, "-%d" % (signal.SIGTERM,),
- str(self.pid)], sudo=True)
-
- def wait(self, timeout=None, cond=None):
- startTime = time.time()
- while self.returncode is None:
- if timeout is not None and (time.time() - startTime) > timeout:
- return False
- if cond is not None and cond():
- return False
- self._processStreams()
- return True
-
- def communicate(self, data=None):
- if data is not None:
- self.stdin.write(data)
- self.stdin.flush()
- self.stdin.close()
-
- self.wait()
- return "".join(self.stdout), "".join(self.stderr)
-
- def __del__(self):
- self._poller.close()
-
-
class DynamicBarrier(object):
def __init__(self):
self._lock = threading.Lock()
@@ -1374,30 +1098,7 @@
break
-# NOTE: it would be best to try and unify NoIntrCall and NoIntrPoll.
-# We could do so defining a new object that can be used as a placeholer
-# for the changing timeout value in the *args/**kwargs. This would
-# lead us to rebuilding the function arguments at each loop.
-def NoIntrPoll(pollfun, timeout=-1):
- """
- This wrapper is used to handle the interrupt exceptions that might
- occur during a poll system call. The wrapped function must be defined
- as poll([timeout]) where the special timeout value 0 is used to return
- immediately and -1 is used to wait indefinitely.
- """
- # When the timeout < 0 we shouldn't compute a new timeout after an
- # interruption.
- endtime = None if timeout < 0 else time.time() + timeout
-
- while True:
- try:
- return pollfun(timeout)
- except (IOError, select.error) as e:
- if e.args[0] != errno.EINTR:
- raise
-
- if endtime is not None:
- timeout = max(0, endtime - time.time())
+NoIntrPoll = utils.NoIntrPoll
def isAscii(s):
--
To view, visit http://gerrit.ovirt.org/14221
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8fb42035b24bc915aaa700ab128580bdb609d9e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
10 years, 5 months
Change in vdsm[master]: Update device hooks:
by gvallare@redhat.com
Giuseppe Vallarelli has uploaded a new change for review.
Change subject: Update device hooks:
......................................................................
Update device hooks:
Added before and after update device hooks.
Bug-Url:https://bugzilla.redhat.com/show_bug.cgi?id=893576
Change-Id: I8fe7f5e6d8291cc227a323b324c977bcd5bc8295
Signed-off-by: Giuseppe Vallarelli <gvallare(a)redhat.com>
---
M vdsm/hooks.py
M vdsm/libvirtvm.py
M vdsm/vdsmd.8.in
M vdsm_hooks/Makefile.am
4 files changed, 46 insertions(+), 2 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/13972/1
diff --git a/vdsm/hooks.py b/vdsm/hooks.py
index c66bfef..4a5d053 100644
--- a/vdsm/hooks.py
+++ b/vdsm/hooks.py
@@ -194,6 +194,16 @@
raiseError=False, params=params)
+def before_update_device(devxml, vmconf={}, params={}):
+ return _runHooksDir(devxml, 'before_update_device', vmconf=vmconf,
+ params=params)
+
+
+def after_update_device(devxml, vmconf={}, params={}):
+ return _runHooksDir(devxml, 'after_update_device', vmconf=vmconf,
+ raiseError=False, params=params)
+
+
def before_nic_hotplug(nicxml, vmconf={}, params={}):
return _runHooksDir(nicxml, 'before_nic_hotplug', vmconf=vmconf,
params=params)
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 18ca5aa..02109ba 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -1712,11 +1712,42 @@
# Update the conf with the new mirroring.
conf['portMirroring'] = networks
+ def _get_device(self, key):
+ """
+ Retrieve nic device associated to its key (alias).
+ """
+
+ device = None
+ for nic_dev in self._devices[vm.NIC_DEVICES]:
+ if nic_dev.alias == key:
+ device = nic_dev
+ break
+ return device
+
def updateDevice(self, params):
+ update = None
if params.get('deviceType') == vm.NIC_DEVICES:
- return self._updateInterfaceDevice(params)
+ nic_to_update = self._get_device(params['alias'])
+ nic_xml = nic_to_update.getXML().toprettyxml(encoding='utf-8')
+
+ self.log.debug('Nic to update: %s' % nic_xml)
+ nic_xml = hooks.before_update_device(nic_xml, self.conf)
+
+ try:
+ self._dom.updateDeviceFlags(
+ nic_xml, libvirt.VIR_DOMAIN_AFFECT_LIVE)
+ except Exception:
+ self.log.debug('Request failed: %s', nic_xml, exc_info=True)
+ update = self._updateInterfaceDevice(params)
+
+ nic_xml = nic_to_update.getXML().toprettyxml(encoding='utf-8')
+ self.log.debug("Nic has been updated: %s" % nic_xml)
+
+ hooks.after_update_device(nic_xml, self.conf)
else:
- return errCode['noimpl']
+ update = errCode['noimpl']
+
+ return update
def hotunplugNic(self, params):
if self.isMigrating():
diff --git a/vdsm/vdsmd.8.in b/vdsm/vdsmd.8.in
index 7cd6c73..3796bb0 100644
--- a/vdsm/vdsmd.8.in
+++ b/vdsm/vdsmd.8.in
@@ -47,6 +47,7 @@
before_vm_migrate_destination, after_vm_migrate_destination,
before_vm_destroy, after_vm_destroy,
before_vm_set_ticket, after_vm_set_ticket,
+ before_update_device, after_update_device,
before_device_create, after_device_create,
before_device_destroy, after_device_destroy,
before_nic_hotplug, after_nic_hotplug, after_nic_hotplug_fail,
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 12bea50..cd2e77f 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -81,6 +81,8 @@
after_vm_destroy \
before_vm_set_ticket \
after_vm_set_ticket \
+ before_update_device \
+ after_update_device \
before_nic_hotplug \
after_nic_hotplug \
before_nic_hotunplug \
--
To view, visit http://gerrit.ovirt.org/13972
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fe7f5e6d8291cc227a323b324c977bcd5bc8295
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Giuseppe Vallarelli <gvallare(a)redhat.com>
10 years, 5 months
Change in vdsm[master]: NetReload: netmodels for addNetwork
by gvallare@redhat.com
Giuseppe Vallarelli has posted comments on this change.
Change subject: NetReload: netmodels for addNetwork
......................................................................
Patch Set 4: (1 inline comment)
....................................................
File vdsm/configNetwork.py
Line 115: raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Multiple nics require a '
Line 116: 'bonding device')
Line 117: nic = nics[0]
Line 118: nicBond = _netinfo.getBondingForNic(nic)
Line 119: if nic not in _netinfo.nics:
Probably you should move this inside Nic class.
Line 120: raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %r' % nic)
Line 121: elif nicBond and nicBond != bonding:
Line 122: raise ConfigNetworkError(ne.ERR_USED_NIC, 'nic %s already enslaved to '
Line 123: '%s' % (nic, nicBond))
--
To view, visit http://gerrit.ovirt.org/14303
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Iba5c5b84760e27245cbe34c3b290c54e51278e72
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap(a)redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Giuseppe Vallarelli <gvallare(a)redhat.com>
Gerrit-Reviewer: Mark Wu <wudxw(a)linux.vnet.ibm.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
10 years, 5 months
Change in vdsm[master]: NetReload: netmodels for addNetwork
by gvallare@redhat.com
Giuseppe Vallarelli has posted comments on this change.
Change subject: NetReload: netmodels for addNetwork
......................................................................
Patch Set 4: I would prefer that you didn't submit this
--
To view, visit http://gerrit.ovirt.org/14303
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Iba5c5b84760e27245cbe34c3b290c54e51278e72
Gerrit-PatchSet: 4
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap(a)redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap(a)redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken(a)redhat.com>
Gerrit-Reviewer: Giuseppe Vallarelli <gvallare(a)redhat.com>
Gerrit-Reviewer: Mark Wu <wudxw(a)linux.vnet.ibm.com>
Gerrit-Reviewer: oVirt Jenkins CI Server
10 years, 5 months