Yaniv Bronhaim has uploaded a new change for review. Change subject: Introducing configurator package in vdsm-tool ......................................................................
Introducing configurator package in vdsm-tool This package union libvirt and sanlock configuration operations. The patch also adds a usage of new configure-and-restart-all vdsm-tool verb that takes care of configuring all related services to vdsm (currently sanlock and libvirtd). Change-Id: I16bf5894e7e55a84b4c2a0caacde383ae7c19242 Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> --- M debian/vdsm-python.install M init/systemd/systemd-vdsmd.in M init/sysvinit/vdsmd.init.in M lib/vdsm/tool/Makefile.am A lib/vdsm/tool/configurator.py D lib/vdsm/tool/libvirt_configure.py D lib/vdsm/tool/sanlock.py M vdsm.spec.in 8 files changed, 151 insertions(+), 154 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/20100/1 diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install index 0e73bfb..a639663 100644 --- a/debian/vdsm-python.install +++ b/debian/vdsm-python.install @@ -12,11 +12,10 @@ ./usr/lib/python2.7/dist-packages/vdsm/qemuImg.py ./usr/lib/python2.7/dist-packages/vdsm/tool/__init__.py ./usr/lib/python2.7/dist-packages/vdsm/tool/dummybr.py -./usr/lib/python2.7/dist-packages/vdsm/tool/libvirt_configure.py +./usr/lib/python2.7/dist-packages/vdsm/tool/configurator.py ./usr/lib/python2.7/dist-packages/vdsm/tool/load_needed_modules.py ./usr/lib/python2.7/dist-packages/vdsm/tool/nwfilter.py ./usr/lib/python2.7/dist-packages/vdsm/tool/passwd.py -./usr/lib/python2.7/dist-packages/vdsm/tool/sanlock.py ./usr/lib/python2.7/dist-packages/vdsm/tool/seboolsetup.py ./usr/lib/python2.7/dist-packages/vdsm/tool/service.py ./usr/lib/python2.7/dist-packages/vdsm/tool/validate_ovirt_certs.py diff --git a/init/systemd/systemd-vdsmd.in b/init/systemd/systemd-vdsmd.in index 692e5eb..3049793 100644 --- a/init/systemd/systemd-vdsmd.in +++ b/init/systemd/systemd-vdsmd.in @@ -26,5 +26,4 @@ [ "$1" != "reconfigure" ] && usage_exit [ -n "$2" -a "$2" != "force" ] && usage_exit -"@BINDIR@/vdsm-tool" libvirt-configure ${2:+--force} && - "@BINDIR@/vdsm-tool" libvirt-configure-services-restart +"@BINDIR@/vdsm-tool" configure-and-restart-all ${2:+--force} diff --git a/init/sysvinit/vdsmd.init.in b/init/sysvinit/vdsmd.init.in index 4a4fc7d..5a0d75a 100755 --- a/init/sysvinit/vdsmd.init.in +++ b/init/sysvinit/vdsmd.init.in @@ -108,11 +108,10 @@ return 1 } -reconfigure_libvirt() { +reconfigure() { local force [ "${1}" = "force" ] && force="--force" - "$VDSM_TOOL" libvirt-configure ${force} && - "$VDSM_TOOL" libvirt-configure-services-restart + "$VDSM_TOOL" configure-and-restart-all ${force} } start() { @@ -206,7 +205,7 @@ reconfigure) # Jump over 'reconfigure' shift 1 - reconfigure_libvirt "$@" + reconfigure "$@" RETVAL=$? ;; *) diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am index 9f00984..18e2b5f 100644 --- a/lib/vdsm/tool/Makefile.am +++ b/lib/vdsm/tool/Makefile.am @@ -38,9 +38,8 @@ __init__.py \ dummybr.py \ nwfilter.py \ - libvirt_configure.py \ + configurator.py \ passwd.py \ - sanlock.py \ seboolsetup.py \ service.py \ vdsm-id.py \ diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py new file mode 100644 index 0000000..0854cb7 --- /dev/null +++ b/lib/vdsm/tool/configurator.py @@ -0,0 +1,144 @@ +# 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 sys +import grp + +from vdsm import utils +import vdsm.tool +from vdsm.tool import service +from vdsm.constants import P_VDSM_EXEC, DISKIMAGE_GROUP + + +def exec_libvirt_configure(action, *args): + """ + Invoke libvirt_configure.sh script + """ + if os.getuid() != 0: + raise RuntimeError("Must run as root") + + rc, out, err = utils.execCmd([os.path.join( + P_VDSM_EXEC, + 'libvirt_configure.sh'), action] + + list(args), + raw=True) + + sys.stdout.write(out) + sys.stderr.write(err) + return rc + + +@vdsm.tool.expose("libvirt-configure") +def configure_libvirt(*args): + """ + libvirt configuration (--force for reconfigure) + """ + rc = exec_libvirt_configure("reconfigure", *args) + if rc != 0: + raise RuntimeError("Failed to configure libvirt") + + return 0 + + +@vdsm.tool.expose("libvirt-test-conflicts") +def test_conflict_configurations(*args): + """ + Validate conflict in configured files + """ + return exec_libvirt_configure("test_conflict_configurations", *args) + + +@vdsm.tool.expose("libvirt-configure-services-restart") +def libvirt_configure_services_restart(*args): + """ + Managing restart of related services + """ + service.service_stop("supervdsmd") + service.service_stop("libvirtd") + service.service_start("libvirtd") + service.service_start("supervdsmd") + return 0 + + +@vdsm.tool.expose("libvirt-is-configured") +def libvirt_is_configured(*args): + """ + 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. + """ + retval = 1 + sanlock_pid_file = "/var/run/sanlock/sanlock.pid" + proc_status_path = "/proc/%s/status" + proc_status_group_prefix = "Groups:\t" + + try: + with open(sanlock_pid_file, "r") as f: + sanlock_pid = f.readline().strip() + with open(proc_status_path % sanlock_pid, "r") as sanlock_status: + for status_line in sanlock_status: + if status_line.startswith(proc_status_group_prefix): + groups = [int(x) for x in + status_line[len(proc_status_group_prefix):]. + strip().split(" ")] + break + else: + raise RuntimeError("Unable to find sanlock service groups") + + except IOError as e: + if e.errno == os.errno.ENOENT: + sys.stdout.write("sanlock service is not running\n") + retval = 0 # service is not running, returning + raise + + if retval != 0: + diskimage_gid = grp.getgrnam(DISKIMAGE_GROUP)[2] + if diskimage_gid not in groups: + sys.stdout.write("sanlock service requires restart\n") + retval = 0 + else: + sys.stdout.write("sanlock service is already configured\n") + + return retval + + +@vdsm.tool.expose("configure-and-restart-all") +def configure_and_restart_all(*args): + """ + Configure related services for vdsm and restart them. --force for + forcing restart of related services after configure + """ + if '--force' in args: + service.service_stop("supervdsmd") + service.service_stop("libvirtd") + + configure_libvirt(*args) + service.service_start("supervdsmd") + service.service_start("libvirtd") + + if sanlock_check_service(*args): + service.service_restart("sanlock") diff --git a/lib/vdsm/tool/libvirt_configure.py b/lib/vdsm/tool/libvirt_configure.py deleted file mode 100644 index 26987ed..0000000 --- a/lib/vdsm/tool/libvirt_configure.py +++ /dev/null @@ -1,84 +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 sys - -from vdsm import utils -import vdsm.tool -from vdsm.tool import service -from vdsm.constants import P_VDSM_EXEC - - -def exec_libvirt_configure(action, *args): - """ - Invoke libvirt_configure.sh script - """ - if os.getuid() != 0: - raise RuntimeError("Must run as root") - - rc, out, err = utils.execCmd([os.path.join( - P_VDSM_EXEC, - 'libvirt_configure.sh'), action] + - list(args), - raw=True) - - sys.stdout.write(out) - sys.stderr.write(err) - return rc - - -@vdsm.tool.expose("libvirt-configure") -def configure_libvirt(*args): - """ - libvirt configuration (--force for reconfigure) - """ - rc = exec_libvirt_configure("reconfigure", *args) - if rc != 0: - raise RuntimeError("Failed to configure libvirt") - - return 0 - - -@vdsm.tool.expose("libvirt-test-conflicts") -def test_conflict_configurations(*args): - """ - Validate conflict in configured files - """ - return exec_libvirt_configure("test_conflict_configurations", *args) - - -@vdsm.tool.expose("libvirt-configure-services-restart") -def libvirt_configure_services_restart(*args): - """ - Managing restart of related services - """ - service.service_stop("supervdsmd") - service.service_stop("libvirtd") - service.service_start("libvirtd") - service.service_start("supervdsmd") - return 0 - - -@vdsm.tool.expose("libvirt-is-configured") -def libvirt_is_configured(*args): - """ - Check if libvirt is already configured for vdsm - """ - return exec_libvirt_configure("check_if_configured", *args) 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 diff --git a/vdsm.spec.in b/vdsm.spec.in index 0b1727f..0f410aa 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1049,10 +1049,9 @@ %endif %{python_sitearch}/%{vdsm_name}/tool/dummybr.py* %{python_sitearch}/%{vdsm_name}/tool/nwfilter.py* -%{python_sitearch}/%{vdsm_name}/tool/libvirt_configure.py* +%{python_sitearch}/%{vdsm_name}/tool/configurator.py* %{_libexecdir}/%{vdsm_name}/libvirt_configure.sh %{python_sitearch}/%{vdsm_name}/tool/passwd.py* -%{python_sitearch}/%{vdsm_name}/tool/sanlock.py* %{python_sitearch}/%{vdsm_name}/tool/seboolsetup.py* %{python_sitearch}/%{vdsm_name}/tool/service.py* %{python_sitearch}/%{vdsm_name}/tool/validate_ovirt_certs.py* -- To view, visit http://gerrit.ovirt.org/20100 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I16bf5894e7e55a84b4c2a0caacde383ae7c19242 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