Yaniv Bronhaim has uploaded a new change for review. Change subject: Merge configuration tools to configurator.py and add configure-all verb ......................................................................
Merge configuration tools to configurator.py and add configure-all verb Change-Id: Id173b3257ba1d493d0ea44185fbb57bb5872cb2e Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> --- M init/sysvinit/vdsmd.init.in R lib/vdsm/tool/configurator.py D lib/vdsm/tool/sanlock.py 3 files changed, 53 insertions(+), 68 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/15/19915/1 diff --git a/init/sysvinit/vdsmd.init.in b/init/sysvinit/vdsmd.init.in index 13ac769..13bfa11 100755 --- a/init/sysvinit/vdsmd.init.in +++ b/init/sysvinit/vdsmd.init.in @@ -106,16 +106,11 @@ return 1 } -reconfigure_libvirt() { +reconfigure() { local force [ "${1}" = "force" ] && force="--force" - "$VDSM_TOOL" libvirt-configure ${force} && + "$VDSM_TOOL" configure-all ${force} && "$VDSM_TOOL" libvirt-configure-services-restart -} - -reconfigure_sanlock() { - "$VDSM_TOOL" sanlock-check-service && - "$VDSM_TOOL" service-restart sanlock } start() { @@ -207,8 +202,7 @@ reconfigure) # Jump over 'reconfigure' shift 1 - reconfigure_libvirt "$@" - reconfigure_sanlock + reconfigure "$@" RETVAL=$? ;; *) diff --git a/lib/vdsm/tool/libvirt_configure.py b/lib/vdsm/tool/configurator.py similarity index 62% rename from lib/vdsm/tool/libvirt_configure.py rename to lib/vdsm/tool/configurator.py index 26987ed..3f1cc62 100644 --- a/lib/vdsm/tool/libvirt_configure.py +++ b/lib/vdsm/tool/configurator.py @@ -19,11 +19,19 @@ import os import sys +import grp from vdsm import utils import vdsm.tool from vdsm.tool import service -from vdsm.constants import P_VDSM_EXEC +from vdsm.constants import P_VDSM_EXEC, DISKIMAGE_GROUP + + +SANLOCK_PID = "/var/run/sanlock/sanlock.pid" + +PROC_STATUS_PATH = "/proc/%s/status" +PROC_STATUS_GROUPS = "Groups:\t" +PROC_STATUS_GROUPS_LEN = len(PROC_STATUS_GROUPS) def exec_libvirt_configure(action, *args): @@ -82,3 +90,44 @@ Check if libvirt is already configured for vdsm """ return exec_libvirt_configure("check_if_configured", *args) + + +@vdsm.tool.expose("sanlock-check-service") +def sanlock_check_service(*args): + """ + Check if sanlock service requires a restart to reload the relevant + supplementary groups. + """ + + try: + sanlock_pid = open(SANLOCK_PID, "r").readline().strip() + sanlock_status = open(PROC_STATUS_PATH % sanlock_pid, "r") + except IOError as e: + if e.errno == os.errno.ENOENT: + return 0 # service is not running, returning + raise + + for status_line in sanlock_status: + if status_line.startswith(PROC_STATUS_GROUPS): + groups = [int(x) for x in + status_line[PROC_STATUS_GROUPS_LEN:].strip().split(" ")] + break + else: + raise RuntimeError("Unable to find sanlock service groups") + + diskimage_gid = grp.getgrnam(DISKIMAGE_GROUP)[2] + return 0 if diskimage_gid in groups else 1 + + +@vdsm.tool.expose("reconfigure-all") +def configure_all(*args): + """ + configure related services for vdsm + """ + if '--force' in args: + service.service_stop("supervdsmd") + service.service_stop("libvirtd") + + configure_libvirt(*args) + if sanlock_check_service(*args): + service.service_restart("sanlock") diff --git a/lib/vdsm/tool/sanlock.py b/lib/vdsm/tool/sanlock.py deleted file mode 100644 index 650a5cf..0000000 --- a/lib/vdsm/tool/sanlock.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2013 Red Hat, 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 -# - -import os -import grp - -from vdsm import constants -from vdsm.tool import expose - - -SANLOCK_PID = "/var/run/sanlock/sanlock.pid" - -PROC_STATUS_PATH = "/proc/%s/status" -PROC_STATUS_GROUPS = "Groups:\t" -PROC_STATUS_GROUPS_LEN = len(PROC_STATUS_GROUPS) - - -@expose("sanlock-check-service") -def sanlock_check_service(*args): - """ - Check if sanlock service requires a restart to reload the relevant - supplementary groups. - """ - - try: - sanlock_pid = open(SANLOCK_PID, "r").readline().strip() - sanlock_status = open(PROC_STATUS_PATH % sanlock_pid, "r") - except IOError as e: - if e.errno == os.errno.ENOENT: - return 0 # service is not running, returning - raise - - for status_line in sanlock_status: - if status_line.startswith(PROC_STATUS_GROUPS): - groups = [int(x) for x in - status_line[PROC_STATUS_GROUPS_LEN:].strip().split(" ")] - break - else: - raise RuntimeError("Unable to find sanlock service groups") - - diskimage_gid = grp.getgrnam(constants.DISKIMAGE_GROUP)[2] - return 0 if diskimage_gid in groups else 1 -- To view, visit http://gerrit.ovirt.org/19915 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id173b3257ba1d493d0ea44185fbb57bb5872cb2e Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches