Change in vdsm[ovirt-3.4]: Run configure during post install when upgrading from vdsm-4...

ybronhei at redhat.com ybronhei at redhat.com
Mon Sep 29 06:18:41 UTC 2014


Yaniv Bronhaim has uploaded a new change for review.

Change subject: Run configure during post install when upgrading from vdsm-4.10.x
......................................................................

Run configure during post install when upgrading from vdsm-4.10.x

In ovirt-3.2 (vdsm 4.10.x) we didn't perform vdsm-tool configure call
during uninstall. This causes failure on first vdsm run if configure is
required. This patch adds simple external script for the configure
and execute it during post upgraded version is vdsm-4.10.x.

Change-Id: I412dc9992675acbb9d03dfa645468789cfb6e65e
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1111935
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M lib/vdsm/tool/Makefile.am
A lib/vdsm/tool/upgrade_320_conf.sh.in
M vdsm.spec.in
3 files changed, 297 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/50/33450/1

diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am
index 0198310..19d32cc 100644
--- a/lib/vdsm/tool/Makefile.am
+++ b/lib/vdsm/tool/Makefile.am
@@ -23,6 +23,7 @@
 	load_needed_modules.py.in \
 	libvirt_configure.sh.in \
 	validate_ovirt_certs.py.in \
+	upgrade_320_conf.sh.in \
 	$(NULL)
 
 nodist_vdsmtool_PYTHON = \
@@ -32,6 +33,7 @@
 
 nodist_vdsmexec_SCRIPTS = \
 	libvirt_configure.sh \
+	upgrade_320_conf.sh \
 	$(NULL)
 
 dist_vdsmtool_PYTHON = \
diff --git a/lib/vdsm/tool/upgrade_320_conf.sh.in b/lib/vdsm/tool/upgrade_320_conf.sh.in
new file mode 100755
index 0000000..4dce061
--- /dev/null
+++ b/lib/vdsm/tool/upgrade_320_conf.sh.in
@@ -0,0 +1,283 @@
+#! /bin/sh
+# 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
+#
+
+. @LIBEXECDIR@/ovirt_functions.sh
+
+ENABLE_LIBVIRT_SANLOCK="@ENABLE_LIBVIRT_SANLOCK@"
+ENABLE_LIBVIRT_SELINUX="@ENABLE_LIBVIRT_SELINUX@"
+
+GETCONFITEM="@VDSMDIR@/get-conf-item"
+VDSM_CONF_FILE="@CONFDIR@/vdsm.conf"
+QEMU_DUMP_PATH="/var/log/core"
+LCONF="@sysconfdir@/libvirt/libvirtd.conf"
+QCONF="@sysconfdir@/libvirt/qemu.conf"
+LDCONF="@LIBVIRT_SERVICE_DEFAULT@"
+QLCONF="@sysconfdir@/libvirt/qemu-sanlock.conf"
+
+# The PACKAGE_VERSION define is not used here because we do not want to
+# update the libvirt configure file every time we change vdsm package
+# version. In fact the configure generated here is almost unrelated to the
+# package version, so anything meaningful can be used here. Since a hard
+# coded version string has been already used, for compatibility we will
+# continue to use this string.
+BY_VDSM_VERS="4.13.0"
+
+[ "${ENABLE_LIBVIRT_SANLOCK}" = "yes" ] || QLCONF="/dev/null"
+
+# trigger for reconfiguration
+FORCE_RECONFIGURE="@VDSMLIBDIR@/reconfigure"
+
+get_libvirt_conf_item() {
+    local cfile="$1"
+    local key="$2"
+    @GREP_PATH@ -E "^\s*"${key}"\s*=" "${cfile}" | \
+            tail -1 | @SED_PATH@ "s/\s*$key\s*=\s*//;s/\s*\(#.*\)\?$//"
+}
+
+libvirtd_sysv2upstart() {
+    # On RHEL 6, libvirtd can be started by either SysV init or Upstart.
+    # We prefer upstart because it respawns libvirtd if when libvirtd crashed.
+
+    if ! [ -x /sbin/initctl ]; then
+        # We don't have Upstart, still use system default init mechanism
+        return 0
+    fi
+
+    local packaged=$(@RPM_PATH@ -ql libvirt libvirt-daemon | \
+                     @GREP_PATH@ libvirtd.upstart | tail -1)
+    local target="/etc/init/libvirtd.conf"
+
+    if ! [ -f "${packaged}" ]; then
+        # libvirtd package does not provide libvirtd.upstart,
+        # this could happen in Ubuntu or other distro,
+        # so continue to use system default init mechanism
+        return 0
+    fi
+
+    # Shutoff libvirt SysV service before configure upstart
+    if [ ! -f "${target}" ]; then
+        "@CHKCONFIG_PATH@" libvirtd off
+    fi
+
+    if ! diff -q "${packaged}" "${target}" >/dev/null 2>&1; then
+        @CP_PATH@ -p "${packaged}" "${target}" || return 1
+        /sbin/initctl reload-configuration
+    fi
+}
+
+# Remove configuration created by vdsm (old "# by vdsm" and the new format)
+# Argument: configuration file that will be inspected
+remove_vdsm_conf() {
+    local confFile
+    for confFile in "$@" ; do
+        # ed considers empty address ranges as error and exits on error.
+        # If there is no old "# by vdsm", ed quits without saving the
+        # edited file. We put each expression in a seperate ed invocation to
+        # have all commands exectuded even if any one of them fails.
+        # TODO: If system or ed crashed when editing the file, the file would
+        # remain in a inconsistent state. Implement atomic file editing in
+        # future.
+        ed -s "${confFile}" >/dev/null 2>&1 <<EOF
+/${start_conf_section}/,/${end_conf_section}/d
+wq
+EOF
+        ed -s "${confFile}" >/dev/null 2>&1 <<EOF
+g/${by_vdsm}/d
+wq
+EOF
+    done
+}
+
+set_if_default() {
+    local cfile="$1"
+    local key="$2"
+    local val="$3"
+
+    @GREP_PATH@ -q "^\s*${key}\s*=" "${cfile}" || \
+      echo "${key}=${val}" >> "${cfile}"
+}
+
+configure() {
+    # if SysV init file and Upstart job file both exist, prefer Upstart
+    libvirtd_sysv2upstart || return $?
+
+    local lconf="$1"
+    local qconf="$2"
+    local ldconf="$3"
+    local qlconf="$4"
+    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}"
+
+    local ts=/etc/pki/vdsm
+    local ssl=`"${GETCONFITEM}" "${VDSM_CONF_FILE}" vars ssl true | tr A-Z a-z`
+    if [ "${ssl}" = '' ]; then
+        echo 'FAILED: Could not read configuration' 1>&2
+        return 3
+    fi
+
+    # do not configure ovirt nodes before registration
+    if isOvirtNode; then
+        if [ ! -f /etc/pki/vdsm/certs/vdsmcert.pem ]; then
+            echo "${prog}: Missing certificates, ${prog} not registered" 1>&2
+            return 6
+        fi
+        /usr/bin/vdsm-tool validate-ovirt-certs
+    fi
+
+    # Remove a previous configuration (if present)
+    remove_vdsm_conf "${lconf}" "${qconf}" "${ldconf}" "${qlconf}"
+
+    # Write to all conf files the *initial* message of vdsm changes
+    for arg in "${lconf}" "${qconf}" "${ldconf}" "${qlconf}"; do
+        echo "${start_conf_section}-${BY_VDSM_VERS}" >> "${arg}"
+    done
+
+    # Set the default values for libvirt and qemu
+    set_if_default "${lconf}" listen_addr \"0.0.0.0\"
+    set_if_default "${lconf}" unix_sock_group \"@QEMUGROUP@\"
+    set_if_default "${lconf}" unix_sock_rw_perms \"0770\"
+    set_if_default "${lconf}" auth_unix_rw \"sasl\"
+    set_if_default "${lconf}" host_uuid "\"$(uuidgen)\""
+    set_if_default "${lconf}" keepalive_interval -1
+    set_if_default "${qconf}" dynamic_ownership 0
+    if [ "${ENABLE_LIBVIRT_SELINUX}" != "yes" ]; then
+        set_if_default "${qconf}" security_driver \"none\"
+    fi
+
+    if [ "${ssl}" = "true" ]; then
+        set_if_default "${qconf}" spice_tls 1
+    else
+        set_if_default "${qconf}" spice_tls 0
+    fi
+    set_if_default "${ldconf}" LIBVIRTD_ARGS --listen
+    set_if_default "${ldconf}" DAEMON_COREFILE_LIMIT unlimited
+    set_if_default "${qconf}" save_image_format \"lzop\"
+    # FIXME until we are confident with libvirt integration, let us have a verbose log
+    set_if_default "${lconf}" log_outputs \"1:file:/var/log/libvirt/libvirtd.log\"
+    set_if_default "${lconf}" log_filters "\"3:virobject 3:virfile 2:virnetlink \
+    3:cgroup 3:event 3:json 1:libvirt 1:util 1:qemu\""
+
+    # If the ssl flag is set, update the libvirt and qemu configuration files
+    # with the location for certificates and permissions.
+    if [ -f $ts/certs/cacert.pem -a \
+         -f $ts/certs/vdsmcert.pem -a \
+         -f $ts/keys/vdsmkey.pem -a \
+         "${ssl}" = "true" ]; then
+        set_if_default "${lconf}" ca_file \"$ts/certs/cacert.pem\"
+        set_if_default "${lconf}" cert_file \"$ts/certs/vdsmcert.pem\"
+        set_if_default "${lconf}" key_file \"$ts/keys/vdsmkey.pem\"
+        set_if_default "${qconf}" spice_tls_x509_cert_dir \"$ts/libvirt-spice\"
+    else
+        set_if_default "${lconf}" auth_tcp \"none\"
+        set_if_default "${lconf}" listen_tcp 1
+        set_if_default "${lconf}" listen_tls 0
+    fi
+
+    # Configure remote display port range
+    set_if_default "${qconf}" remote_display_port_min 5900
+    set_if_default "${qconf}" remote_display_port_max 6923
+
+    # Configuring sanlock
+    if [ "${ENABLE_LIBVIRT_SANLOCK}" = "yes" ]; then
+        set_if_default "${qconf}" lock_manager \"sanlock\"
+        set_if_default "${qlconf}" auto_disk_leases 0
+        set_if_default "${qlconf}" require_lease_for_disks 0
+    fi
+
+    # Configuring auto dump path
+    set_if_default "${qconf}" auto_dump_path \"${QEMU_DUMP_PATH}\"
+
+    # Write to all conf files the *end* message of vdsm changes
+    for arg in "${lconf}" "${qconf}" "${ldconf}" "${qlconf}"
+    do
+        echo "${end_conf_section}-${BY_VDSM_VERS}" >> "${arg}"
+    done
+
+    local lnetwork=/etc/libvirt/qemu/networks/autostart/default.xml
+    rm -f "${lnetwork}"
+
+    local llogr=/etc/logrotate.d/libvirtd
+    local stanza=`mktemp`
+    /bin/cat > "${stanza}" <<EOF
+## beginning of configuration section by vdsm
+/var/log/libvirt/libvirtd.log {
+    rotate 100
+    missingok
+    copytruncate
+    size 15M
+    compress
+    compresscmd /usr/bin/xz
+    uncompresscmd /usr/bin/unxz
+    compressext .xz
+}
+## end of configuration section by vdsm
+EOF
+    # unpersist cmd is remove_config on ovirt-functions
+    if isOvirtNode; then
+        . /usr/libexec/ovirt-functions
+        remove_config "${llogr}"
+    fi
+    # Backup (comment) original logrotate.d/libvirtd
+    @SED_PATH@ -i 's/^/# VDSM backup/' "$llogr"
+    @SED_PATH@ -e "/# vdsm/,/# end vdsm/d" "${llogr}" >> "${stanza}"
+    local oldmod=`/usr/bin/stat --format=%a "${llogr}"`
+
+    @MV_PATH@ "${stanza}" "${llogr}"
+
+    if [ -n "${oldmod}" ]; then
+        @CHMOD_PATH@ "${oldmod}" "${llogr}"
+    fi
+    restorecon "${llogr}"
+
+    # persist cmd is ovirt_store_config on ovirt-functions
+    if isOvirtNode; then
+        . /usr/libexec/ovirt-functions
+        ovirt_store_config \
+            "${lconf}" \
+            "${ldconf}" \
+            "${llogr}" \
+            "${qconf}" \
+            "${qlconf}"
+    fi
+
+    echo "Reconfiguration of libvirt is done."
+
+    #
+    # finished reconfiguration, do not trigger
+    # next time
+    #
+    if [ -f "${FORCE_RECONFIGURE}" ]; then
+        @RM_PATH@ -f "${FORCE_RECONFIGURE}"
+    fi
+}
+
+case "$1" in
+     configure)
+        configure "$LCONF" "$QCONF" "$LDCONF" "$QLCONF" "$2"
+        RETVAL=$?
+        ;;
+     *)
+        echo "Usage: $0 {configure}"
+        RETVAL=2
+esac
+
+exit $RETVAL
+
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 66427e1..981b085 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -685,6 +685,12 @@
 /usr/sbin/usermod -a -G %{qemu_group},%{snlk_group} %{vdsm_user}
 /usr/sbin/usermod -a -G %{cdrom_group} %{qemu_user}
 
+# On upgrade from vdsm-4.10.x we need to perform manual configure.
+# From 3.4 and above we perform the configure with vdsm-tool on uninstall.
+if [ "$1" -ge 1 ]; then
+    rpm -q %{vdsm_name} > "%{_localstatedir}/lib/%{vdsm_name}/upgraded_version"
+fi
+
 %post
 %{_bindir}/vdsm-tool configure --module sanlock --force
 %{_bindir}/vdsm-tool sebool-config || :
@@ -735,6 +741,11 @@
 /bin/systemctl daemon-reload >/dev/null 2>&1 || :
 exit 0
 %endif
+
+if grep -q '^vdsm-4\.10\.' "%{_localstatedir}/lib/%{vdsm_name}/upgraded_version";
+then
+    %{_libexecdir}/%{vdsm_name}/upgrade_320_conf.sh configure
+fi
 
 %preun
 if [ "$1" -eq 0 ]; then
@@ -1156,6 +1167,7 @@
 %{python_sitearch}/%{vdsm_name}/tool/nwfilter.py*
 %{python_sitearch}/%{vdsm_name}/tool/configurator.py*
 %{_libexecdir}/%{vdsm_name}/libvirt_configure.sh
+%{_libexecdir}/%{vdsm_name}/upgrade_320_conf.sh
 %{python_sitearch}/%{vdsm_name}/tool/passwd.py*
 %{python_sitearch}/%{vdsm_name}/tool/restore_nets.py*
 %{python_sitearch}/%{vdsm_name}/tool/seboolsetup.py*


-- 
To view, visit http://gerrit.ovirt.org/33450
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I412dc9992675acbb9d03dfa645468789cfb6e65e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.4
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>


More information about the vdsm-patches mailing list