* Yang parser is stricter (see cardinality below) which may break parsing of slack yang specs.

* YANG parser cardinality checked (only modules level yet)
  * See https://github.com/clicon/clixon/issues/48
This commit is contained in:
Olof hagsand 2018-11-18 20:55:57 +01:00
parent 9c57902b96
commit a8f0aad411
28 changed files with 159 additions and 47 deletions

View file

@ -142,11 +142,10 @@ EOF
echo -e "\e[0m:"
exit -1
fi
# If error dont match output strings
if [ $r != 0 ]; then
return
fi
# If error dont match output strings (why not?)
# if [ $r != 0 ]; then
# return
# fi
# Match if both are empty string
if [ -z "$ret" -a -z "$expect" ]; then
return

View file

@ -10,6 +10,9 @@ datastore=../datastore/datastore_client
cat <<EOF > $fyang
module ietf-ip{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ip;
container x {
list y {
key "a b";

View file

@ -28,6 +28,8 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-routing {
prefix rt;
@ -93,7 +95,7 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><validate><source><candid
new "netconf disabled feature"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><candidate/></target><config><A>foo</A></config></edit-config></rpc>]]>]]>" '^<rpc-reply><rpc-error><error-tag>operation-failed</error-tag><error-type>protocol</error-type><error-severity>error</error-severity><error-message>XML node config/A has no corresponding yang specification (Invalid XML or wrong Yang spec?'
# This test has been broken up into all differetn modules instead of one large
# This test has been broken up into all different modules instead of one large
# reply since the modules change so often
new "netconf schema resource, RFC 7895"
ret=$($clixon_netconf -qf $cfg -y $fyang<<EOF
@ -101,7 +103,7 @@ ret=$($clixon_netconf -qf $cfg -y $fyang<<EOF
EOF
)
new "netconf module A"
expect="<module><name>example</name><revision/><namespace/><feature>A</feature><conformance-type>implement</conformance-type></module>"
expect="<module><name>example</name><revision/><namespace>urn:example:clixon</namespace><feature>A</feature><conformance-type>implement</conformance-type></module>"
match=`echo "$ret" | grep -GZo "$expect"`
if [ -z "$match" ]; then
err "$expect" "$ret"

View file

@ -24,6 +24,8 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
prefix if;

View file

@ -26,6 +26,9 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container c{
presence true;
list a0{

View file

@ -31,6 +31,8 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-netconf-acm {
prefix nacm;

View file

@ -37,6 +37,8 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container authentication {
description "Example code for enabling www basic auth and some example

View file

@ -30,6 +30,8 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
prefix if;

View file

@ -41,6 +41,9 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container c{
leaf d{
type string;

View file

@ -24,6 +24,9 @@ fconfig=$dir/config
cat <<EOF > $fyang
module ietf-ip{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ip;
container x {
list y {
key "a";

View file

@ -30,6 +30,8 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
prefix if;

View file

@ -22,6 +22,9 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
container cont1{
list interface{
key name;

View file

@ -26,6 +26,9 @@ EOF
cat <<EOF > $fyang
module example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
typedef ab {
type string {
pattern

View file

@ -27,6 +27,8 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
identity routing-protocol {
description

View file

@ -79,13 +79,13 @@ new "XMLdecl no version"
expecteof "$PROG" 255 '<?xml ?><a/>' ''
new "XMLdecl misspelled version"
expecteof "$PROG" 255 '<?xml verion="1.0"?><a/>' '<a/>'
expecteof "$PROG -l o" 255 '<?xml verion="1.0"?><a/>' 'yntax error: at or before: v'
new "XMLdecl version + encoding"
expecteof "$PROG" 0 '<?xml version="1.0" encoding="UTF-16"?><a/>' '<a/>'
new "XMLdecl version + misspelled encoding"
expecteof "$PROG" 255 '<?xml version="1.0" encding="UTF-16"?><a/>' '<a/>'
expecteof "$PROG -l o" 255 '<?xml version="1.0" encding="UTF-16"?><a/>' 'syntax error: at or before: e'
new "XMLdecl version + standalone"
expecteof "$PROG" 0 '<?xml version="1.0" standalone="yes"?><a/>' '<a/>'

View file

@ -27,7 +27,9 @@ EOF
cat <<EOF > $fyang
module $APPNAME{
yang-version 1.1;
prefix ex;
namespace "urn:example:clixon";
extension c-define {
description "Example from RFC 6020";
argument "name";
@ -89,6 +91,8 @@ EOF
# This yang definition uses an extension which is not defined. Error when loading
cat <<EOF > $fyangerr
module $APPNAME{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
extension c-define {
description "Example from RFC 6020";
@ -126,7 +130,9 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><cand
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "cli not defined extension"
#new "cli not defined extension"
#new "netconf not defined extension"
#expecteof "$clixon_netconf -qf $cfg -l o" 0 "$YANG" "Extension ex:not-defined not found"
# This text yields an error, but the test cannot detect the error message yet
#expectfn "$clixon_cli -1f $cfg -y $fyangerr show version" 0 "Yang error: Extension ex:not-defined not found"

View file

@ -1,41 +1,26 @@
#!/bin/bash
# Test: YANG parser tests
# First an example yang, second all openconfig yangs
# Problem with this is that util only parses single file. it should
# call yang_parse().
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_yang"
PROG=../util/clixon_util_yang
OPENCONFIG=~/syssrc/openconfig
exit 0 # nyi
# include err() and new() functions and creates $dir
. ./lib.sh
YANG=$(cat <<EOF
module test{
prefix ex;
extension c-define {
description "Example from RFC 6020";
argument "name";
}
ex:not-defined ARGUMENT;
}
EOF
)
new "yang parse"
#expecteof "$PROG" 0 "$YANG" "^$YANG$"
if [ ! -d $OPENCONFIG ]; then
echo "$OPENCONFIG not found. Do git clone https://github.com/openconfig/public and point DIR to it to run these tests"
rm -rf $dir
exit 0
fi
# Openconfig
# Files not parseable:
# - openconfig-access-points.yang
# - openconfig-access-points.yang
new "Openconfig"
files=$(find $OPENCONFIG -name "*.yang")
for f in $files; do
new "$f"
YANG=$(cat $f)
# expecteof "$PROG" 0 "$YANG" "module"
# NYI
expecteof "$PROG" 0 "$YANG" "module"
done
rm -rf $dir