Federico Simoncelli has uploaded a new change for review. Change subject: Revert "Introducing configurator package in vdsm-tool" ......................................................................
Revert "Introducing configurator package in vdsm-tool" This reverts commit 89d70a90288ba233eb760e78e2e59a96bdfb985f. Change-Id: I8bd71a1e9a62ce5e76b2131a9cec55f02bfa8de1 Signed-off-by: Federico Simoncelli <fsimo...@redhat.com> --- M debian/vdsm-python.install M init/systemd/systemd-vdsmd.in M init/sysvinit/vdsmd.init.in M init/vdsmd_init_common.sh.in M lib/vdsm/tool/Makefile.am D lib/vdsm/tool/configurator.py A lib/vdsm/tool/libvirt_configure.py M lib/vdsm/tool/libvirt_configure.sh.in A lib/vdsm/tool/sanlock.py M vdsm.spec.in 10 files changed, 218 insertions(+), 316 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/49/21849/1 diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install index 5901152..7b695f3 100644 --- a/debian/vdsm-python.install +++ b/debian/vdsm-python.install @@ -13,11 +13,12 @@ ./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/configurator.py +./usr/lib/python2.7/dist-packages/vdsm/tool/libvirt_configure.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/restore_nets.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/transient.py diff --git a/init/systemd/systemd-vdsmd.in b/init/systemd/systemd-vdsmd.in index a502b62..692e5eb 100644 --- a/init/systemd/systemd-vdsmd.in +++ b/init/systemd/systemd-vdsmd.in @@ -26,6 +26,5 @@ [ "$1" != "reconfigure" ] && usage_exit [ -n "$2" -a "$2" != "force" ] && usage_exit -if [ "$2" = "force" ] || ! "@BINDIR@/vdsm-tool" is-configured; then - "@BINDIR@/vdsm-tool" configure --force -fi +"@BINDIR@/vdsm-tool" libvirt-configure ${2:+--force} && + "@BINDIR@/vdsm-tool" libvirt-configure-services-restart diff --git a/init/sysvinit/vdsmd.init.in b/init/sysvinit/vdsmd.init.in index ea1ea85..4a4fc7d 100755 --- a/init/sysvinit/vdsmd.init.in +++ b/init/sysvinit/vdsmd.init.in @@ -108,10 +108,11 @@ return 1 } -reconfigure() { - if [ "${1}" = "force" ] || ! "$VDSM_TOOL" is-configured; then - "$VDSM_TOOL" configure "--force" - fi +reconfigure_libvirt() { + local force + [ "${1}" = "force" ] && force="--force" + "$VDSM_TOOL" libvirt-configure ${force} && + "$VDSM_TOOL" libvirt-configure-services-restart } start() { @@ -205,11 +206,11 @@ reconfigure) # Jump over 'reconfigure' shift 1 - reconfigure "$@" + reconfigure_libvirt "$@" RETVAL=$? ;; *) - echo "Usage: $0 {start|stop|status|restart|force-reload|try-restart|condrestart}" + echo "Usage: $0 {start|stop|status|restart|force-reload|try-restart}" RETVAL=2 esac diff --git a/init/vdsmd_init_common.sh.in b/init/vdsmd_init_common.sh.in index dde9a71..9d9a5ba 100644 --- a/init/vdsmd_init_common.sh.in +++ b/init/vdsmd_init_common.sh.in @@ -46,8 +46,29 @@ } -task_check_is_configured() { - "$VDSM_TOOL" is-configured +task_reconfigure_sanlock() { + _reconfigure_sanlock +} + +_reconfigure_sanlock() { + # If sanlock was started before the *first* installation of vdsm + # then it is probably missing the supplementary groups. + # Here we attempt to restart the service (when needed) to refresh + # the groups. + "$VDSM_TOOL" sanlock-check-service + if [ $? != 0 ]; then + echo -n "Attempting to restart sanlock service:" + "$VDSM_TOOL" service-restart sanlock || return 1 + fi +} + + +task_check_libvirt_configure() { + if ! "$VDSM_TOOL" libvirt-is-configured; then + echo "Perform 'vdsm-tool libvirt-configure' before starting vdsmd" + return 1 + fi + return 0 } @@ -166,8 +187,8 @@ } -task_validate_configuration(){ - "$VDSM_TOOL" validate-config +task_test_conflicting_conf(){ + "$VDSM_TOOL" libvirt-test-conflicts } task_restore_nets(){ @@ -213,9 +234,9 @@ configure_coredump \ run_init_hooks \ gencerts \ - check_is_configured \ - validate_configuration \ + check_libvirt_configure \ prepare_transient_repository \ + reconfigure_sanlock \ syslog_available \ nwfilter \ dummybr \ @@ -223,6 +244,7 @@ tune_system \ test_space \ test_lo \ + test_conflicting_conf \ restore_nets \ " ;; diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am index f448a67..5112141 100644 --- a/lib/vdsm/tool/Makefile.am +++ b/lib/vdsm/tool/Makefile.am @@ -38,9 +38,10 @@ __init__.py \ dummybr.py \ nwfilter.py \ - configurator.py \ + libvirt_configure.py \ passwd.py \ restore_nets.py \ + sanlock.py \ seboolsetup.py \ service.py \ transient.py \ diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py deleted file mode 100644 index 9e866b4..0000000 --- a/lib/vdsm/tool/configurator.py +++ /dev/null @@ -1,287 +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 -import grp -import argparse - -from .. import utils -from . import service, expose -from ..constants import P_VDSM_EXEC, DISKIMAGE_GROUP - - -class _ModuleConfigure(object): - def __init__(self): - pass - - def getName(self): - return None - - def getServices(self): - return [] - - def validate(self): - return True - - def configure(self): - pass - - def isconfigured(self): - return True - - -class LibvirtModuleConfigure(_ModuleConfigure): - def __init__(self): - super(LibvirtModuleConfigure, self).__init__() - - def getName(self): - return 'libvirt' - - def getServices(self): - return ["supervdsmd", "vdsmd", "libvirtd"] - - def _exec_libvirt_configure(self, action): - """ - Invoke libvirt_configure.sh script - """ - if os.getuid() != 0: - raise UserWarning("Must run as root") - - rc, out, err = utils.execCmd( - ( - os.path.join( - P_VDSM_EXEC, - 'libvirt_configure.sh' - ), - action, - ), - raw=True, - ) - sys.stdout.write(out) - sys.stderr.write(err) - if rc != 0: - raise RuntimeError("Failed to perform libvirt action.") - - def configure(self): - self._exec_libvirt_configure("reconfigure") - - def validate(self): - """ - Validate conflict in configured files - """ - try: - self._exec_libvirt_configure("test_conflict_configurations") - return True - except RuntimeError: - return False - - def isconfigured(self): - """ - Check if libvirt is already configured for vdsm - """ - try: - self._exec_libvirt_configure("check_if_configured") - return True - except RuntimeError: - return False - - -class SanlockModuleConfigure(_ModuleConfigure): - def __init__(self): - super(SanlockModuleConfigure, self).__init__() - - def getName(self): - return 'sanlock' - - def getServices(self): - return ['sanlock'] - - def configure(self): - """ - Configure sanlock process groups - """ - if os.getuid() != 0: - raise UserWarning("Must run as root") - - rc, out, err = utils.execCmd( - ( - '/usr/sbin/usermod', - '-a', - '-G', - 'qemu,kvm', - 'sanlock' - ), - raw=True, - ) - sys.stdout.write(out) - sys.stderr.write(err) - if rc != 0: - raise RuntimeError("Failed to perform sanlock config.") - - def isconfigured(self, *args): - """ - Return 0 if sanlock service requires a restart to reload the relevant - supplementary groups. - """ - proc_status_group_prefix = "Groups:\t" - try: - with open("/var/run/sanlock/sanlock.pid", "r") as f: - sanlock_pid = f.readline().strip() - with open(os.path.join('/proc', sanlock_pid, 'status'), - "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: - raise RuntimeError("sanlock service is not running") - raise - - diskimage_gid = grp.getgrnam(DISKIMAGE_GROUP)[2] - if diskimage_gid not in groups: - raise RuntimeError("sanlock service requires restart") - - sys.stdout.write("sanlock service is already configured\n") - return True - - -__configurers = ( - LibvirtModuleConfigure(), - SanlockModuleConfigure(), -) - - -@expose("configure") -def configure(*args): - """ - Configure external services for vdsm - """ - args = _parse_args("configure") - configurer_to_trigger = [] - for c in __configurers: - if c.getName() in args.modules: - if not c.validate(): - raise RuntimeError( - "Configuration of %s is invalid" % c.getName() - ) - if args.force or not c.isconfigured(): - configurer_to_trigger.append(c) - - services = [] - for c in configurer_to_trigger: - for s in c.getServices(): - if service.service_status(s) == 0: - if not args.force: - raise RuntimeError( - "Cannot configure while %s is running" % s - ) - services.append(s) - - for s in services: - service.service_stop(s) - - for c in configurer_to_trigger: - c.configure() - - for s in reversed(services): - service.service_start(s) - - -@expose("is-configured") -def isconfigured(*args): - """ - Determine if module is configured - """ - ret = True - args = _parse_args('is-configured') - - m = [ - c.getName() for c in __configurers - if c.getName() in args.modules and not c.isconfigured() - ] - - if m: - sys.stdout.write( - "Modules %s are not configured\n " % ','.join(m), - ) - ret = False - - if not ret: - raise RuntimeError("Not configured. Try 'vdsm-tool configure'") - - -@expose("validate-config") -def validate_config(*args): - """ - Determine if configuration is valid - """ - ret = True - args = _parse_args('validate-config') - - m = [ - c.getName() for c in __configurers - if c.getName() in args.modules and not c.validate() - ] - - if m: - sys.stdout.write( - "Modules %s contains invalid configuration\n " % ','.join(m), - ) - ret = False - - if not ret: - raise RuntimeError("Config is not valid. Check conf files") - - -def _parse_args(action): - parser = argparse.ArgumentParser('vdsm-tool %s' % (action)) - allModules = [n.getName() for n in __configurers] - parser.add_argument( - '--module', - dest='modules', - choices=allModules, - default=[], - metavar='STRING', - action='append', - help=( - 'Specify the module to run the action on ' - '(e.g %(choices)s).\n' - 'If non is specified, operation will run for ' - 'all related modules.' - ), - ) - if action == "configure": - parser.add_argument( - '--force', - dest='force', - default=False, - action='store_true', - help='Force configuration, trigger services restart', - ) - args = parser.parse_args(sys.argv[2:]) - if not args.modules: - args.modules = allModules - return args diff --git a/lib/vdsm/tool/libvirt_configure.py b/lib/vdsm/tool/libvirt_configure.py new file mode 100644 index 0000000..0ecaa55 --- /dev/null +++ b/lib/vdsm/tool/libvirt_configure.py @@ -0,0 +1,84 @@ +# 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 .. import utils +from . import expose +from . import service +from ..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 + + +@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 + + +@expose("libvirt-test-conflicts") +def test_conflict_configurations(*args): + """ + Validate conflict in configured files + """ + return exec_libvirt_configure("test_conflict_configurations", *args) + + +@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 + + +@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/libvirt_configure.sh.in b/lib/vdsm/tool/libvirt_configure.sh.in index 950c11f..b6fc2e7 100755 --- a/lib/vdsm/tool/libvirt_configure.sh.in +++ b/lib/vdsm/tool/libvirt_configure.sh.in @@ -104,12 +104,14 @@ return 0 fi - # Shutoff libvirt SysV service before configure upstart + # Stop libvirt SysV service before configure upstart if [ ! -f "${target}" ]; then "@CHKCONFIG_PATH@" libvirtd off + "@SERVICE_PATH@" libvirtd stop fi - if ! diff -q "${packaged}" "${target}" >/dev/null 2>&1; then + if ! diff -q "${packaged}" "${target}" >/dev/null 2>&1; + then /bin/cp -p "${packaged}" "${target}" || return 1 /sbin/initctl reload-configuration fi @@ -173,6 +175,7 @@ local qconf="$2" local ldconf="$3" local qlconf="$4" + local force_reconfigure="$5" local by_vdsm="by vdsm" local start_conf_section="## beginning of configuration section ${by_vdsm}" local end_conf_section="## end of configuration section ${by_vdsm}" @@ -191,6 +194,20 @@ return 6 fi /usr/bin/vdsm-tool validate-ovirt-certs + fi + + # + # reconfigure if: + # - force specified or + # - we have the FORCE_RECONFIGURE trigger file + # - not configured + # + if [ "${force_reconfigure}" != "--force" ] && \ + ! [ -f "${FORCE_RECONFIGURE}" ] && \ + is_already_configured "${lconf}" "${qconf}" "${ldconf}" "${qlconf}"; + then + echo "Not forcing reconfigure" + return 0 fi # Remove a previous configuration (if present) @@ -297,6 +314,14 @@ fi echo "Reconfiguration of libvirt is done." + echo + cat << __EOF__ +To start working with the new configuration, execute: +'vdsm-tool libvirt-configure-services-restart' +This will manage restarting of the following services: +libvirtd, supervdsmd +__EOF__ + echo # # finished reconfiguration, do not trigger @@ -321,7 +346,7 @@ RETVAL=$? ;; *) - echo "Usage: $0 {reconfigure|test_conflict_configurations|check_if_configured}" + echo "Usage: $0 {reconfigure *conf-files [--force] | test_conflict_configurations *conf-files | check_if_configured}" RETVAL=2 esac diff --git a/lib/vdsm/tool/sanlock.py b/lib/vdsm/tool/sanlock.py new file mode 100644 index 0000000..ba59a73 --- /dev/null +++ b/lib/vdsm/tool/sanlock.py @@ -0,0 +1,58 @@ +# 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 .. import constants +from . 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 43e47ea..b72e1da 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -641,6 +641,7 @@ /usr/sbin/useradd -r -u 36 -g %{vdsm_group} -d /var/lib/vdsm \ -s /sbin/nologin -c "Node Virtualization Manager" %{vdsm_user} /usr/sbin/usermod -a -G %{qemu_group},%{snlk_group} %{vdsm_user} +/usr/sbin/usermod -a -G %{qemu_group},%{vdsm_group} %{snlk_user} %post %{_bindir}/vdsm-tool sebool-config || : @@ -736,9 +737,6 @@ if [ "$1" -ge 1 ]; then supervdsmd_start_required='no' vdsmd_start_required='no' - - # Both vdsm and supervdsm should be managed here and must be restarted if - # ran before (code might changed) if %{_bindir}/vdsm-tool service-status vdsmd >/dev/null 2>&1; then %{_bindir}/vdsm-tool service-stop vdsmd >/dev/null 2>&1 vdsmd_start_required='yes' @@ -747,12 +745,11 @@ %{_bindir}/vdsm-tool service-stop supervdsmd >/dev/null 2>&1 supervdsmd_start_required='yes' fi - - if ! %{_bindir}/vdsm-tool is-configured --module libvirt >/dev/null 2>&1; - then - %{_bindir}/vdsm-tool configure --module libvirt --force >/dev/null 2>&1 + if %{_bindir}/vdsm-tool libvirt-configure | grep -q 'is done.'; then + if %{_bindir}/vdsm-tool service-status libvirtd >/dev/null 2>&1; then + %{_bindir}/vdsm-tool service-restart libvirtd >/dev/null 2>&1 + fi fi - if [ "${supervdsmd_start_required}" = 'yes' ]; then %{_bindir}/vdsm-tool service-start supervdsmd >/dev/null 2>&1 fi @@ -1065,10 +1062,11 @@ %endif %{python_sitearch}/%{vdsm_name}/tool/dummybr.py* %{python_sitearch}/%{vdsm_name}/tool/nwfilter.py* -%{python_sitearch}/%{vdsm_name}/tool/configurator.py* +%{python_sitearch}/%{vdsm_name}/tool/libvirt_configure.py* %{_libexecdir}/%{vdsm_name}/libvirt_configure.sh %{python_sitearch}/%{vdsm_name}/tool/passwd.py* %{python_sitearch}/%{vdsm_name}/tool/restore_nets.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/transient.py* -- To view, visit http://gerrit.ovirt.org/21849 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8bd71a1e9a62ce5e76b2131a9cec55f02bfa8de1 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Federico Simoncelli <fsimo...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches