Change in vdsm[master]: Extend vdsm-tool: moving configure libvirt to external shell...

ybronhei at redhat.com ybronhei at redhat.com
Thu May 30 16:43:31 UTC 2013


Yaniv Bronhaim has uploaded a new change for review.

Change subject: Extend vdsm-tool: moving configure libvirt to external shell script
......................................................................

Extend vdsm-tool: moving configure libvirt to external shell script

Using vdsm-tool to configure libvirt

Change-Id: Id58b129afbf141a47a85b421961bf5b1776b41e4
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M lib/vdsm/tool/Makefile.am
A lib/vdsm/tool/libvirt_configure.py
A lib/vdsm/tool/libvirt_configure.sh.in
M vdsm.spec.in
M vdsm/vdsmd.init.in
5 files changed, 291 insertions(+), 228 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/15216/1

diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am
index 0515be6..0b4f22d 100644
--- a/lib/vdsm/tool/Makefile.am
+++ b/lib/vdsm/tool/Makefile.am
@@ -21,6 +21,7 @@
 
 EXTRA_DIST = \
 	load_needed_modules.py.in \
+	libvirt_configure.sh.in \
 	validate_ovirt_certs.py.in \
 	$(NULL)
 
@@ -31,6 +32,8 @@
 
 dist_vdsmtool_DATA = \
 	__init__.py \
+	libvirt_configure.py \
+	libvirt_configure.sh \
 	passwd.py \
 	seboolsetup.py \
 	service.py \
diff --git a/lib/vdsm/tool/libvirt_configure.py b/lib/vdsm/tool/libvirt_configure.py
new file mode 100644
index 0000000..34d9014
--- /dev/null
+++ b/lib/vdsm/tool/libvirt_configure.py
@@ -0,0 +1,38 @@
+# 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
+#
+
+from vdsm import utils
+from vdsm.tool import expose
+import sys
+
+
+ at expose("libvirt-configure")
+def libvirt_configure():
+    """
+    Configure libvirt conf files
+    """
+    rc, out, err = utils.execCmd(["./libvirt_configure.sh"], sudo=True)
+
+    if rc != 0:
+        msg = "Failed to configure libvirt: %s" % err
+        raise RuntimeError(msg)
+    else:
+        for msg in out:
+            sys.stdout.write(msg + '\n')
+        return 0
diff --git a/lib/vdsm/tool/libvirt_configure.sh.in b/lib/vdsm/tool/libvirt_configure.sh.in
new file mode 100755
index 0000000..077e3c0
--- /dev/null
+++ b/lib/vdsm/tool/libvirt_configure.sh.in
@@ -0,0 +1,247 @@
+#! /bin/sh
+#
+# Copyright 2006-2013 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+. @LIBEXECDIR@/ovirt_functions.sh
+GETCONFITEM=@VDSMDIR@/get-conf-item
+CONF_FILE=@CONFDIR@/vdsm.conf
+LCONF=/etc/libvirt/libvirtd.conf
+QCONF=/etc/libvirt/qemu.conf
+LDCONF=/etc/sysconfig/libvirtd
+QLCONF=/etc/libvirt/qemu-sanlock.conf
+
+# trigger for reconfiguration
+FORCE_RECONFIGURE=@VDSMLIBDIR@/reconfigure
+
+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
+    local target
+
+    packaged=`/bin/rpm -ql libvirt libvirt-daemon | \
+              /bin/grep libvirtd.upstart | /usr/bin/tail -1`
+    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
+
+    # 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;
+    then
+        /bin/cp -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() {
+    sed -i --copy -e "/${start_conf_section}/,/${end_conf_section}/d" \
+        -e "/$by_vdsm/d" "$@"
+}
+
+set_if_default() {
+    local cfile
+    local key
+    local val
+    cfile="$1"
+    key="$2"
+    val="$3"
+
+    /bin/grep -q "^\s*$key\s*=" "$cfile" || \
+      echo "$key=$val" >> "$cfile"
+}
+
+start_configure() {
+    # if SysV init file and Upstart job file both exist, prefer Upstart
+    libvirtd_sysv2upstart || exit $?
+
+    local force_reconfigure="$1"
+    local by_vdsm="by vdsm"
+    # The PACKAGE_VERSION macro 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.
+    local by_vdsm_vers="4.10.3"
+    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
+
+    if isOvirt
+    then
+        . /usr/libexec/ovirt-functions
+    else
+        ovirt_store_config() { :; }
+    fi
+
+    local lconf
+    local qconf
+    local ldconf
+    local ssl=`$GETCONFITEM $CONF_FILE vars ssl true | tr A-Z a-z`
+
+    lconf="$2"
+    qconf="$3"
+    ldconf="$4"
+    qlconf="$5"
+
+    # do not configure ovirt nodes before registration
+    if isOvirt
+    then
+        if [ ! -f /etc/pki/vdsm/certs/vdsmcert.pem ]
+        then
+	    echo "$prog: Missing certificates, $prog not registered" 1>&2
+	    exit 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" ] &&
+        grep -q "$by_vdsm_vers" $lconf && grep -q "$by_vdsm_vers" $qconf && \
+        grep -q "$by_vdsm_vers" $ldconf && grep -q "$by_vdsm_vers" $qlconf
+    then
+        exit 0
+    fi
+
+    echo $"Configuring libvirt for vdsm..."
+
+    # 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 \"kvm\"
+    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 [ "$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/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
+
+    # Configuring sanlock
+    set_if_default $qconf lock_manager \"sanlock\"
+    set_if_default $qlconf auto_disk_leases 0
+    set_if_default $qlconf require_lease_for_disks 0
+
+    # 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
+# vdsm
+/var/log/libvirtd.log {
+    rotate 100
+    missingok
+    copytruncate
+    size 15M
+    compress
+    compresscmd /usr/bin/xz
+    uncompresscmd /usr/bin/unxz
+    compressext .xz
+}
+# end vdsm
+EOF
+
+    /bin/sed -e "/# vdsm/,/# end vdsm/d" "$llogr" >> "$stanza"
+    local oldmod=`/usr/bin/stat --format=%a "$llogr"`
+    /bin/mv "$stanza" "$llogr"
+    if [ -n "$oldmod" ]; then
+        /bin/chmod "$oldmod" "$llogr"
+    fi
+    restorecon "$llogr"
+
+    ovirt_store_config "$lconf" "$qconf" "$ldconf" "$llogr"
+
+    /usr/bin/vdsm-tool service-restart libvirtd
+
+    #
+    # finished reconfiguration, do not trigger
+    # next time
+    #
+    if [ -f "$FORCE_RECONFIGURE" ]; then
+        rm -f "$FORCE_RECONFIGURE"
+    fi
+}
+
+
+start_configure "$LCONF" "$QCONF" "$LDCONF" "$QLCONF" "$1"
+echo "Done configuring libvirt successfully"
+exit 0
+
+
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 0defc29..70e2655 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -974,6 +974,8 @@
 %else
 %{python_sitearch}/%{vdsm_name}/tool/load_needed_modules.py*
 %endif
+%{python_sitearch}/%{vdsm_name}/tool/libvirt_configure.py*
+%attr(0755, -, -) %{python_sitearch}/%{vdsm_name}/tool/libvirt_configure.sh*
 %{python_sitearch}/%{vdsm_name}/tool/passwd.py*
 %{python_sitearch}/%{vdsm_name}/tool/seboolsetup.py*
 %{python_sitearch}/%{vdsm_name}/tool/service.py*
diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in
index 72a48c3..803f2af 100755
--- a/vdsm/vdsmd.init.in
+++ b/vdsm/vdsmd.init.in
@@ -37,9 +37,6 @@
                  supervdsmd"
 CONFLICTING_SERVICES="libvirt-guests"
 
-# trigger for reconfiguration
-FORCE_RECONFIGURE=@VDSMLIBDIR@/reconfigure
-
 LCONF=/etc/libvirt/libvirtd.conf
 QCONF=/etc/libvirt/qemu.conf
 LDCONF=/etc/sysconfig/libvirtd
@@ -204,230 +201,6 @@
     return 1
 }
 
-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
-    local target
-
-    packaged=`/bin/rpm -ql libvirt libvirt-daemon | \
-              /bin/grep libvirtd.upstart | /usr/bin/tail -1`
-    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
-
-    # 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;
-    then
-        /bin/cp -p "$packaged" "$target" || return 1
-        /sbin/initctl reload-configuration
-    fi
-}
-
-# configure libvirt to vdsm's needs
-configure_libvirt()
-{
-
-    # if SysV init file and Upstart job file both exist, prefer Upstart
-    libvirtd_sysv2upstart || return $?
-
-    local force_reconfigure="$1"
-    local by_vdsm="by vdsm"
-    # The PACKAGE_VERSION macro 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.
-    local by_vdsm_vers="4.10.3"
-    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
-
-    # Remove configuration created by vdsm (old "# by vdsm" and the new format)
-    # Argument: configuration file that will be inspected
-    remove_vdsm_conf() {
-        sed -i --copy -e "/${start_conf_section}/,/${end_conf_section}/d" \
-            -e "/$by_vdsm/d" "$@"
-    }
-
-    set_if_default() {
-        local cfile
-        local key
-        local val
-        cfile="$1"
-        key="$2"
-        val="$3"
-
-        /bin/grep -q "^\s*$key\s*=" "$cfile" || \
-          echo "$key=$val" >> "$cfile"
-    }
-
-    if isOvirt
-    then
-        . /usr/libexec/ovirt-functions
-    else
-        ovirt_store_config() { :; }
-    fi
-
-    local lconf
-    local qconf
-    local ldconf
-    local ssl=`$GETCONFITEM $CONF_FILE vars ssl true | tr A-Z a-z`
-
-    lconf="$2"
-    qconf="$3"
-    ldconf="$4"
-    qlconf="$5"
-
-    # do not configure ovirt nodes before registration
-    if isOvirt
-    then
-        if [ ! -f /etc/pki/vdsm/certs/vdsmcert.pem ]
-        then
-            log_failure_msg "$prog: Missing certificates, $prog not registered"
-            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" ] &&
-       grep -q "$by_vdsm_vers" $lconf && grep -q "$by_vdsm_vers" $qconf && \
-       grep -q "$by_vdsm_vers" $ldconf && grep -q "$by_vdsm_vers" $qlconf
-    then
-        log_success_msg $"$prog: libvirt already configured for vdsm "
-        return 0
-    fi
-
-    echo $"Configuring libvirt for vdsm..."
-
-    # 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 \"kvm\"
-    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 [ "$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/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
-
-    # Configuring sanlock
-    set_if_default $qconf lock_manager \"sanlock\"
-    set_if_default $qlconf auto_disk_leases 0
-    set_if_default $qlconf require_lease_for_disks 0
-
-    # 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
-# vdsm
-/var/log/libvirtd.log {
-    rotate 100
-    missingok
-    copytruncate
-    size 15M
-    compress
-    compresscmd /usr/bin/xz
-    uncompresscmd /usr/bin/unxz
-    compressext .xz
-}
-# end vdsm
-EOF
-    /bin/sed -e "/# vdsm/,/# end vdsm/d" "$llogr" >> "$stanza"
-    local oldmod=`/usr/bin/stat --format=%a "$llogr"`
-    /bin/mv "$stanza" "$llogr"
-    if [ -n "$oldmod" ]; then
-       /bin/chmod "$oldmod" "$llogr"
-    fi
-    restorecon "$llogr"
-
-    ovirt_store_config "$lconf" "$qconf" "$ldconf" "$llogr"
-
-    /usr/bin/vdsm-tool service-restart libvirtd
-
-    #
-    # finished reconfiguration, do not trigger
-    # next time
-    #
-    if [ -f "$FORCE_RECONFIGURE" ]; then
-        rm -f "$FORCE_RECONFIGURE"
-    fi
-}
-
-
 RETVAL=0
 
 reconfigure() {
@@ -441,7 +214,7 @@
             args="$args $LCONF $QCONF $LDCONF $QLCONF"
             ;;
     esac
-    configure_libvirt $args
+    /usr/bin/vdsm-tool configure_libvirt $args
 }
 
 has_systemd() {


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

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


More information about the vdsm-patches mailing list