[Ovirt-devel] [PATCH node] augtool wrapper

Alan Pevec apevec at redhat.com
Thu Jan 15 14:20:26 UTC 2009


workaround for bind-mounted files
see https://fedorahosted.org/augeas/ticket/32
requires augeas 0.3.5

augtool [tmpaugscript]
script MUST NOT include save, it is added by the wrapper
with copy_if_rename_fails flag set
'tmpaugscript' is removed after successfull execution
without a parameter, augtool commands are expected on standard input

Signed-off-by: Alan Pevec <apevec at redhat.com>
---
 ovirt-node.spec.in              |    2 +-
 scripts/ovirt-config-hostname   |   10 +++-----
 scripts/ovirt-config-networking |    4 +-
 scripts/ovirt-config-storage    |    3 +-
 scripts/ovirt-early             |    7 +-----
 scripts/ovirt-functions         |   46 +++++++++++++++++++++-----------------
 scripts/ovirt-process-config    |    9 +++----
 7 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index 501bf4f..ddccc2d 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -18,7 +18,7 @@ Requires(preun): /sbin/chkconfig
 BuildRequires:  libvirt-devel >= 0.5.1
 BuildRequires:  dbus-devel hal-devel
 Requires:       libvirt >= 0.5.1
-Requires:       augeas
+Requires:       augeas >= 0.3.5
 Requires:       libvirt-qpid >= 0.2.3
 Requires:       hal
 Requires:       collectd-virt
diff --git a/scripts/ovirt-config-hostname b/scripts/ovirt-config-hostname
index 8530843..f609b38 100755
--- a/scripts/ovirt-config-hostname
+++ b/scripts/ovirt-config-hostname
@@ -8,16 +8,14 @@
 HOSTNAME_FILE="/etc/sysconfig/network"
 
 function set_hostname {
-    augtool > /dev/null <<EOF
-    set /files$HOSTNAME_FILE/HOSTNAME "$1"
-    save
+    augtool <<EOF
+set /files$HOSTNAME_FILE/HOSTNAME "$1"
 EOF
 }
 
 function remove_hostname {
-    augtool > /dev/null <<EOF
-    rm /files$HOSTNAME_FILE/HOSTNAME
-    save
+    augtool <<EOF
+rm /files$HOSTNAME_FILE/HOSTNAME
 EOF
 }
 
diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking
index 52af071..3c22369 100755
--- a/scripts/ovirt-config-networking
+++ b/scripts/ovirt-config-networking
@@ -188,8 +188,8 @@ if [ "$RESTART" == "Y" ]; then
     {
     printf "Configuring network.\n"
     config="$WORKDIR"/config-augtool
-    { cat "$WORKDIR"/augtool-* && printf "save\n"; } > $config \
-    && augtool < $config  \
+    cat "$WORKDIR"/augtool-* > $config \
+    && augtool $config  \
     && service network restart
     } 2>&1 | tee $CONFIG_LOG_FILE
 
diff --git a/scripts/ovirt-config-storage b/scripts/ovirt-config-storage
index f68e058..58734f4 100755
--- a/scripts/ovirt-config-storage
+++ b/scripts/ovirt-config-storage
@@ -120,14 +120,13 @@ do_configure()
         fi
     done
     # save input variables
-    augtool <<EOF > /dev/null
+    augtool <<EOF
 set /files$OVIRT_DEFAULTS/OVIRT_INIT $DRIVE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_BOOT_SIZE $BOOT_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_SWAP_SIZE $SWAP_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_ROOT_SIZE $ROOT_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_CONFIG_SIZE $CONFIG_SIZE
 set /files$OVIRT_DEFAULTS/OVIRT_VOL_LOGGING_SIZE $LOGGING_SIZE
-save
 EOF
 }
 
diff --git a/scripts/ovirt-early b/scripts/ovirt-early
index a911b65..f145594 100755
--- a/scripts/ovirt-early
+++ b/scripts/ovirt-early
@@ -300,12 +300,7 @@ start() {
             echo "set /files$OVIRT_DEFAULTS/OVIRT_$PARAM '\"$value\"'" \
                 >> $tmpaug
         done
-        echo "save" >> $tmpaug
-        # augtool on bindmounted files fails
-        umount_config $OVIRT_DEFAULTS
-        augtool < $tmpaug > /dev/null
-        ovirt_store_config $OVIRT_DEFAULTS
-        rm $tmpaug
+        augtool $tmpaug
     else
         echo "initial startup"
         # dump all ovirt bootparams
diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions
index 9301678..57e6fd1 100644
--- a/scripts/ovirt-functions
+++ b/scripts/ovirt-functions
@@ -51,12 +51,9 @@ is_firstboot() {
 
 disable_firstboot() {
     if mount_config; then
-        umount_config $OVIRT_DEFAULTS
-        augtool > /dev/null <<EOF
+        augtool <<EOF
 set /files$OVIRT_DEFAULTS/OVIRT_FIRSTBOOT no
-save
 EOF
-        ovirt_store_config $OVIRT_DEFAULTS
     fi
 }
 
@@ -196,24 +193,31 @@ mount_config() {
     fi
 }
 
-# unmount bindmounted config files
-#       umount_config /etc/config /etc/config2 ...
-#
-# Use before running sed -i or augeas against the bindmounted file,
-# Otherwise save fails: https://fedorahosted.org/augeas/ticket/32
-# After file is replaced, call ovirt_store_config /etc/config /etc/config2 ...
-# to bindmount the config file again.
-#
-umount_config() {
-    if grep -q " /config " /proc/mounts; then
-        for f in "$@"; do
-            if grep -q " $f " /proc/mounts ; then
-                umount -n $f
-                # refresh rootfs copy
-                cp /config$f $f
-            fi
-        done
+# augtool wrapper
+#   workaround for bind-mounted files
+#   see https://fedorahosted.org/augeas/ticket/32
+# augtool [tmpaugscript]
+# script MUST NOT include save, it is added by the wrapper
+# with copy_if_rename_fails flag set
+# 'tmpaugscript' is removed after successfull execution
+# without a parameter, augtool commands are expected on standard input
+augtool() {
+    local tmpaug=$1
+    if [ -z "$1" ]; then
+        # read from stdin
+        tmpaug=$(mktemp)
+        cat > $tmpaug
     fi
+    cat >> $tmpaug <<EOF
+clear /augeas/save/copy_if_rename_fails
+save
+EOF
+    /usr/bin/augtool < $tmpaug > /dev/null
+    rc=$?
+    if [ $rc -eq 0 ]; then
+        rm $tmpaug
+    fi
+    return $rc
 }
 
 # persist configuration to /config
diff --git a/scripts/ovirt-process-config b/scripts/ovirt-process-config
index 8641fa0..dd1b7e5 100755
--- a/scripts/ovirt-process-config
+++ b/scripts/ovirt-process-config
@@ -5,6 +5,8 @@
 # configuration file. It then restarts the networking service
 # and saves the configuration files.
 
+. /etc/init.d/ovirt-functions
+
 ME=$(basename "$0")
 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
 try_h() { printf "Try \`$ME -h' for more information.\n" >&2; exit 1;}
@@ -57,17 +59,14 @@ networking=$(awk '/^[ \t]*ifcfg=/ {
         }
     }
 
-
-    printf("save\n")
-
 }' $CONFIG)
 
 echo "$networking" > $OVIRT_CONFIG_OUTPUT_FILE
 
 if [ -f $OVIRT_CONFIG_OUTPUT_FILE ]; then
-    umount_config /etc/sysconfig/network-scripts/ifcfg*
-    augtool < $OVIRT_CONFIG_OUTPUT_FILE \
+    augtool $OVIRT_CONFIG_OUTPUT_FILE \
 	&& RESULT=0 || RESULT=1
+    # FIXME do not store ifcfg-lo
     if ls /etc/sysconfig/network-scripts/ifcfg* > /dev/null >2&1; then
 	ovirt_store_config /etc/sysconfig/network-scripts/ifcfg*
     fi
-- 
1.6.0.6




More information about the ovirt-devel mailing list