From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22456 invoked by alias); 8 Sep 2009 11:12:19 -0000 Received: (qmail 22439 invoked by alias); 8 Sep 2009 11:12:19 -0000 X-SWARE-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL,BAYES_05,J_CHICKENPOX_81,J_CHICKENPOX_91,SPF_HELO_PASS X-Spam-Status: No, hits=-0.6 required=5.0 tests=AWL,BAYES_05,J_CHICKENPOX_81,J_CHICKENPOX_91,SPF_HELO_PASS X-Spam-Check-By: sourceware.org X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bastion2.fedora.phx.redhat.com Subject: cluster: STABLE3 - ccs_config_validate: give the tool a decent shape To: cluster-cvs-relay@redhat.com X-Project: Cluster Project X-Git-Module: cluster.git X-Git-Refname: refs/heads/STABLE3 X-Git-Reftype: branch X-Git-Oldrev: c360ca1235d96c9616d38f66526cdb56f4e95feb X-Git-Newrev: f309331a651dfa8de2323ac429adf0c4fb6f3199 From: "Fabio M. Di Nitto" Message-Id: <20090908111143.523E71201F5@lists.fedorahosted.org> Date: Tue, 08 Sep 2009 11:12:00 -0000 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 Mailing-List: contact cluster-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cluster-cvs-owner@sourceware.org X-SW-Source: 2009-q3/txt/msg00315.txt.bz2 Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=f309331a651dfa8de2323ac429adf0c4fb6f3199 Commit: f309331a651dfa8de2323ac429adf0c4fb6f3199 Parent: c360ca1235d96c9616d38f66526cdb56f4e95feb Author: Fabio M. Di Nitto AuthorDate: Tue Sep 8 13:11:08 2009 +0200 Committer: Fabio M. Di Nitto CommitterDate: Tue Sep 8 13:11:08 2009 +0200 ccs_config_validate: give the tool a decent shape add several fancy options and checks Signed-off-by: Fabio M. Di Nitto --- config/tools/xml/Makefile | 1 + config/tools/xml/ccs_config_validate.in | 154 ++++++++++++++++++++++++++++--- 2 files changed, 142 insertions(+), 13 deletions(-) diff --git a/config/tools/xml/Makefile b/config/tools/xml/Makefile index 31a2aab..a5c5cc7 100644 --- a/config/tools/xml/Makefile +++ b/config/tools/xml/Makefile @@ -29,6 +29,7 @@ ${TARGET2}: $(S)/${TARGET2}.in cat $(S)/$(TARGET2).in | sed \ -e 's#@SBINDIR@#${sbindir}#g' \ -e 's#@SHAREDIR@#${sharedir}#g' \ + -e 's#@VERSION@#${RELEASE_VERSION}#g' \ > $(TARGET2) ${TARGET3}: $(S)/${TARGET3}.in diff --git a/config/tools/xml/ccs_config_validate.in b/config/tools/xml/ccs_config_validate.in index 4d028fe..9ac98f7 100644 --- a/config/tools/xml/ccs_config_validate.in +++ b/config/tools/xml/ccs_config_validate.in @@ -1,7 +1,5 @@ #!/bin/bash -set -e - # rpm based distros if [ -d /etc/sysconfig ]; then [ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster @@ -17,25 +15,155 @@ fi [ -z "$CONFIG_LOADER" ] && CONFIG_LOADER=xmlconfig export COROSYNC_DEFAULT_CONFIG_IFACE=$CONFIG_LOADER:cmanpreconfig -[ -n "$1" ] && export COROSYNC_CLUSTER_CONFIG_FILE="$1" +print_usage() { + echo "Usage:" + echo "" + echo "ccs_config_validate [options]" + echo "" + echo "Options:" + echo " -h Print this help, then exit" + echo " -V Print program version information, then exit" + echo " -v Produce verbose output" + echo "" + echo " -r Force validation of runtime config" + echo " -C config_loader Override config plugin loader" + echo "" + echo "Validating XML configuraton files:" + echo " -f configfile Validate an alternate config file" + echo " -l Do not perform load test (requires -f)" + echo "" + echo "Debugging options:" + echo " -t tempfile Force temporay file to tempfile" + echo " -n Do not remove temporary file" + echo " -o Overwrite temporary file (dangerous)" +} + +check_opts() { + while [ "$1" != "--" ]; do + case $1 in + -h) + print_usage + exit 0 + ;; + -V) + echo "ccs_config_validate version @VERSION@" + exit 0 + ;; + -t) + shift + tempfile="$1" + ;; + -n) + notempfilerm=1 + ;; + -o) + overwritetempfile=1 + ;; + -C) + shift + COROSYNC_DEFAULT_CONFIG_IFACE=$1:cmanpreconfig + loaderoverride=1 + if [ -n "$runtimetest" ] || \ + [ -n "$filetest" ] || \ + [ -n "$noloadtest" ]; then + echo "Error: invalid options. -C can not be set together with -l or -r or -f" >&2 + exit 255 + fi + ;; + -f) + shift + COROSYNC_CLUSTER_CONFIG_FILE=$1 + COROSYNC_DEFAULT_CONFIG_IFACE=xmlconfig:cmanpreconfig + filetest=1 + if [ -n "$loaderoverride" ] || \ + [ -n "$runtimetest" ]; then + echo "Error: invalid options. -f can not be set together with -r or -C" >&2 + exit 255 + fi + ;; + -l) + noloadtest=1 + ;; + -r) + unset COROSYNC_DEFAULT_CONFIG_IFACE + runtimetest=1 + if [ -n "$noloadtest" ] || \ + [ -n "$loaderoverride" ] || \ + [ -n "$filetest" ]; then + echo "Error: invalid options. -r can not be set together with -l or -C or -f" >&2 + exit 255 + fi + ;; + -v) + verbose=1 + ;; + esac + shift + done + + if [ -n "$noloadtest" ] && [ -z "$COROSYNC_CLUSTER_CONFIG_FILE" ]; then + echo "Error: -l requires -f option" >&2 + exit 255 + fi -tempfile=$(mktemp) +} -if [ -z "$tempfile" ]; then - echo "Unable to create temp file" +lecho() +{ + [ -n "$verbose" ] && echo $@ + return 0 +} + +export COROSYNC_DEFAULT_CONFIG_IFACE +export COROSYNC_CLUSTER_CONFIG_FILE + +opts=$(getopt t:hVnC:f:lrov $@) +if [ "$?" != 0 ]; then + print_usage >&2 exit 255 fi +check_opts $opts -if ! ccs_config_dump > $tempfile; then - rm -f $tempfile - echo "Unable to get the configuration" - exit 255 +if [ -n "$tempfile" ]; then + if [ -f "$tempfile" ] && [ -z "$overwritetempfile" ]; then + echo "Selected temporary file $tempfile already exists" >&2 + echo "Use -o to force overwrite (dangerous)" >&2 + exit 255 + fi +else + tempfile=$(mktemp) + if [ -z "$tempfile" ]; then + echo "Unable to create temporary file" >&2 + exit 255 + fi fi +lecho "Creating temporary file: $tempfile" +lecho "Config interface set to: $COROSYNC_DEFAULT_CONFIG_IFACE" -xmllint \ +if [ -n "$noloadtest" ]; then + cp $COROSYNC_CLUSTER_CONFIG_FILE $tempfile +else + if ! ccs_config_dump > $tempfile; then + [ -z "$notempfilerm" ] && rm -f $tempfile + echo "Unable to get the configuration" >&2 + exit 255 + fi +fi +lecho "Configuration stored in temporary file" + +lecho "Validating.." + +xmlout=$(xmllint --noout \ --relaxng @SHAREDIR@/cluster.rng \ - $tempfile >/dev/null + $tempfile 2>&1) res=$? -rm -f $tempfile +echo "$xmlout" | sed \ + -e 's#.*validates$#Configuration validates#g' \ + -e 's#.*validate$#Configuration fails to validate#g' \ + -e 's#'$tempfile'#tempfile#g' + +lecho "Validation completed" + +[ -z "$notempfilerm" ] && rm -f $tempfile exit $res