Modified YANG deviate+derived solution
Changed flag to YANG_FLAG_REFINE More complete test
This commit is contained in:
parent
442e0391cc
commit
39fb149756
5 changed files with 108 additions and 85 deletions
|
|
@ -94,7 +94,10 @@
|
||||||
* augment/grouping */
|
* augment/grouping */
|
||||||
#define YANG_FLAG_MYMODULE 0x800 /* Use external map to access my-module for
|
#define YANG_FLAG_MYMODULE 0x800 /* Use external map to access my-module for
|
||||||
* UNKNOWNS and augment/grouping */
|
* UNKNOWNS and augment/grouping */
|
||||||
#define YANG_FLAG_NOORIG 0x1000 /* Node different from orig, do not use orig-link */
|
#define YANG_FLAG_REFINE 0x1000 /* In derived trees from grouping and augments, this node
|
||||||
|
* may be different from orig, therefore do not use link to
|
||||||
|
* original. May also be due to deviations of derived trees
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Types
|
* Types
|
||||||
|
|
|
||||||
|
|
@ -2416,6 +2416,8 @@ yang_deviation(yang_stmt *ys,
|
||||||
/* Make a copy of deviate child and insert. */
|
/* Make a copy of deviate child and insert. */
|
||||||
if ((yc1 = ys_dup(yc)) == NULL)
|
if ((yc1 = ys_dup(yc)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
|
if (yang_apply(yc1, -1, (yang_applyfn_t*)yang_flag_set, -1, (void*)YANG_FLAG_REFINE) < 0)
|
||||||
|
goto done;
|
||||||
if (yn_insert(ytarget, yc1) < 0)
|
if (yn_insert(ytarget, yc1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -2449,7 +2451,8 @@ yang_deviation(yang_stmt *ys,
|
||||||
/* Make a copy of deviate child and insert. */
|
/* Make a copy of deviate child and insert. */
|
||||||
if ((yc1 = ys_dup(yc)) == NULL)
|
if ((yc1 = ys_dup(yc)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
yang_flag_set(yc1, YANG_FLAG_NOORIG);
|
if (yang_apply(yc1, -1, (yang_applyfn_t*)yang_flag_set, -1, (void*)YANG_FLAG_REFINE) < 0)
|
||||||
|
goto done;
|
||||||
if (yn_insert(ytarget, yc1) < 0)
|
if (yn_insert(ytarget, yc1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1486,7 +1486,7 @@ yang_type_get(yang_stmt *ys,
|
||||||
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if ((yorig = yang_orig_get(ys)) != NULL && yang_flag_get(ytype, YANG_FLAG_NOORIG) == 0){
|
if ((yorig = yang_orig_get(ys)) != NULL && yang_flag_get(ytype, YANG_FLAG_REFINE) == 0){
|
||||||
ys = yorig;
|
ys = yorig;
|
||||||
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
|
if ((ytype = yang_find(ys, Y_TYPE, NULL)) == NULL){
|
||||||
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
clixon_err(OE_DB, ENOENT, "mandatory type object is not found");
|
||||||
|
|
|
||||||
|
|
@ -81,56 +81,6 @@ EOF
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# The following test is a special case: A deviation of a grouped type did not appear in
|
|
||||||
# type resolution
|
|
||||||
f=$dir/my.yang
|
|
||||||
cat <<EOF > $f
|
|
||||||
module my {
|
|
||||||
namespace "urn:example:clixon";
|
|
||||||
prefix "ex";
|
|
||||||
|
|
||||||
import "openconfig-network-instance" {
|
|
||||||
prefix "oc-netinst";
|
|
||||||
}
|
|
||||||
deviation "/oc-netinst:network-instances/oc-netinst:network-instance/oc-netinst:protocols/oc-netinst:protocol/oc-netinst:isis/oc-netinst:interfaces/oc-netinst:interface/oc-netinst:levels/oc-netinst:level/oc-netinst:afi-safi/oc-netinst:af/oc-netinst:config/oc-netinst:metric" {
|
|
||||||
description "metric range is restricted";
|
|
||||||
deviate "replace" {
|
|
||||||
type "union" {
|
|
||||||
type "uint32";
|
|
||||||
type "enumeration" {
|
|
||||||
enum "MYTEXT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default "MYTEXT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
modname=$(basename $f | awk -F "." '{print $1}')
|
|
||||||
# Generate autocli for these modules
|
|
||||||
AUTOCLI=$(autocli_config openconfig-* kw-nokey false)
|
|
||||||
|
|
||||||
cat <<EOF > $cfg
|
|
||||||
<clixon-config xmlns="http://clicon.org/config">
|
|
||||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
|
||||||
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
|
|
||||||
<CLICON_YANG_DIR>${OPENCONFIG}</CLICON_YANG_DIR>
|
|
||||||
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
|
|
||||||
<CLICON_YANG_AUGMENT_ACCEPT_BROKEN>true</CLICON_YANG_AUGMENT_ACCEPT_BROKEN>
|
|
||||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
|
||||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
|
||||||
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
|
||||||
<CLICON_SOCK>/usr/local/var/run/$APPNAME.sock</CLICON_SOCK>
|
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
|
||||||
${AUTOCLI}
|
|
||||||
</clixon-config>
|
|
||||||
EOF
|
|
||||||
|
|
||||||
new "deviation: $clixon_cli -D $DBG -1f $cfg -y $f show version"
|
|
||||||
expectpart "$($clixon_cli -D $DBG -1f $cfg -y $f show version)" 0 "${CLIXON_VERSION}"
|
|
||||||
|
|
||||||
rm -rf $dir
|
rm -rf $dir
|
||||||
|
|
||||||
new "endtest"
|
new "endtest"
|
||||||
|
|
|
||||||
|
|
@ -32,38 +32,42 @@ EOF
|
||||||
|
|
||||||
cat <<EOF > $fyangbase
|
cat <<EOF > $fyangbase
|
||||||
module example-base{
|
module example-base{
|
||||||
yang-version 1.1;
|
yang-version 1.1;
|
||||||
prefix base;
|
prefix base;
|
||||||
namespace "urn:example:base";
|
namespace "urn:example:base";
|
||||||
grouping system-top {
|
grouping system-top {
|
||||||
container system {
|
container system {
|
||||||
must "daytime or time"; /* deviate delete removes this */
|
must "daytime or time"; /* deviate delete removes this */
|
||||||
leaf daytime{ /* deviate not-supported removes this */
|
leaf daytime{ /* deviate not-supported removes this */
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
leaf time{
|
leaf time{
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
list name-server {
|
list name-server {
|
||||||
max-elements 1; /* deviate replace replaces to "max.elements 3" here */
|
max-elements 1; /* deviate replace replaces to "max.elements 3" here */
|
||||||
key name;
|
key name;
|
||||||
leaf name {
|
leaf name {
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list user {
|
list user {
|
||||||
key name;
|
key name;
|
||||||
leaf name {
|
leaf name {
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
leaf type {
|
leaf type {
|
||||||
type string;
|
type string;
|
||||||
/* deviate add adds "default admin" here */
|
/* deviate add adds "default admin" here */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
leaf my {
|
||||||
}
|
/* deviate replaces with int and default -42 */
|
||||||
uses system-top;
|
type uint16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uses system-top;
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -242,6 +246,69 @@ EOF
|
||||||
new "5. deviate delete"
|
new "5. deviate delete"
|
||||||
testrun true false false true
|
testrun true false false true
|
||||||
|
|
||||||
|
# Replace example from RFC 7950 Sec 7.20.3.3
|
||||||
|
cat <<EOF > $fyangdev
|
||||||
|
module example-deviations{
|
||||||
|
yang-version 1.1;
|
||||||
|
prefix md;
|
||||||
|
namespace "urn:example:deviations";
|
||||||
|
import example-base {
|
||||||
|
prefix base;
|
||||||
|
}
|
||||||
|
deviation /base:system/base:my {
|
||||||
|
deviate replace {
|
||||||
|
type int8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviation /base:system/base:my {
|
||||||
|
deviate add {
|
||||||
|
default -42;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
new "6. deviate replace default"
|
||||||
|
|
||||||
|
if [ "$BE" -ne 0 ]; then
|
||||||
|
new "kill old backend"
|
||||||
|
sudo clixon_backend -zf "$cfg"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
err
|
||||||
|
fi
|
||||||
|
new "start backend -s init -f $cfg"
|
||||||
|
start_backend -s init -f "$cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
new "wait backend"
|
||||||
|
wait_backend
|
||||||
|
|
||||||
|
new "show default value, expect deviated"
|
||||||
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">report-all</with-defaults><source><running/></source><filter type=\"xpath\" select=\"/base:system/base:my\" xmlns:base=\"urn:example:base\"/></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><system xmlns=\"urn:example:base\"><my>-42</my></system></data></rpc-reply>"
|
||||||
|
|
||||||
|
new "set negative value"
|
||||||
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><system xmlns=\"urn:example:base\"><daytime>Sept17</daytime><my>-77</my></system></config></edit-config></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
|
new "netconf validate ok"
|
||||||
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><validate><source><candidate/></source></validate></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
|
new "set large value"
|
||||||
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><system xmlns=\"urn:example:base\"><my>98735</my></system></config></edit-config></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
|
||||||
|
|
||||||
|
new "netconf validate expect fail"
|
||||||
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><validate><source><candidate/></source></validate></rpc>" "" "<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>my</bad-element></error-info><error-severity>error</error-severity><error-message>Number 98735 out of range: -128 - 127</error-message></rpc-error></rpc-reply>"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
|
|
||||||
new "endtest"
|
new "endtest"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue