Resolved conflict.

This commit is contained in:
Kristofer Hallin 2021-11-09 08:53:47 +01:00
commit 9ce20ea449
No known key found for this signature in database
GPG key ID: 5A2B21943DE5C500
17 changed files with 310 additions and 40 deletions

View file

@ -185,6 +185,18 @@ module example-augment {
type string;
}
}
/* augment a list */
augment "/if:interfaces" {
list ports{
key id;
leaf id {
type int32;
}
leaf str {
type string;
}
}
}
}
EOF
@ -291,6 +303,30 @@ expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-inte
new "restconf GET augment multi-namespace cross level 2"
expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces/interface=e1/example-augment:ospf/reference-bandwidth)" 0 "HTTP/$HVER 200" '{"example-augment:reference-bandwidth":23}'
new "delete interfaces"
expectpart "$(curl $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces)" 0 "HTTP/$HVER 204"
# augmented lists
XML="<interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\"><mymod:ports xmlns:mymod=\"urn:example:augment\"><mymod:id>22</mymod:id><mymod:str>nisse</mymod:str></mymod:ports><mymod:ports xmlns:mymod=\"urn:example:augment\"><mymod:id>44</mymod:id><mymod:str>kalle</mymod:str></mymod:ports></interfaces>"
new "netconf PUT augmented list"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><edit-config><default-operation>merge</default-operation><target><candidate/></target><config>$XML</config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
new "netconf commit"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><commit/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
new "netconf get config"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><get-config><source><running/></source></get-config></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><data>$XML</data></rpc-reply>]]>]]>"
JSON='{"ietf-interfaces:interfaces":{"example-augment:ports":[{"id":22,"str":"foo"},{"id":44,"str":"bar"}]}}'
new "restconf PUT augmented list"
expectpart "$(curl $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces -d "$JSON")" 0 "HTTP/$HVER 204"
# Escaped [] why?
JSON1='{"ietf-interfaces:interfaces":{"example-augment:ports":\[{"id":22,"str":"foo"},{"id":44,"str":"bar"}\]}}'
new "restconf GET augmented list"
expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+json' $RCPROTO://localhost/restconf/data/ietf-interfaces:interfaces)" 0 "HTTP/$HVER 200" "$JSON1"
if [ $RC -ne 0 ]; then
new "Kill restconf daemon"
stop_restconf

View file

@ -136,7 +136,6 @@ wait_backend
function testparam()
{
# Try hidden parameter list
new "query table parameter hidden"
expectpart "$(echo "set table ?" | $clixon_cli -f $cfg 2>&1)" 0 "set table" "<cr>" --not-- "parameter"
@ -282,6 +281,60 @@ EOF
new "Test hidden parameter in table/param/value augment"
testvalue
# Example using imported module where clixon-lib is NOT declared in main module
# see discussion in ys_populate_unknown (y1 vs y2) and
# https://github.com/clicon/clixon/issues/282
cat <<EOF > $fyang
module example {
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import example-augment{
prefix aug;
}
container table{
list parameter{
key name;
leaf name{
type string;
}
uses aug:pg;
}
}
}
EOF
# Use this as grouping (not annotate)
cat <<EOF > $fyang2
module example-augment {
namespace "urn:example:augment";
prefix aug;
import clixon-lib{
prefix cl;
}
grouping pg {
cl:autocli-op hide; /* This is the extension */
leaf value{
description "a value";
type string;
}
list index{
key i;
leaf i{
type string;
}
leaf iv{
type string;
}
}
}
}
EOF
new "Test hidden parameter in imported module"
testparam
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)

View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash
# Tests for using the auto cli.
# In particular setting a config, displaying as cli commands and reconfigure it
# In particular setting a config, displaying as cli commands and reconfigure it
# Tests:
# Make a config in CLI. Show output as CLI, save it and ensure it is the same
# Try the different GENMODEL settings
@ -15,6 +16,7 @@ APPNAME=example
cfg=$dir/conf_yang.xml
fyang=$dir/$APPNAME.yang
fyang2=$dir/${APPNAME}2.yang
fstate=$dir/state.xml
clidir=$dir/cli
if [ -d $clidir ]; then
@ -25,12 +27,19 @@ fi
# Use yang in example
if [ ! -d "$OPENCONFIG" ]; then
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
echo "...skipped: OPENCONFIG not set"
if [ "$s" = $0 ]; then exit 0; else return 0; fi
fi
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$dir_tmp</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
<CLICON_YANG_DIR>$OPENCONFIG/</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_CLISPEC_DIR>$clidir</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
@ -49,6 +58,9 @@ cat <<EOF > $fyang
module $APPNAME {
namespace "urn:example:clixon";
prefix ex;
import openconfig-extensions { prefix oc-ext; }
/* Set openconfig version to "fake" an openconfig YANG */
oc-ext:openconfig-version;
container table{
list parameter{
key name;
@ -69,6 +81,85 @@ module $APPNAME {
}
}
}
container interfaces {
list interface {
key name;
leaf name {
type string;
}
container config {
leaf enabled {
type boolean;
default false;
description "Whether the interface is enabled or not.";
}
}
container state {
config false;
leaf oper-status {
type enumeration {
enum UP {
value 1;
description "Ready to pass packets.";
}
enum DOWN {
value 2;
description "The interface does not pass any packets.";
}
}
}
}
leaf enabled {
type boolean;
default false;
description "Whether the interface is enabled or not.";
}
}
}
}
EOF
# For openconfig but NO openconfig extension
cat <<EOF > $fyang2
module ${APPNAME}2 {
namespace "urn:example:clixon2";
prefix ex2;
import openconfig-extensions { prefix oc-ext; }
container interfaces2 {
list interface {
key name;
leaf name {
type string;
}
container config {
leaf enabled {
type boolean;
default false;
description "Whether the interface is enabled or not.";
}
}
container state {
config false;
leaf oper-status {
type enumeration {
enum UP {
value 1;
description "Ready to pass packets.";
}
enum DOWN {
value 2;
description "The interface does not pass any packets.";
}
}
}
}
leaf enabled {
type boolean;
default false;
description "Whether the interface is enabled or not.";
}
}
}
}
EOF
@ -127,6 +218,9 @@ function testrun()
elif [ $mode = HIDE ]; then
table=
name=
elif [ $mode = OC_COMPRESS ]; then
table=
name=
else
table=" table"
name=
@ -159,7 +253,7 @@ SAVED=$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show config)
new "delete a x"
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg delete$table parameter$name a value x)" 0 ""
new "show match a & b xml"
new "show match a & b xml"
expectpart "$($clixon_cli -1 -o CLICON_CLI_GENMODEL_TYPE=$mode -f $cfg show xml)" 0 "<table xmlns=\"urn:example:clixon\">" "<parameter>" "<name>a</name>" "</parameter>" "<parameter>" "<name>b</name>" "<value>z</value>" "</parameter>" "</table>" --not-- "<value>x</value>"
new "delete a"
@ -190,6 +284,9 @@ testrun HIDE
new "keywords=ALL"
testrun ALL
new "keywords=OC_COMPRESS"
testrun OC_COMPRESS
new "keywords=VARS"
testrun VARS
@ -201,11 +298,20 @@ new "commit"
expectpart "$($clixon_cli -1 -f $cfg commit)" 0 ""
new "show state"
expectpart "$($clixon_cli -1 -f $cfg show state)" 0 "exstate sender x" "table parameter a" "table parameter a value x"
expectpart "$($clixon_cli -1 -f $cfg show state)" 0 "exstate sender x" "table parameter a" "table parameter a value x"
new "show state exstate"
expectpart "$($clixon_cli -1 -f $cfg show state exstate)" 0 "state sender x" --not-- "table parameter a" "table parameter a value x"
#---- openconfig path compression
new "Openconfig: check no config path"
expectpart "$($clixon_cli -1 -f $cfg set interfaces interface e config enabled true 2>&1)" 255 "Unknown command"
# negative test
new "Openconfig: check exist config path"
expectpart "$($clixon_cli -1 -f $cfg set interfaces2 interface e config enabled true 2>&1)" 0 "^$"
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)