Wenyi Gao has uploaded a new change for review.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool
Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Signed-off-by: Wenyi Gao wenyi@linux.vnet.ibm.com --- M .gitignore M vdsm-tool/Makefile.am A vdsm-tool/base.py A vdsm-tool/needed_service.py.in M vdsm.spec.in M vdsm/vdsmd.init.in 6 files changed, 145 insertions(+), 42 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/8759/1
diff --git a/.gitignore b/.gitignore index 49a78ef..f9c26d4 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ vdsm/vdsmd.8 vdsm/vdsmd.init vdsm-tool/load_needed_modules.py +vdsm-tool/needed_service.py vdsm-tool/validate_ovirt_certs.py vdsm_cli/vdsClient vdsm_cli/vdscli.py diff --git a/vdsm-tool/Makefile.am b/vdsm-tool/Makefile.am index 997e339..0ed3226 100644 --- a/vdsm-tool/Makefile.am +++ b/vdsm-tool/Makefile.am @@ -27,7 +27,9 @@
dist_vdsmtool_DATA = \ __init__.py \ + base.py \ load_needed_modules.py \ + needed_service.py \ passwd.py \ validate_ovirt_certs.py \ $(NULL) diff --git a/vdsm-tool/base.py b/vdsm-tool/base.py new file mode 100644 index 0000000..9ded9a1 --- /dev/null +++ b/vdsm-tool/base.py @@ -0,0 +1,77 @@ +# Copyright IBM, Corp. 2012 +# +# 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 +# + +import subprocess + + +def exec_command(argv): + """ + This function executes a given shell command. + """ + try: + p = subprocess.Popen(argv, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = p.communicate() + rc = p.returncode + except: + raise Exception('Failed to execute "%s"', ' '.join(argv), + exc_info=True) + + return (rc, out, err) + + +def call_init_function(function, *args, **kwargs): + """ + Call a function from /etc/init.d/functions. + """ + allowed_init_function = ['success', 'failure', 'pidofproc', + 'killproc', 'daemon'] + rc = -1 + srccmd = 'SYSTEMCTL_SKIP_REDIRECT=true source /etc/init.d/functions;' + + if function not in allowed_init_function: + print('Illegal function "%s"', function) + return rc + + tmpcmd = function + ' '.join('%s=%s' % item for item in kwargs.iteritems()) + tmpcmd += ' ' + ' '.join(args) + # Only allow to execute one shell command. + if any(c in tmpcmd for c in (';', '&&', '||')): + print('Illegal function parameters "%s"', tmpcmd) + return rc + + cmd = srccmd + tmpcmd + try: + rc = subprocess.call([cmd], shell=True) + except: + raise Exception('Failed to execute "%s"', cmd, exc_info=True) + + return rc + + +def print_msg(msg, success=True): + """ + Print message followed by a color string "[ OK ]" or "[Failed]". + """ + print msg, + if success: + call_init_function('success') + else: + call_init_function('failure') + print diff --git a/vdsm-tool/needed_service.py.in b/vdsm-tool/needed_service.py.in new file mode 100644 index 0000000..5266408 --- /dev/null +++ b/vdsm-tool/needed_service.py.in @@ -0,0 +1,61 @@ +# Copyright IBM, Corp. 2012 +# +# 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 +# + +import os + +from vdsm import constants +from vdsm.tool.base import exec_command, print_msg +from vdsm.tool import expose + +EX_CHKCONFIG = '@CHKCONFIG_PATH@' +EX_SERVICE = constants.EXT_SERVICE + + +@expose('shutdown-conflicting-srv') +def shutdown_conflicting_srv(): + """ + Shutdown conflicting service + """ + srv = 'libvirt-guests' + exec_command([EX_CHKCONFIG, srv, 'off']) + rc = exec_command([EX_SERVICE, srv, 'status'])[0] + if rc == 0: + if os.path.exists('/var/lock/subsys/libvirt-guests'): + os.unlink('/var/lock/subsys/libvirt-guests') + else: + exec_command([EX_SERVICE, srv, 'stop']) + return 0 + + +@expose('start-needed-srv') +def start_needed_srv(): + """ + Start needed service + """ + services = ['iscsid', 'multipathd', 'ntpd', 'wdmd', 'sanlock'] + for srv in services: + rc = exec_command([EX_SERVICE, srv, 'status'])[0] + if rc != 0: + print 'Starting %s...' % srv + rc = exec_command([EX_SERVICE, srv, 'start'])[0] + if rc != 0: + print_msg('vdsm: Dependent %s failed to start' % srv, False) + return rc + exec_command([EX_SERVICE, 'iscsid', 'force-start']) + return 0 diff --git a/vdsm.spec.in b/vdsm.spec.in index f61a36a..dc7ee24 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -771,6 +771,8 @@ %{python_sitearch}/%{vdsm_name}/tool/passwd.py* %{python_sitearch}/%{vdsm_name}/tool/validate_ovirt_certs.py* %{python_sitearch}/%{vdsm_name}/tool/load_needed_modules.py* +%{python_sitearch}/%{vdsm_name}/tool/needed_service.py* +%{python_sitearch}/%{vdsm_name}/tool/base.py*
%files tests %doc %{_datadir}/%{vdsm_name}/tests/README diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in index 2b9ad11..35fb05e 100755 --- a/vdsm/vdsmd.init.in +++ b/vdsm/vdsmd.init.in @@ -32,8 +32,6 @@ CORE_DUMP_PATH=/var/log/core/core.%p.%t.dump DOM_METADATA_BACKUP_DIR=/var/log/vdsm/backup CORE_PATTERN=/proc/sys/kernel/core_pattern -NEEDED_SERVICES="iscsid multipathd ntpd wdmd sanlock" -CONFLICTING_SERVICES="libvirt-guests"
LCONF=/etc/libvirt/libvirtd.conf QCONF=/etc/libvirt/qemu.conf @@ -130,49 +128,11 @@ fi }
-shutdown_conflicting_srv() { - local srv - - for srv in $CONFLICTING_SERVICES - do - /sbin/chkconfig $srv off - if /sbin/service $srv status > /dev/null 2>&1; - then - if [ "$srv" == "libvirt-guests" ]; then - /bin/rm -f /var/lock/subsys/libvirt-guests - else - /sbin/service $srv stop - fi - fi - done - return 0 -}
libvirt_should_use_upstart() { [[ -x /sbin/initctl ]] }
-start_needed_srv() { - local srv - local ret_val - - for srv in $NEEDED_SERVICES - do - if ! /sbin/service $srv status > /dev/null 2>&1; - then - echo "Starting $srv..." - /sbin/service $srv start - ret_val=$? - if [ $ret_val -ne 0 ] - then - log_failure_msg "$prog: Dependent $srv failed to start" - return $ret_val - fi - fi - done - - /sbin/service iscsid force-start -}
test_lo() { if ! LC_ALL=C /sbin/ifconfig lo | /bin/grep -q UP; @@ -428,7 +388,7 @@ local ret_val python @VDSMDIR@/hooks.pyc before_vdsm_start
- shutdown_conflicting_srv && stop_libvirtd_sysv + /usr/bin/vdsm-tool shutdown-conflicting-srv && stop_libvirtd_sysv
if ! @LIBEXECDIR@/vdsm-gencerts.sh --check; then echo -n $"Configuring a self-signed VDSM host certificate: " @@ -443,7 +403,7 @@ return $ret_val fi
- start_needed_srv && start_libvirtd + /usr/bin/vdsm-tool start-needed-srv && start_libvirtd ret_val=$? if [ $ret_val -ne 0 ] then
-- To view, visit http://gerrit.ovirt.org/8759 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Wenyi Gao wenyi@linux.vnet.ibm.com
Yaniv Bronhaim has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2: Fails
It gets stuck. Please verify that it works the same over rhel6.3 and fedora17.
The code simplify vsdmd which I like and prefer, just keep in mind that vdsm-tool exists only upstream.
-- To view, visit http://gerrit.ovirt.org/8759 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Federico Simoncelli fsimonce@redhat.com Gerrit-Reviewer: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Wenyi Gao has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2:
Yaniv,
How did you test? I tested it on Fedora17 and there is no failure.
-- To view, visit http://gerrit.ovirt.org/8759 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Federico Simoncelli fsimonce@redhat.com Gerrit-Reviewer: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Yaniv Bronhaim has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2:
Over rhel6.3 and when I ran: service vdsmd restart, it got stuck, maybe I miss something
-- To view, visit http://gerrit.ovirt.org/8759 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Federico Simoncelli fsimonce@redhat.com Gerrit-Reviewer: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Wenyi Gao has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2:
Yaniv,
It's very difficulty for me to set up rhel6.3 to run vdsm because the latest vdsm version need to depends on many latest version packages including kernel-3.6. So must we verify it on rhel6.3?
-- To view, visit http://gerrit.ovirt.org/8759 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: I54eca4b2cc3a17e9819a0188e5dc4c8bd28161da Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Federico Simoncelli fsimonce@redhat.com Gerrit-Reviewer: Wenyi Gao wenyi@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Itamar Heim has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2:
still relevant or should be abandoned?
Yaniv Bronhaim has posted comments on this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Patch Set 2:
Not relevant. Manipulatation of related services is part of the daemon manager to take care (init scripts of systemd\sysv\upstat - look under init folder), shouldn't be part of a tool
Please abandon patch.
Itamar Heim has abandoned this change.
Change subject: Move start_needed_srv and shutdown_conflicting_srv to vdsm-tool ......................................................................
Abandoned
abandoning per last comment, please re-open if relevant
vdsm-patches@lists.fedorahosted.org