diff --git a/test/test_restconf_yang_patch.sh b/test/test_restconf_yang_patch.sh index 4253a4df..d472e6ee 100755 --- a/test/test_restconf_yang_patch.sh +++ b/test/test_restconf_yang_patch.sh @@ -7,7 +7,7 @@ # 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" +#echo "...skipped: YANG_PATCH JSON NYI" #if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example @@ -211,22 +211,22 @@ REQ='{ ] } }' -new "RFC 8072 YANG Patch: Error." +new "RFC 8072 YANG Patch JSON: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H 'Content-Type: application/yang-patch+json' -H 'Accept: application/yang-patch+json' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces -d "$REQ")" 0 "HTTP/$HVER 204 No Content" # # Create artist in jukebox example REQ='{"example-jukebox:artist":[{"name":"Foo Fighters"}]}' -new "RFC 8072 YANG Patch jukebox example 1: Error." +new "RFC 8072 YANG Patch JSON jukebox example 1: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Create album in jukebox example REQ='Wasting Light2011' -new "RFC 8072 YANG Patch jukebox example 2: Error." +new "RFC 8072 YANG Patch JSON jukebox example 2: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Add fields to album in jukebox example REQ='{"example-jukebox:album":[{"name":"Wasting Light","genre":"example-jukebox:alternative","year":2011}]}' -new "RFC 8072 YANG Patch jukebox example 3: Error." +new "RFC 8072 YANG Patch JSON jukebox example 3: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters/album=Wasting%20Light -d "$REQ")" 0 "HTTP/$HVER 204 No Content" # Uncomment to get info about album in jukebox example @@ -235,22 +235,22 @@ expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H 'Content-Type: application/ya # Add songs to playlist in jukebox example REQ="{\"example-jukebox:song\":[{\"index\":1,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Rope']\"}]}" -new "RFC 8072 YANG Patch jukebox example 4: Error." +new "RFC 8072 YANG Patch JSON jukebox example 4: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=first -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Add song at end of playlist REQ="{\"example-jukebox:song\":[{\"index\":2,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Bridge Burning']\"}]}" -new "RFC 8072 YANG Patch jukebox example 5: Error." +new "RFC 8072 YANG Patch JSON jukebox example 5: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Add song at end of playlist REQ="{\"example-jukebox:song\":[{\"index\":4,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Still More Rope']\"}]}" -new "RFC 8072 YANG Patch jukebox example 6: Error." +new "RFC 8072 YANG Patch JSON jukebox example 6: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Add song at end of playlist REQ="{\"example-jukebox:song\":[{\"index\":3,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='More Rope']\"}]}" -new "RFC 8072 YANG Patch jukebox example 7: Error." +new "RFC 8072 YANG Patch JSON jukebox example 7: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Run YANG patch on the playlist, testing "insert after" and "insert before" @@ -306,7 +306,7 @@ REQ='{ ] } }' -new "RFC 8072 YANG Patch jukebox example: Error." +new "RFC 8072 YANG Patch JSON jukebox example: Error." expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H 'Content-Type: application/yang-patch+json' -H 'Accept: application/yang-patch+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One -d "$REQ")" 0 "HTTP/$HVER 201 Created" # Uncomment to get info about playlist in jukebox example diff --git a/test/test_restconf_yang_patch_xml.sh b/test/test_restconf_yang_patch_xml.sh new file mode 100755 index 00000000..ffdd757e --- /dev/null +++ b/test/test_restconf_yang_patch_xml.sh @@ -0,0 +1,314 @@ +#!/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 XML 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 +fyangpatch=$dir/ietf-yang-patch.yang +finterfaces=$dir/ietf-interfaces.yang +fexample=$dir/clixon-example.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 + +# Yang Patch spec (fyangpatch must be set) +. ./yang-patch.sh + +# Interfaces spec (finterfaces must be set) +. ./interfaces.sh + +# clixon example spec (fexample must be set) +. ./example.sh + +# 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 + +# Modify several interfaces with a YANG patch, testing create, merge, and delete +REQ=' + test-patch-xml + + edit-1 + create + /interface=eth1 + + + eth1 + clixon-example:eth + false + + + + + edit-2 + create + /interface=eth2 + + + eth2 + clixon-example:eth + false + + + + + edit-3 + create + /interface=eth4 + + + eth4 + clixon-example:eth + false + + + + + edit-4 + merge + /interface=eth2 + + + true + + + + + edit-5 + delete + /interface=eth1 + + ' +new "RFC 8072 YANG Patch XML Media: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H 'Content-Type: application/yang-patch+xml' -H 'Accept: application/yang-patch+xml' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces -d "$REQ")" 0 "HTTP/$HVER 204 No Content" +# +# Create artist in jukebox example +REQ='{"example-jukebox:artist":[{"name":"Foo Fighters"}]}' +new "RFC 8072 YANG Patch jukebox example 1: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Create album in jukebox example +REQ='Wasting Light2011' +new "RFC 8072 YANG Patch jukebox example 2: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+xml' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Add fields to album in jukebox example +REQ='{"example-jukebox:album":[{"name":"Wasting Light","genre":"example-jukebox:alternative","year":2011}]}' +new "RFC 8072 YANG Patch jukebox example 3: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library/artist=Foo%20Fighters/album=Wasting%20Light -d "$REQ")" 0 "HTTP/$HVER 204 No Content" + +# Uncomment to get info about album in jukebox example +#new "RFC 8072 YANG Patch jukebox example get 2: Error." +#expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/library)" 0 "HTTP/$HVER 201 OK" + +# Add songs to playlist in jukebox example +REQ="{\"example-jukebox:song\":[{\"index\":1,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Rope']\"}]}" +new "RFC 8072 YANG Patch jukebox example 4: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=first -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Add song at end of playlist +REQ="{\"example-jukebox:song\":[{\"index\":2,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Bridge Burning']\"}]}" +new "RFC 8072 YANG Patch jukebox example 5: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Add song at end of playlist +REQ="{\"example-jukebox:song\":[{\"index\":4,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Still More Rope']\"}]}" +new "RFC 8072 YANG Patch jukebox example 6: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Add song at end of playlist +REQ="{\"example-jukebox:song\":[{\"index\":3,\"id\":\"/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='More Rope']\"}]}" +new "RFC 8072 YANG Patch jukebox example 7: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One?insert=last -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Run YANG patch on the playlist, testing "insert after" and "insert before" +REQ=' + test-patch-jukebox + + edit-1 + insert + /song=5 + /song=1 + after + + + 5 + Rope Galore + + + + + edit-2 + insert + /song=6 + /song=4 + before + + + 6 + How Much Rope Does a Man Need + + + + edit-3 + insert + /song=24 + /song=6 + before + + + 24 + The twenty-fourth song + + + ' +new "RFC 8072 YANG Patch XML jukebox example: Error." +expectpart "$(curl -u andy:bar $CURLOPTS -X PATCH -H 'Content-Type: application/yang-patch+json' -H 'Accept: application/yang-patch+json' $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One -d "$REQ")" 0 "HTTP/$HVER 201 Created" + +# Uncomment to get info about playlist in jukebox example +#new "RFC 8072 YANG Patch jukebox example get : Error." +#expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example-jukebox:jukebox/playlist=Foo-One)" 0 "HTTP/$HVER 201 OK" + +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