public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - ccs_config_validate: give the tool a decent shape
@ 2009-09-08 11:12 Fabio M. Di Nitto
  0 siblings, 0 replies; only message in thread
From: Fabio M. Di Nitto @ 2009-09-08 11:12 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=f309331a651dfa8de2323ac429adf0c4fb6f3199
Commit:        f309331a651dfa8de2323ac429adf0c4fb6f3199
Parent:        c360ca1235d96c9616d38f66526cdb56f4e95feb
Author:        Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate:    Tue Sep 8 13:11:08 2009 +0200
Committer:     Fabio M. Di Nitto <fdinitto@redhat.com>
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 <fdinitto@redhat.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-09-08 11:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-08 11:12 cluster: STABLE3 - ccs_config_validate: give the tool a decent shape Fabio M. Di Nitto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).