From 3ab1f50a19c8daac65e56ee900c2aefbc29db6ae Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 4 May 2020 13:35:04 +0200 Subject: [PATCH] undef state path bypass --- apps/backend/backend_plugin.c | 58 +++++++++++++++++++++++++++++++++-- include/clixon_custom.h | 5 +-- test/test_xml_validate.sh | 51 ++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100755 test/test_xml_validate.sh diff --git a/apps/backend/backend_plugin.c b/apps/backend/backend_plugin.c index 4daca324..6706b520 100644 --- a/apps/backend/backend_plugin.c +++ b/apps/backend/backend_plugin.c @@ -249,7 +249,7 @@ clixon_plugin_statedata_all(clicon_handle h, clicon_log_xml(LOG_DEBUG, x, "%s STATE:", __FUNCTION__); #endif #ifdef USE_STATE_PATH_KLUDGE - /* This kludge skips all yang binding and validation of paths begining with a + /* This kludge skips all yang binding and validation of paths beginning with a * specific prefix * Note that there are many problems with this kludge. */ @@ -294,7 +294,11 @@ clixon_plugin_statedata_all(clicon_handle h, goto done; } -/*! Create and initialize transaction */ +/*! Create and initialize a validate/commit transaction + * @retval td New alloced transaction, + * @retval NULL Error + * @see transaction_free which deallocates the returned handle + */ transaction_data_t * transaction_new(void) { @@ -310,7 +314,10 @@ transaction_new(void) return td; } -/*! Free transaction structure */ +/*! Free transaction structure + * + * @param[in] td Transaction data will be deallocated after the call + */ int transaction_free(transaction_data_t *td) { @@ -330,6 +337,13 @@ transaction_free(transaction_data_t *td) return 0; } +/*! Call single plugin transaction_begin() before a validate/commit. + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_begin_one(clixon_plugin *cp, clicon_handle h, @@ -375,6 +389,13 @@ plugin_transaction_begin_all(clicon_handle h, return retval; } +/*! Call single plugin transaction_validate() in a validate/commit transaction + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_validate_one(clixon_plugin *cp, clicon_handle h, @@ -418,6 +439,14 @@ plugin_transaction_validate_all(clicon_handle h, return retval; } +/*! Call single plugin transaction_complete() in a validate/commit transaction + * complete is called after validate (before commit) + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_complete_one(clixon_plugin *cp, clicon_handle h, @@ -493,6 +522,14 @@ plugin_transaction_revert_all(clicon_handle h, return retval; /* ignore errors */ } + +/*! Call single plugin transaction_commit() in a commit transaction + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_commit_one(clixon_plugin *cp, clicon_handle h, @@ -544,6 +581,14 @@ plugin_transaction_commit_all(clicon_handle h, return retval; } + +/*! Call single plugin transaction_commit_done() in a commit transaction + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_commit_done_one(clixon_plugin *cp, clicon_handle h, @@ -588,6 +633,13 @@ plugin_transaction_commit_done_all(clicon_handle h, return retval; } +/*! Call single plugin transaction_end() in a commit/validate transaction + * @param[in] cp Plugin handle + * @param[in] h Clixon handle + * @param[in] td Transaction data + * @retval 0 OK + * @retval -1 Error + */ int plugin_transaction_end_one(clixon_plugin *cp, clicon_handle h, diff --git a/include/clixon_custom.h b/include/clixon_custom.h index fde0bb04..c48090fe 100644 --- a/include/clixon_custom.h +++ b/include/clixon_custom.h @@ -102,7 +102,8 @@ #define STATE_ORDERED_BY_SYSTEM /*! Restart specific backend plugins - * Experimental code for now, needs some testing + * Note, depending on plugin callbacks, there may be other dependencies which may make this + * difficult in the general case. */ #undef RESTART_PLUGIN_RPC @@ -132,5 +133,5 @@ * This is a temporary option which will go away in future releases, therefore * marked as obsolete."; */ -#define USE_STATE_PATH_KLUDGE +#undef USE_STATE_PATH_KLUDGE diff --git a/test/test_xml_validate.sh b/test/test_xml_validate.sh new file mode 100755 index 00000000..adf3fb81 --- /dev/null +++ b/test/test_xml_validate.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Test for XML validations, Mainly Yang encoding +# Mainly negative checks, ie input correct but invalid XML and expect to get +# error message back. +# Triggered by the fact that clixon accepted duplicate containers. + +# Magic line must be first in script (see README.md) +s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi + +: ${clixon_util_xml:="clixon_util_xml -D $DBG"} + +fyang=$dir/example.yang + +cat < $fyang +module example { + yang-version 1.1; + namespace "urn:example:example"; + prefix ex; + revision 2019-01-13; + container a{ + container b{ + leaf c { + type string; + } + } + } +} +EOF + +new "xml unknown yang, fail" +echo "$clixon_util_xml -uy $fyang -vo" +expecteof "$clixon_util_xml -uy $fyang -vo" 0 '' 2> /dev/null + +new "xml double containers no validation, ok" +expecteof "$clixon_util_xml -y $fyang -o" 0 'xy' '^xy$' + +new "xml double containers validation, fail" +expecteof "$clixon_util_xml -y $fyang -vo" 255 'xy' 2> /dev/null +#'xml validation error: protocol operation-failed' + +new "xml double leafs no validation, ok" +expecteof "$clixon_util_xml -y $fyang -o" 0 'xy' 'xy' + +new "xml double leafs validation, fail" +expecteof "$clixon_util_xml -y $fyang -vo" 255 'xy' 2> /dev/null +#'xml validation error: protocol operation-failed' + +rm -rf $dir + +# unset conditional parameters +unset clixon_util_xml