[PATCH][RFC][follow-up 1]] Perform validation in corosync-xmlproc using RELAX NG schema

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As the schema already exists, nothing blocks performing the validation
before actual conversion of XML format of configuration into standard
corosync.conf one.

In case xmllint is not present or the file does not validate
successfully, conversion can be forced using '-f' option.

Signed-off-by: Jan Pokorný <jpokorny@xxxxxxxxxx>
---
 conf/Makefile.am          |  5 +++--
 tools/corosync-xmlproc.sh | 44 +++++++++++++++++++++++++++++++++++---------
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/conf/Makefile.am b/conf/Makefile.am
index d0771c5..3b158b7 100644
--- a/conf/Makefile.am
+++ b/conf/Makefile.am
@@ -37,7 +37,8 @@ EXTRA_DIST		= COROSYNC-MIB.txt corosync-signals.conf \
 			  corosync.xml.example \
 			  xml2conf.xsl \
 			  lenses/corosync.aug \
-			  lenses/tests/test_corosync.aug
+			  lenses/tests/test_corosync.aug \
+			  $(CONF_SCHEMA)
 
 corosysconfdir		= ${COROSYSCONFDIR}
 
@@ -57,7 +58,7 @@ corosysxmlconfdir	= ${COROSYSCONFDIR}
 corosysxmlconf_DATA	= corosync.xml.example
 
 corosysxmlxsltdir	= ${datadir}/corosync
-corosysxmlxslt_DATA	= xml2conf.xsl
+corosysxmlxslt_DATA	= xml2conf.xsl $(CONF_SCHEMA)
 endif
 
 if INSTALL_MIB
diff --git a/tools/corosync-xmlproc.sh b/tools/corosync-xmlproc.sh
index c098958..e9aa325 100644
--- a/tools/corosync-xmlproc.sh
+++ b/tools/corosync-xmlproc.sh
@@ -1,6 +1,6 @@
 #!@BASHPATH@
 
-# Copyright (c) 2011 Red Hat, Inc.
+# Copyright (c) 2013 Red Hat, Inc.
 #
 # All rights reserved.
 #
@@ -32,26 +32,52 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
+SCHEMA="@DATADIR@/corosync/corosync.rng"
+STYLESHEET="@DATADIR@/corosync/xml2conf.xsl"
+
 XSLT_PROC=xsltproc
+# to be run as (xmllint/jing compatible): $XML_VALIDATOR "$SCHEMA" "$1"
+#XML_VALIDATOR="jing"
+XML_VALIDATOR="xmllint --noout --relaxng"
+
+out_param=
+force=0
 
 usage() {
-    echo "$0 input_config [output]"
-    echo "	where input_config is valid XML configuration file"
+    echo "$0 [-f] input_config [output]"
+    echo "	where -f means to forcibly continue despite validation issues"
+    echo "	and input_config is the XML formatted configuration file"
 
     exit 1
 }
 
-[ "$1" == "" ] && usage
+if [ "$1" = "-f" ]; then
+    force=1
+    shift
+fi
+[ "$1" = "" ] && usage
 
 $XSLT_PROC -V >/dev/null 2>&1
-if [ "$?" != 0 ];then
-    echo "Can't find xslt processor $XSLT_PROC"
+if [ $? -ne 0 ]; then
+    echo "Can't find XSLT processor $XSLT_PROC"
     exit 2
 fi
 
-# TODO:
-# Validation should occur before actual processing
+# stdout reserved for generated output
+$XML_VALIDATOR "$SCHEMA" "$1" >&2
+ret=$?
+if [ $ret -ne 0 ]; then
+    if [ $force -eq 1 ]; then
+        echo "Continuing despite failing to validate ($ret)"
+    elif [ $ret -eq 127 ]; then
+        echo "Can't find XML validator $XML_VALIDATOR"
+        exit 2
+    else
+        echo "Validation failed"
+        exit 3
+    fi
+fi
 
 [ "$2" != "" ] && out_param="-o $2"
 
-$XSLT_PROC --stringparam inputfile "$1" $out_param @DATADIR@/corosync/xml2conf.xsl "$1"
+$XSLT_PROC --stringparam inputfile "$1" $out_param "$STYLESHEET" "$1"
-- 
1.7.11.7

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss



[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux