From 600f29a11771d2c211b284d90b77a1a19d385ea6 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 26 Jul 2021 12:20:06 +0200 Subject: [PATCH] - Added yang patch test: test_restconf_yang_patch.sh as placeholder for rfc 8072 tests - Added patch-xml as valid media --- apps/restconf/restconf_methods.c | 7 +- test/test_restconf_yang_patch.sh | 205 +++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+), 4 deletions(-) create mode 100755 test/test_restconf_yang_patch.sh diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 3d9630bb..355f77e3 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -1203,16 +1203,15 @@ api_data_patch(clicon_handle h, ret = api_data_write(h, req, api_path0, pcvec, pi, qvec, data, pretty, media_in, media_out, 1, ds); break; - case YANG_PATCH_XML: - ret = restconf_notimplemented(h, req, pretty, media_out); - break; case YANG_PATCH_JSON: /* RFC 8072 patch */ + case YANG_PATCH_XML: #ifdef YANG_PATCH ret = api_data_yang_patch(h, req, api_path0, pcvec, pi, qvec, data, pretty, media_out, ds); #else - ret = restconf_unsupported_media(h, req, pretty, media_out); + ret = restconf_notimplemented(h, req, pretty, media_out); #endif + break; break; default: ret = restconf_unsupported_media(h, req, pretty, media_out); diff --git a/test/test_restconf_yang_patch.sh b/test/test_restconf_yang_patch.sh new file mode 100755 index 00000000..6d91704a --- /dev/null +++ b/test/test_restconf_yang_patch.sh @@ -0,0 +1,205 @@ +#!/usr/bin/env bash +# Restconf RFC8072 yang patch +# XXX enable YANG_PACTH in include/clixon_custom.h to run this test +# Use nacm module in example/main/example_restconf.c hardcoded to +# andy:bar and wilma:bar + +# Magic line must be first in script (see README.md) +s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi + +echo "...skipped: YANG_PATCH NYI" +if [ "$s" = $0 ]; then exit 0; else return 0; fi + +APPNAME=example + +cfg=$dir/conf.xml +startupdb=$dir/startup_db +fjukebox=$dir/example-jukebox.yang + +# Define default restconfig config: RESTCONFIG +RESTCONFIG=$(restconf_config user false) + +cat < $cfg + + $cfg + /usr/local/share/clixon + $IETFRFC + $dir + /usr/local/var/$APPNAME/$APPNAME.sock + ietf-netconf:startup + /usr/local/lib/$APPNAME/restconf + $dir/restconf.pidfile + $dir + internal + true + $RESTCONFIG + +EOF + +NACM0=" + true + deny + deny + permit + + + admin + andy + + + limited + wilma + + + + admin + admin + + permit-all + * + * + permit + + Allow the 'admin' group complete access to all operations and data. + + + + + limited + limited + + limit-jukebox + jukebox-example + read create delete + deny + + + +" + +cat< $startupdb +<${DATASTORE_TOP}> + $NACM0 + +EOF + +# An extra testmodule that includes nacm +cat < $dir/example-system.yang + module example-system { + namespace "http://example.com/ns/example-system"; + prefix "ex"; + import ietf-netconf-acm { + prefix nacm; + } + container system { + leaf enable-jukebox-streaming { + type boolean; + } + leaf extraleaf { + type string; + } + } + } +EOF + +# Common Jukebox spec (fjukebox must be set) +. ./jukebox.sh + +new "test params: -s startup -f $cfg" +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -zf $cfg + if [ $? -ne 0 ]; then + err + fi + sudo pkill -f clixon_backend # to be sure + + new "start backend -s startup -f $cfg" + start_backend -s startup -f $cfg +fi + +new "wait backend" +wait_backend + +if [ $RC -ne 0 ]; then + new "kill old restconf daemon" + stop_restconf_pre + + new "start restconf daemon" + start_restconf -f $cfg +fi + +new "wait restconf" +wait_restconf + +# RFC 8072 A.1.1 +REQ=' + add-songs-patch + + edit1 + create + /song=Bridge%20Burning + + + Bridge Burning + /media/bridge_burning.mp3 + MP3 + 288 + + + + + edit2 + create + /song=Rope + + + Rope + /media/rope.mp3 + MP3 + 259 + + + + + edit3 + create + /song=Dear%20Rosemary + + + Dear Rosemary + /media/dear_rosemary.mp3 + MP3 + 269 + + + + ' + +new "RFC 8072 A.1.1 Add resources: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H 'Content-Type: application/yang-patch+xml' -H 'Accept: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters/album=Wasting%20Light -d "$REQ")" 0 "HTTP/$HVER 409" + + +if [ $RC -ne 0 ]; then + new "Kill restconf daemon" + stop_restconf +fi + +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg +fi + +# Set by restconf_config +unset RESTCONFIG + +rm -rf $dir + +new "endtest" +endtest