Text syntax parser/loader

Added support for list x y;
Uses a mechanism to parse as unknown XML body and post-parsing replace with list keys
Fixed example and test to work with new TEXT syntax
This commit is contained in:
Olof hagsand 2022-06-02 19:05:12 +02:00
parent 0c79298e76
commit b6bfcb69f7
14 changed files with 227 additions and 377 deletions

View file

@ -300,7 +300,7 @@ edit table
show config text
EOF
new "show config text"
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "parameter {" "name a;" "value 42;"
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "parameter a {" "value 42;"
cat <<EOF > $fin
edit table

View file

@ -72,10 +72,21 @@ show("Show a particular state of the system"){
}
configuration("Show configuration"), cli_auto_show("datamodel", "candidate", "text", true, false);{
cli("Show configuration as CLI commands"), cli_auto_show("datamodel", "candidate", "cli", true, false, "set ");
xml("Show configuration as XML"), cli_auto_show("datamodel", "candidate", "xml", true, false, "set ");
}
}
save("Save candidate configuration to XML file") <filename:string>("Filename (local filename)"), save_config_file("candidate","filename", "xml");
load("Load configuration from XML file") <filename:string>("Filename (local filename)"),load_config_file("filename", "replace");
save("Save candidate configuration to XML file") <filename:string>("Filename (local filename)"), save_config_file("candidate","filename", "xml"){
cli("Save configuration as CLI commands"), save_config_file("candidate","filename", "cli");
xml("Save configuration as XML"), save_config_file("candidate","filename", "xml");
json("Save configuration as JSON"), save_config_file("candidate","filename", "json");
text("Save configuration as TEXT"), save_config_file("candidate","filename", "text");
}
load("Load configuration from XML file") <filename:string>("Filename (local filename)"),load_config_file("filename", "replace");{
cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli");
xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml");
json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json");
text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text");
}
rpc("example rpc") <a:string>("routing instance"), example_client_rpc("");
@ -154,7 +165,7 @@ new "cli success validate"
expectpart "$($clixon_cli -1 -f $cfg -l o validate)" 0 "^$"
new "cli compare diff"
expectpart "$($clixon_cli -1 -f $cfg -l o show compare text)" 0 "+ ip 1.2.3.4;"
expectpart "$($clixon_cli -1 -f $cfg -l o show compare text)" 0 "+ address 1.2.3.4"
new "cli start shell"
expectpart "$($clixon_cli -1 -f $cfg -l o shell echo foo)" 0 "foo"
@ -162,17 +173,19 @@ expectpart "$($clixon_cli -1 -f $cfg -l o shell echo foo)" 0 "foo"
new "cli commit"
expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
new "cli save"
expectpart "$($clixon_cli -1 -f $cfg -l o save $dir/foo)" 0 "^$"
for format in cli json text xml; do
new "cli save $format"
expectpart "$($clixon_cli -1 -f $cfg -l o save $dir/foo $format)" 0 "^$"
new "cli delete all"
expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$"
new "cli delete all"
expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$"
new "cli load"
expectpart "$($clixon_cli -1 -f $cfg -l o load $dir/foo)" 0 "^$"
new "cli load $format"
expectpart "$($clixon_cli -1 -f $cfg -l o load $dir/foo $format)" 0 "^$"
new "cli check load"
expectpart "$($clixon_cli -1 -f $cfg -l o show conf cli)" 0 "interfaces interface eth/0/0 ipv4 enabled true"
new "cli check load"
expectpart "$($clixon_cli -1 -f $cfg -l o show conf cli)" 0 "interfaces interface eth/0/0 ipv4 enabled true"
done
new "cli debug set"
expectpart "$($clixon_cli -1 -f $cfg -l o debug cli 1)" 0 "^$"

View file

@ -1,103 +0,0 @@
#!/usr/bin/env bash
# Test: TEX syntax parser tests.
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${clixon_util_text_syntax:=clixon_util_text_syntax}
: ${clixon_util_xml:=clixon_util_xml}
fyang=$dir/example.yang
cat <<EOF > $fyang
module example{
prefix ex;
namespace "urn:example:clixon";
/* Generic config data */
container table{
list parameter{
key "name index";
leaf name{
type string;
}
leaf index{
type int32;
}
leaf value{
type string;
}
leaf-list array{
type string;
}
}
}
}
EOF
cat <<EOF > $dir/x1.xml
<table xmlns="urn:example:clixon">
<parameter>
<name>a</name>
<index>0</index>
<value>foo bar\n
description</value>
</parameter>
<parameter>
<name>b</name>
<index>17</index>
<value>bar:fie</value>
<array>bar</array>
<array>fie</array>
<array>foo</array>
</parameter>
</table>
EOF
cat <<EOF > $dir/x1.txt
example:table {
parameter {
name a;
index 0;
value "foo bar\n
description";
}
parameter {
name b;
index 17;
value bar:fie;
array [
bar
fie
foo
]
}
}
EOF
new "test params: -y $fyang"
# No yang
new "xml to txt"
expectpart "$($clixon_util_xml -f $dir/x1.xml -y $fyang -oX -D $DBG > $dir/x2.txt)" 0 ""
ret=$(diff $dir/x1.txt $dir/x2.txt)
if [ $? -ne 0 ]; then
err1 "$ret"
fi
new "txt to xml"
expectpart "$($clixon_util_text_syntax -f $dir/x1.txt -y $fyang -D $DBG > $dir/x2.xml)" 0 ""
ret=$(diff $dir/x1.xml $dir/x2.xml)
if [ $? -ne 0 ]; then
err1 "XML" "$ret"
fi
rm -rf $dir
# unset conditional parameters
unset clixon_util_text_syntax
unset clixon_util_xml
new "endtest"
endtest