* Changed base OS in clixon-system container to Alpine

* Moved datastore/text/ code to datastore/ since there is only one type of datastore.
* Added "magic script line" to test script for sourced and scriped exits
This commit is contained in:
Olof Hagsand 2019-02-13 21:33:40 +01:00
parent 9fc8ac2e8e
commit d64d433468
58 changed files with 579 additions and 538 deletions

8
.gitignore vendored
View file

@ -7,9 +7,9 @@ lex.*_parse.c
Makefile Makefile
apps/Makefile apps/Makefile
apps/*/Makefile apps/*/Makefile
datastore/Makefile
docker/Makefile docker/Makefile
docker/base/Makefile docker/*/Makefile
docker/system/Makefile
etc/Makefile etc/Makefile
example/Makefile example/Makefile
lib/Makefile lib/Makefile
@ -34,10 +34,6 @@ apps/netconf/clixon_netconf
apps/restconf/clixon_restconf apps/restconf/clixon_restconf
apps/xmldb/clixon_xmldb apps/xmldb/clixon_xmldb
docker/backend/Dockerfile
docker/cli/Dockerfile
docker/netconf/Dockerfile
etc/clixonrc etc/clixonrc
include/clixon_config.h include/clixon_config.h

View file

@ -128,6 +128,7 @@
* XML prolog syntax for 'well-formed' XML * XML prolog syntax for 'well-formed' XML
* `<!DOCTYPE` (ie DTD) is not supported. * `<!DOCTYPE` (ie DTD) is not supported.
* Added Clixon example full system docker container, see [docker/system](docker/system). * Added Clixon example full system docker container, see [docker/system](docker/system).
* Moved datastore/text/ code to datastore/ since there is only one type of datastore.
* Changed clixon base system container to use Alpine [docker/base](docker/base). * Changed clixon base system container to use Alpine [docker/base](docker/base).
* clixon-config YAML file has new revision: 2019-02-06. * clixon-config YAML file has new revision: 2019-02-06.
* Added new log function: `clicon_log_xml()` for logging XML tree * Added new log function: `clicon_log_xml()` for logging XML tree
@ -521,7 +522,6 @@ enables saved files to be used as datastore without any editing. Thanks Matt, Ne
* New configuration option: CLICON_RESTCONF_PRETTY. Default true. Set to false to get more compact Restconf output. * New configuration option: CLICON_RESTCONF_PRETTY. Default true. Set to false to get more compact Restconf output.
* Default configure file handling generalized by Renato Botelho/Matt Smith. Config file FILE is selected in the following priority order: * Default configure file handling generalized by Renato Botelho/Matt Smith. Config file FILE is selected in the following priority order:
* Provide -f FILE option when starting a program (eg clixon_backend -f FILE) * Provide -f FILE option when starting a program (eg clixon_backend -f FILE)
* Provide --with-configfile=FILE when configuring * Provide --with-configfile=FILE when configuring

View file

@ -52,7 +52,7 @@ INSTALL = @INSTALL@
INCLUDES = -I. -I@srcdir@ @INCLUDES@ INCLUDES = -I. -I@srcdir@ @INCLUDES@
SHELL = /bin/sh SHELL = /bin/sh
SUBDIRS = lib apps include etc datastore util yang SUBDIRS = lib apps include etc datastore yang
.PHONY: doc example all clean depend $(SUBDIRS) install loc TAGS .config.status docker test .PHONY: doc example all clean depend $(SUBDIRS) install loc TAGS .config.status docker test

View file

@ -45,7 +45,6 @@ bindir = @bindir@
libdir = @libdir@ libdir = @libdir@
mandir = @mandir@ mandir = @mandir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
wwwdir = /www-data
localstatedir = @localstatedir@ localstatedir = @localstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
includedir = @includedir@ includedir = @includedir@

View file

@ -50,6 +50,7 @@ sysconfdir = @sysconfdir@
includedir = @includedir@ includedir = @includedir@
HOST_VENDOR = @host_vendor@ HOST_VENDOR = @host_vendor@
# XXX why is not wwwdir under prefix?
wwwdir = @wwwdir@ wwwdir = @wwwdir@
wwwuser = @wwwuser@ wwwuser = @wwwuser@
@ -100,7 +101,7 @@ distclean: clean
# Put other executables in libexec/ # Put other executables in libexec/
# Also create a libexec/ directory for writeable/temporary files. # Also create a libexec/ directory for writeable/temporary files.
# Put config file in etc/ # Put config file in etc/
# Also a rule for letting www-dir be owned by www-data, which only orks for sudo # Also a rule for letting www-dir be owned by www-data, which only works for sudo
install: install-lib $(APPL) install: install-lib $(APPL)
ifeq ($(shell whoami),root) ifeq ($(shell whoami),root)
install -d -m 0755 -o $(wwwuser) -g $(wwwuser) $(DESTDIR)$(wwwdir) install -d -m 0755 -o $(wwwuser) -g $(wwwuser) $(DESTDIR)$(wwwdir)

View file

@ -61,11 +61,11 @@
#include <fcntl.h> #include <fcntl.h>
#include <time.h> #include <time.h>
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <libgen.h> #include <libgen.h>
#include <sys/stat.h> /* chmod */
/* cligen */ /* cligen */
#include <cligen/cligen.h> #include <cligen/cligen.h>
@ -694,6 +694,11 @@ main(int argc,
clicon_err(OE_CFG, errno, "FCGX_OpenSocket"); clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
goto done; goto done;
} }
/* umask settings may interfer: we want group to write: this is 774 */
if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){
clicon_err(OE_UNIX, errno, "chmod");
goto done;
}
if (FCGX_InitRequest(r, sock, 0) != 0){ if (FCGX_InitRequest(r, sock, 0) != 0){
clicon_err(OE_CFG, errno, "FCGX_InitRequest"); clicon_err(OE_CFG, errno, "FCGX_InitRequest");
goto done; goto done;

17
configure vendored
View file

@ -715,6 +715,7 @@ with_cligen
enable_stdyangs enable_stdyangs
enable_publish enable_publish
with_restconf with_restconf
with_wwwuser
with_configfile with_configfile
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
@ -1362,6 +1363,7 @@ Optional Packages:
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-cligen=dir Use CLIGEN here --with-cligen=dir Use CLIGEN here
--without-restconf disable support for restconf --without-restconf disable support for restconf
--with-wwwuser=<user> Set www user different from www-data
--with-configfile=FILE set default path to config file --with-configfile=FILE set default path to config file
Some influential environment variables: Some influential environment variables:
@ -4170,6 +4172,18 @@ fi
fi fi
# This is for changing web user default www-data
# Check whether --with-wwwuser was given.
if test "${with_wwwuser+set}" = set; then :
withval=$with_wwwuser;
fi
if test "${with_wwwuser}"; then
wwwuser=${with_wwwuser}
fi
echo "wwwuser:$wwwuser"
# Set default config file location # Set default config file location
CLIXON_DEFAULT_CONFIG=/usr/local/etc/clixon.xml CLIXON_DEFAULT_CONFIG=/usr/local/etc/clixon.xml
@ -4433,7 +4447,7 @@ _ACEOF
ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile extras/rpm/Makefile docker/Makefile docker/system/Makefile docker/base/Makefile datastore/Makefile datastore/text/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/standard/Makefile doc/Makefile test/Makefile" ac_config_files="$ac_config_files Makefile lib/Makefile lib/src/Makefile lib/clixon/Makefile apps/Makefile apps/cli/Makefile apps/backend/Makefile apps/netconf/Makefile apps/restconf/Makefile include/Makefile etc/Makefile etc/clixonrc example/Makefile extras/rpm/Makefile docker/Makefile docker/system/Makefile docker/base/Makefile datastore/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/standard/Makefile doc/Makefile test/Makefile"
cat >confcache <<\_ACEOF cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure # This file is a shell script that caches the results of configure
@ -5145,7 +5159,6 @@ do
"docker/system/Makefile") CONFIG_FILES="$CONFIG_FILES docker/system/Makefile" ;; "docker/system/Makefile") CONFIG_FILES="$CONFIG_FILES docker/system/Makefile" ;;
"docker/base/Makefile") CONFIG_FILES="$CONFIG_FILES docker/base/Makefile" ;; "docker/base/Makefile") CONFIG_FILES="$CONFIG_FILES docker/base/Makefile" ;;
"datastore/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/Makefile" ;; "datastore/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/Makefile" ;;
"datastore/text/Makefile") CONFIG_FILES="$CONFIG_FILES datastore/text/Makefile" ;;
"util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;; "util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;;
"yang/Makefile") CONFIG_FILES="$CONFIG_FILES yang/Makefile" ;; "yang/Makefile") CONFIG_FILES="$CONFIG_FILES yang/Makefile" ;;
"yang/clixon/Makefile") CONFIG_FILES="$CONFIG_FILES yang/clixon/Makefile" ;; "yang/clixon/Makefile") CONFIG_FILES="$CONFIG_FILES yang/clixon/Makefile" ;;

View file

@ -191,6 +191,14 @@ if test "x${with_restconf}" == xyes; then
AC_CHECK_LIB(fcgi, FCGX_Init,, AC_MSG_ERROR([libfcgi-dev missing])) AC_CHECK_LIB(fcgi, FCGX_Init,, AC_MSG_ERROR([libfcgi-dev missing]))
fi fi
# This is for changing web user default www-data
AC_ARG_WITH([wwwuser],
[AS_HELP_STRING([--with-wwwuser=<user>],[Set www user different from www-data])])
if test "${with_wwwuser}"; then
wwwuser=${with_wwwuser}
fi
echo "wwwuser:$wwwuser"
# Set default config file location # Set default config file location
CLIXON_DEFAULT_CONFIG=/usr/local/etc/clixon.xml CLIXON_DEFAULT_CONFIG=/usr/local/etc/clixon.xml
AC_ARG_WITH([configfile], AC_ARG_WITH([configfile],
@ -245,7 +253,6 @@ AC_OUTPUT(Makefile
docker/system/Makefile docker/system/Makefile
docker/base/Makefile docker/base/Makefile
datastore/Makefile datastore/Makefile
datastore/text/Makefile
util/Makefile util/Makefile
yang/Makefile yang/Makefile
yang/clixon/Makefile yang/clixon/Makefile

View file

@ -30,7 +30,6 @@
# #
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
# #
VPATH = @srcdir@
prefix = @prefix@ prefix = @prefix@
datarootdir = @datarootdir@ datarootdir = @datarootdir@
srcdir = @srcdir@ srcdir = @srcdir@
@ -43,78 +42,60 @@ mandir = @mandir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
HOST_VENDOR = @host_vendor@
VPATH = @srcdir@
CC = @CC@ CC = @CC@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@ -rdynamic -fPIC
INSTALLFLAGS = @INSTALLFLAGS@ INSTALLFLAGS = @INSTALLFLAGS@
LDFLAGS = @LDFLAGS@ LDFLAGS = @LDFLAGS@
LIBS = @LIBS@ LIBS = @LIBS@
with_restconf = @with_restconf@ DATASTORE = text
SH_SUFFIX = @SH_SUFFIX@
CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@
CLIXON_MINOR = @CLIXON_VERSION_MINOR@
# Use this clixon lib for linking
CLIXON_LIB = libclixon.so.$(CLIXON_MAJOR).$(CLIXON_MINOR)
# For dependency
LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
LIBS = -L$(top_srcdir)/lib/src @LIBS@ $(top_srcdir)/lib/src/$(CLIXON_LIB)
CPPFLAGS = @CPPFLAGS@ CPPFLAGS = @CPPFLAGS@
INCLUDES = -I. -I$(top_srcdir)/lib/src -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@ INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
PLUGIN = $(DATASTORE).so
SUBDIRS = text SRC = clixon_xmldb_text.c
.PHONY: all clean depend install $(SUBDIRS) OBJS = $(SRC:.c=.o)
APPSRC = datastore_client.c all: $(PLUGIN)
APPOBJ = $(APPSRC:.c=.o)
APPL = datastore_client
all: $(SUBDIRS) $(APPL) $(PLUGIN): $(SRC)
ifeq ($(HOST_VENDOR),apple)
$(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) $(LDFLAGS) -shared -undefined dynamic_lookup -o $@ -lc $^ $(LIBS)
else
$(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) $(LDFLAGS) -shared -o $@ -lc $^ $(LIBS)
endif
clean:
rm -f $(PLUGIN) $(OBJS) *.core
distclean: clean
rm -f Makefile *~ .depend
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .o .SUFFIXES: .c .o
.c.o: .c.o: $(SRC)
$(CC) $(INCLUDES) -D__PROGRAM__=\"$(APPL)\" $(CPPFLAGS) $(CFLAGS) -c $< $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
$(APPL) : $(APPOBJ) $(LIBDEPS) install: $(PLUGIN)
$(CC) $(LDFLAGS) $(APPOBJ) $(LIBS) -o $@ install -d -m 0755 $(DESTDIR)$(libdir)/xmldb
install -m 0644 $(INSTALLFLAGS) $(PLUGIN) $(DESTDIR)$(libdir)/xmldb
depend:
for i in $(SUBDIRS); \
do (cd $$i; $(MAKE) $(MFLAGS) $@); done
$(SUBDIRS):
(cd $@; $(MAKE) $(MFLAGS) all)
install-include: install-include:
for i in $(SUBDIRS); \
do (cd $$i ; $(MAKE) $(MFLAGS) $@)||exit 1; done;
install: uninstall:
for i in $(SUBDIRS); \ rm -rf $(DESTDIR)$(libdir)/xmldb/$(PLUGIN)
do (cd $$i && $(MAKE) $(MFLAGS) $@)||exit 1; done
uninstall:
for i in $(SUBDIRS); \
do (cd $$i && $(MAKE) $(MFLAGS) $@)||exit 1; done
clean:
rm -f *.core $(APPL) $(APPOBJ)
for i in $(SUBDIRS); \
do (cd $$i; $(MAKE) $(MFLAGS) $@); done
distclean: clean
rm -f Makefile *~ .depend
for i in $(SUBDIRS); \
do (cd $$i; $(MAKE) $(MFLAGS) $@); done
TAGS: TAGS:
find $(srcdir) -name '*.[chyl]' -print | etags - find . -name '*.[chyl]' -print | etags -
depend:
$(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(SRC) > .depend
#include .depend

View file

@ -1,101 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
#
# Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
#
# This file is part of CLIXON
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Alternatively, the contents of this file may be used under the terms of
# the GNU General Public License Version 3 or later (the "GPL"),
# in which case the provisions of the GPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of the GPL, and not to allow others to
# use your version of this file under the terms of Apache License version 2,
# indicate your decision by deleting the provisions above and replace them with
# the notice and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the Apache License version 2 or the GPL.
#
# ***** END LICENSE BLOCK *****
#
prefix = @prefix@
datarootdir = @datarootdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
dbdir = @prefix@/db
mandir = @mandir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
sysconfdir = @sysconfdir@
HOST_VENDOR = @host_vendor@
VPATH = @srcdir@
CC = @CC@
CFLAGS = @CFLAGS@ -rdynamic -fPIC
INSTALLFLAGS = @INSTALLFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
DATASTORE = text
CPPFLAGS = @CPPFLAGS@
INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
PLUGIN = $(DATASTORE).so
SRC = clixon_xmldb_text.c
OBJS = $(SRC:.c=.o)
all: $(PLUGIN)
$(PLUGIN): $(SRC)
ifeq ($(HOST_VENDOR),apple)
$(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) $(LDFLAGS) -shared -undefined dynamic_lookup -o $@ -lc $^ $(LIBS)
else
$(CC) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) $(LDFLAGS) -shared -o $@ -lc $^ $(LIBS)
endif
clean:
rm -f $(PLUGIN) $(OBJS) *.core
distclean: clean
rm -f Makefile *~ .depend
.SUFFIXES:
.SUFFIXES: .c .o
.c.o: $(SRC)
$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
install: $(PLUGIN)
install -d -m 0755 $(DESTDIR)$(libdir)/xmldb
install -m 0644 $(INSTALLFLAGS) $(PLUGIN) $(DESTDIR)$(libdir)/xmldb
install-include:
uninstall:
rm -rf $(DESTDIR)$(libdir)/xmldb/$(PLUGIN)
TAGS:
find . -name '*.[chyl]' -print | etags -
depend:
$(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(SRC) > .depend
#include .depend

View file

@ -37,11 +37,9 @@ MAINTAINER Olof Hagsand <olof@hagsand.se>
# For clixon and cligen # For clixon and cligen
RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev
# Create a directory to hold source-code, dependencies etc # Create a directory to hold source-code, dependencies etc
RUN mkdir /clixon RUN mkdir /clixon
RUN mkdir /clixon/build RUN mkdir /clixon/build
WORKDIR /clixon WORKDIR /clixon
# Clone cligen # Clone cligen
@ -58,37 +56,54 @@ RUN mkdir /clixon/clixon
WORKDIR /clixon/clixon WORKDIR /clixon/clixon
COPY clixon . COPY clixon .
# Build clixon (without restconf if you dont have nginx) # Need to add www user manually
RUN ./configure --without-restconf --prefix=/clixon/build --with-cligen=/clixon/build RUN adduser -D -H www-data
# nginx adds group www-data
RUN apk add --update nginx
# Configure, build and install clixon
RUN ./configure --prefix=/clixon/build --with-cligen=/clixon/build --with-wwwuser=www-data
RUN make RUN make
RUN make install RUN make install
RUN make install-include RUN make install-include
# Build and install the clixon example (not really necessary for base)
WORKDIR /clixon/clixon/example WORKDIR /clixon/clixon/example
RUN DESTDIR=/clixon/build make RUN make
RUN make install RUN make install
RUN install example.xml /clixon/build/etc/clixon.xml
# #
# Stage 2 # Stage 2
# #
FROM alpine FROM alpine
MAINTAINER Olof Hagsand <olof@hagsand.se> MAINTAINER Olof Hagsand <olof@hagsand.se>
# For clixon and cligen # For clixon and cligen
RUN apk add --update flex bison # fcgi-dev curl-dev RUN apk add --update flex bison fcgi-dev
# Run a clicon group - actually an application may want another # need to add www user manually
RUN adduser -D -H www-data
# nginx adds group www-data
RUN apk add --update nginx
# Test-specific (for test scripts)
#RUN apk add --update sudo curl bash
# Expose nginx port for restconf
EXPOSE 80
# Create clicon group
RUN addgroup clicon RUN addgroup clicon
RUN adduser nginx clicon
RUN adduser www-data clicon
COPY --from=0 /clixon/build/ /usr/local/ COPY --from=0 /clixon/build/ /usr/local/
COPY --from=0 /www-data /www-data
# For debug # Manually created
#RUN apk add --update bash nano RUN chown www-data /www-data
RUN chgrp www-data /www-data

View file

@ -12,23 +12,24 @@ See [clixon-system](../system/README.md) for a more complete clixon image.
## Build and push ## Build and push
Perform the build by `make docker`. Perform the build by `make docker`. This copies the latest _committed_ clixon code into the container.
You may also do `make push` if you want to push the image, but you may then consider changing the image name (in the makefile:s).
You may run the container directly by going directly to example and You may also do `make push` if you want to push the image, but you may then consider changing the image name (in the makefile:s).
the docker runtime scripts there
(You may have to login for push with sudo docker login -u <username>) (You may have to login for push with sudo docker login -u <username>)
## Example run ## Example run
The following shows a simple example of how to run the example The base container is a minimal and primitive example. Look at the [clixon-system](../system) for a more stream-lined application.
application. First,the container is started, then the backend is startend in the background inside the container, and finally the CLI is started in the foreground.
The following shows a simple example of how to run the example
application. First, the container is started with the backend running:
``` ```
$ sudo docker run --name clixon --rm -td clixon/clixon $ sudo docker run --rm --name clixon-base -d clixon/clixon clixon_backend -Fs init
$ sudo docker exec -it clixon clixon_backend -s init -f /usr/local/etc/example.xml ```
$ sudo docker exec -it clixon clixon_cli -f /usr/local/etc/example.xml Then a CLI is started, and finally the container is removed:
```
$ sudo docker exec -it clixon-base clixon_cli
> set interfaces interface e > set interfaces interface e
> show configuration > show configuration
interfaces { interfaces {
@ -38,10 +39,10 @@ application. First,the container is started, then the backend is startend in the
} }
} }
> q > q
$ sudo docker kill clixon $ sudo docker kill clixon-base
``` ```
Note that this is a special case since the example is Note that the clixon example application is a special case since the example is
already a part of the installation. If you want to add your own already a part of the installation. If you want to add your own
application, such as plugins, cli syntax files, yang models, etc, you application, such as plugins, cli syntax files, yang models, etc, you
need to extend the base container with your own additions. need to extend the base container with your own additions.

16
docker/base/start.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
# Usage: ./startup.sh
# Debug: DBG=1 ./startup.sh
# See also cleanup.sh
>&2 echo "Running script: $0"
# Start clixon-example backend
sudo docker run --name clixon --rm -td clixon/clixon || err "Error starting clixon"
>&2 echo "clixon started"

View file

@ -31,34 +31,23 @@
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
# #
# This application could use the base image, but it does not at this point. FROM alpine
FROM debian
MAINTAINER Olof Hagsand <olof@hagsand.se> MAINTAINER Olof Hagsand <olof@hagsand.se>
# Clixon dependenies (not needed if build from base) # For clixon and cligen
RUN apt-get update && apt-get install -y \ RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev
git make gcc flex bison \
libfcgi-dev \
libcurl4-openssl-dev
# Application-specific
RUN apt-get update && apt-get install -y nginx
# Test-specific (for test scripts)
RUN apt-get update && apt-get install -y sudo curl procps time
# The example uses "clicon" group
RUN groupadd clicon
RUN usermod -a -G clicon www-data
# Create a directory to hold source-code, dependencies etc # Create a directory to hold source-code, dependencies etc
RUN mkdir /clixon RUN mkdir /clixon
RUN mkdir /clixon/build
WORKDIR /clixon WORKDIR /clixon
# Clone and build cligen (not necessary if use base image) # Clone cligen
RUN git clone https://github.com/olofhagsand/cligen.git RUN git clone https://github.com/olofhagsand/cligen.git
# Build cligen
WORKDIR /clixon/cligen WORKDIR /clixon/cligen
RUN ./configure RUN ./configure --prefix=/clixon/build
RUN make RUN make
RUN make install RUN make install
@ -67,30 +56,69 @@ RUN mkdir /clixon/clixon
WORKDIR /clixon/clixon WORKDIR /clixon/clixon
COPY clixon . COPY clixon .
RUN ./configure # Need to add www user manually
RUN adduser -D -H www-data
# nginx adds group www-data
RUN apk add --update nginx
# Configure, build and install clixon
RUN ./configure --prefix=/clixon/build --with-cligen=/clixon/build --with-wwwuser=www-data
RUN make RUN make
RUN make install RUN make install
RUN make install-include RUN make install-include
# Install utils
WORKDIR /clixon/clixon/util
RUN make
RUN make install
# Build and install the clixon example
WORKDIR /clixon/clixon/example WORKDIR /clixon/clixon/example
RUN make RUN make
RUN make install RUN make install
RUN install example.xml /usr/local/etc/clixon.xml RUN install example.xml /clixon/build/etc/clixon.xml
RUN ldconfig # Copy tests
WORKDIR /clixon/clixon/test
RUN install -d /clixon/build/bin/test
RUN install *.sh /clixon/build/bin/test
# Copy startscript # Copy startscript
WORKDIR /clixon WORKDIR /clixon
COPY startsystem.sh startsystem.sh COPY startsystem.sh startsystem.sh
RUN install startsystem.sh /usr/local/bin/ RUN install startsystem.sh /clixon/build/bin/
#
# Stage 2
#
FROM alpine
MAINTAINER Olof Hagsand <olof@hagsand.se>
# For clixon and cligen
RUN apk add --update flex bison fcgi-dev
# need to add www user manually
RUN adduser -D -H www-data
# nginx adds group www-data
RUN apk add --update nginx
# Test-specific (for test scripts)
RUN apk add --update sudo curl procps grep make bash
# Expose nginx port for restconf # Expose nginx port for restconf
EXPOSE 80 EXPOSE 80
# Create clicon group
RUN addgroup clicon
RUN adduser nginx clicon
RUN adduser www-data clicon
COPY --from=0 /clixon/build/ /usr/local/
COPY --from=0 /www-data /www-data
# Manually created
RUN chown www-data /www-data
RUN chgrp www-data /www-data
# Log to stderr. # Log to stderr.
CMD /usr/local/bin/startsystem.sh CMD /usr/local/bin/startsystem.sh

View file

@ -67,7 +67,7 @@ push:
# Start the clixon system container and run the test script # Start the clixon system container and run the test script
test: docker test: docker
./cleanup.sh ; PORT=8080 ./start.sh # kill (ignore error) and the start it ./cleanup.sh ; PORT=8080 ./start.sh # kill (ignore error) and the start it
sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test && ./all.sh' sudo docker exec -it clixon-system bash -c 'cd /usr/local/bin/test && ./all.sh'
depend: depend:

View file

@ -52,7 +52,7 @@ As restconf using curl on exposed port 80:
``` ```
Or run tests: Or run tests:
``` ```
$ sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test&& ./all.sh' $ sudo docker exec -it clixon-system bash -c 'cd /usr/local/bin/test&& ./all.sh'
``` ```
To check status and then kill it: To check status and then kill it:

View file

@ -11,6 +11,8 @@
DBG=${DBG:-0} DBG=${DBG:-0}
WWWUSER=${WWWUSER:-www-data}
# Initiate clixon configuration (env variable) # Initiate clixon configuration (env variable)
echo "$CONFIG" > /usr/local/etc/clixon.xml echo "$CONFIG" > /usr/local/etc/clixon.xml
@ -19,7 +21,7 @@ echo "$STORE" > /usr/local/var/example/running_db
>&2 echo "Write nginx config files" >&2 echo "Write nginx config files"
# nginx site config file # nginx site config file
cat <<EOF > /etc/nginx/sites-enabled/default cat <<EOF > /etc/nginx/conf.d/default.conf
# #
server { server {
listen 80 default_server; listen 80 default_server;
@ -28,7 +30,6 @@ server {
server_name localhost; server_name localhost;
server_name _; server_name _;
location / { location / {
root /usr/share/nginx/html/restconf;
fastcgi_pass unix:/www-data/fastcgi_restconf.sock; fastcgi_pass unix:/www-data/fastcgi_restconf.sock;
include fastcgi_params; include fastcgi_params;
} }
@ -46,13 +47,17 @@ server {
EOF EOF
# This is a clixon site test file. Disable all model testing. # This is a clixon site test file. Disable all model testing.
cat <<EOF > /clixon/clixon/test/site.sh cat <<EOF > /usr/local/bin/test/site.sh
# Add your local site specific env variables (or tests) here. # Add your local site specific env variables (or tests) here.
MODELS=0 # Dont run yangmodels/openconfig tests SKIPLIST="test_yangmodels.sh test_openconfig.sh test_install.sh test_order.sh"
IETFRFC=/clixon/clixon/yang/standard #IETFRFC=
EOF EOF
chmod 775 /usr/local/bin/test/site.sh
if [ ! -d /run/nginx ]; then
mkdir /run/nginx
fi
# Start nginx # Start nginx
#/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf #/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
@ -60,9 +65,12 @@ EOF
>&2 echo "nginx started" >&2 echo "nginx started"
# Start clixon_restconf # Start clixon_restconf
su -c "/www-data/clixon_restconf -l f/www-data/restconf.log -D $DBG" -s /bin/sh www-data & su -c "/www-data/clixon_restconf -l f/www-data/restconf.log -D $DBG" -s /bin/sh $WWWUSER &
>&2 echo "clixon_restconf started" >&2 echo "clixon_restconf started"
# Set grp write XXX do this when creating
chmod g+w /www-data/fastcgi_restconf.sock
# Start clixon backend # Start clixon backend
>&2 echo "start clixon_backend:" >&2 echo "start clixon_backend:"
/usr/local/sbin/clixon_backend -FD $DBG -s running -l e # logs on docker logs /usr/local/sbin/clixon_backend -FD $DBG -s running -l e # logs on docker logs

View file

@ -21,7 +21,22 @@ application. Assumes setup of http daemon as describe under apps/restonf
- test_datastore.sh Datastore tests - test_datastore.sh Datastore tests
- and many more... - and many more...
Tests called 'test*.sh' and placed in this directory will be automatically run as part of the all.sh, sum.sh tests etc. Tests called 'test_*.sh' and placed in this directory will be
automatically run as part of the all.sh, sum.sh tests etc. The scripts need to follow some rules to work properly, such as add this magic line as the first command line in the script, which ensures it works well when started from `all.sh`:
```
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
```
You need to build and install the clixon utility programs before running the tests as some of the tests rely on them:
```
cd util
make
sudo make install
```
You need to start nginx for some of the text. There are instructions in
* If you run systemd: `sudo systemctl start nginx.service`
* The [example](../example/README.md) has instructions
You can prefix a test with `BE=0` if you want to run your own backend. You can prefix a test with `BE=0` if you want to run your own backend.
@ -37,14 +52,16 @@ Run all tests but continue after errors and only print a summary test output ide
all.sh summary all.sh summary
``` ```
You need to start nginx. There are instructions in [the example](../example/README.md)
Example site.sh file: Example site.sh file:
```
# Add your local site specific env variables (or tests) here.
# Add test to this list that you dont want run
SKIPLIST="test_openconfig.sh test_yangmodels.sh"
# Parse yang openconfig models from https://github.com/openconfig/public
OPENCONFIG=/home/olof/src/clixon/test/public
# Parse yangmodels from https://github.com/YangModels/yang
YANGMODELS=/usr/local/share/yangmodels
# Standard IETF RFC yang files.
IETFRFC=$YANGMODELS/standard/ietf/RFC
```
#!/bin/bash
# Add your local site specific env variables (or tests) here.
# get from: https://github.com/openconfig/public
OPENCONFIG=/home/olof/src/clixon/test/public
# get from: https://github.com/YangModels/yang
YANGMODELS=/usr/local/share/yangmodels
IETFRFC=$YANGMODELS/standard/ietf/RFC

View file

@ -7,12 +7,11 @@ if [ $# -gt 0 ]; then
exit -1 exit -1
fi fi
# include err() and new() functions
. ./lib.sh
err=0 err=0
testnr=0
for test in test*.sh; do for test in test*.sh; do
echo "Running $test" testfile=$test
./$test . ./$test
errcode=$? errcode=$?
if [ $errcode -ne 0 ]; then if [ $errcode -ne 0 ]; then
err=1 err=1

View file

@ -12,18 +12,34 @@
#set -e #set -e
# Probe nginx # Testfile (not including path)
#sudo systemctl status nginx.service > /dev/null : ${testfile:=$(basename $0)}
#if [ $? -ne 0 ]; then
# sudo systemctl start nginx.service # Add test to this list that you dont want run
#fi # Typically add them in your site file
: ${SKIPLIST:=""}
>&2 echo "Running $testfile"
# Site file, an example of this file in README.md # Site file, an example of this file in README.md
if [ -x ./site.sh ]; then if [ -x ./site.sh ]; then
. ./site.sh . ./site.sh
if [ $? -ne 0 ]; then
return -1 # skip
fi
# test skiplist.
for f in $SKIPLIST; do
if [ "$testfile" = "$f" ]; then
return -1 # skip
fi
done
fi fi
testnr=0 # Running test number
: ${testnr:=0}
# Single test. Set by "new"
testname= testname=
# If set to 0, override starting of clixon_backend in test (you bring your own) # If set to 0, override starting of clixon_backend in test (you bring your own)
@ -36,11 +52,6 @@ testname=
# eg logging to a file: RCLOG="-l f/www-data/restconf.log" # eg logging to a file: RCLOG="-l f/www-data/restconf.log"
: ${RCLOG:=} : ${RCLOG:=}
# If reset, do NOT run tests with external yang models.
# This involves downloading
# https://github.com/openconfig/public and https://github.com/YangModels/yang
: ${MODELS:=1}
# Parse yangmodels from https://github.com/YangModels/yang # Parse yangmodels from https://github.com/YangModels/yang
# Recommended: checkout yangmodels elsewhere in the tree and set the env # Recommended: checkout yangmodels elsewhere in the tree and set the env
# to that # to that

View file

@ -7,16 +7,14 @@ if [ $# -gt 0 ]; then
exit -1 exit -1
fi fi
# include err() and new() functions
. ./lib.sh
err=0 err=0
for test in test*.sh; do for testfile in test*.sh; do # For lib.sh the variable must be called testfile
echo "Running $test" echo "Running $testfile"
./$test > /dev/null 2>&1 ./$testfile > /dev/null 2>&1
errcode=$? errcode=$?
if [ $errcode -ne 0 ]; then if [ $errcode -ne 0 ]; then
err=1 err=1
echo -e "\e[31mError in $test errcode=$errcode" echo -e "\e[31mError in $testfile errcode=$errcode"
echo -ne "\e[0m" echo -ne "\e[0m"
fi fi
done done

View file

@ -6,9 +6,10 @@
# Use-case: The ietf-netconf edit-config has a shorthand version of choice w mandatory: # Use-case: The ietf-netconf edit-config has a shorthand version of choice w mandatory:
# container { choice target { mandatory; leaf candidate; leaf running; }} # container { choice target { mandatory; leaf candidate; leaf running; }}
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/choice.xml cfg=$dir/choice.xml
fyang=$dir/type.yang fyang=$dir/type.yang
@ -95,7 +96,7 @@ if [ $BE -ne 0 ]; then
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
err err
fi fi
pkill clixon_backend # to be sure sudo pkill clixon_backend # to be sure
new "start backend -s init -f $cfg -y $fyang" new "start backend -s init -f $cfg -y $fyang"
sudo $clixon_backend -s init -f $cfg -y $fyang sudo $clixon_backend -s init -f $cfg -y $fyang

View file

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
# Test1: backend and cli basic functionality # Test1: backend and cli basic functionality
# Start backend server # Start backend server
# Add an ethernet interface and an address # Add an ethernet interface and an address
@ -8,9 +7,13 @@
# Set the mandatory type # Set the mandatory type
# Commit # Commit
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir # include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
# Use yang in example # Use yang in example

View file

@ -3,9 +3,11 @@
# 1) Load <3.9 startup/running/extra files without namespaces - ensure it returns namespaces # 1) Load <3.9 startup/running/extra files without namespaces - ensure it returns namespaces
# #
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_startup.xml cfg=$dir/conf_startup.xml
# Use yang in example # Use yang in example
@ -29,7 +31,6 @@ cat <<EOF > $cfg
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN> <CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN>
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING> <CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE> <CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
<CLICON_XML_SORT>true</CLICON_XML_SORT>
</config> </config>
EOF EOF

View file

@ -1,12 +1,15 @@
#!/bin/bash #!/bin/bash
# Test5: datastore tests. # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# datastore tests.
# Just run a binary direct to datastore. No clixon. # Just run a binary direct to datastore. No clixon.
# include err() and new() functions and creates $dir
. ./lib.sh
fyang=$dir/ietf-ip.yang fyang=$dir/ietf-ip.yang
datastore=../datastore/datastore_client # If set, enable debugging (of backend)
: ${clixon_util_datastore:=clixon_util_datastore}
: ${clixon_datastore_lib:=/usr/local/lib/xmldb/text.so}
cat <<EOF > $fyang cat <<EOF > $fyang
module ietf-ip{ module ietf-ip{
@ -46,126 +49,124 @@ module ietf-ip{
} }
EOF EOF
xml='<config><x xmlns="urn:example:clixon"><y><a>1</a><b>2</b><c>first-entry</c></y><y><a>1</a><b>3</b><c>second-entry</c></y><y><a>2</a><b>3</b><c>third-entry</c></y><d/><f><e>a</e><e>b</e><e>c</e></f><g>astring</g></x></config>' xml='<config><x xmlns="urn:example:clixon"><y><a>1</a><b>2</b><c>first-entry</c></y><y><a>1</a><b>3</b><c>second-entry</c></y><y><a>2</a><b>3</b><c>third-entry</c></y><d/><f><e>a</e><e>b</e><e>c</e></f><g>astring</g></x></config>'
run(){
name=$1
mydir=$dir/$name
if [ ! -d $mydir ]; then name=text
mkdir $mydir
fi
rm -rf $mydir/*
conf="-d candidate -b $mydir -p ../datastore/$name/$name.so -y $dir/ietf-ip.yang"
new "datastore $name init"
expectfn "$datastore $conf init" 0 ""
new "datastore $name put all replace" mydir=$dir/$name
ret=$($datastore $conf put replace "$xml")
expectmatch "$ret" $? "0" ""
new "datastore $name get" if [ ! -d $mydir ]; then
expectfn "$datastore $conf get /" 0 "^$xml$" mkdir $mydir
fi
rm -rf $mydir/*
new "datastore $name put all remove" # XXX static link
expectfn "$datastore $conf put remove <config/>" 0 "" conf="-d candidate -b $mydir -p $clixon_datastore_lib -y $dir/ietf-ip.yang"
new "datastore $name get" new "datastore init"
expectfn "$datastore $conf get /" 0 "^<config/>$" expectfn "$clixon_util_datastore $conf init" 0 ""
new "datastore $name put all merge" new "datastore put all replace"
ret=$($datastore $conf put merge "$xml") ret=$($clixon_util_datastore $conf put replace "$xml")
expectmatch "$ret" $? "0" "" expectmatch "$ret" $? "0" ""
# expectfn "$datastore $conf put merge $xml" 0 ""
new "datastore $name get" new "datastore get"
expectfn "$datastore $conf get /" 0 "^$xml$" expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
new "datastore $name put all delete" new "datastore put all remove"
expectfn "$datastore $conf put remove <config/>" 0 "" expectfn "$clixon_util_datastore $conf put remove <config/>" 0 ""
new "datastore $name get" new "datastore get"
expectfn "$datastore $conf get /" 0 "^<config/>$" expectfn "$clixon_util_datastore $conf get /" 0 "^<config/>$"
new "datastore $name put all create" new "datastore put all merge"
ret=$($datastore $conf put create "$xml") ret=$($clixon_util_datastore $conf put merge "$xml")
expectmatch "$ret" $? "0" "" expectmatch "$ret" $? "0" ""
new "datastore $name get" # expectfn "$clixon_util_datastore $conf put merge $xml" 0 ""
expectfn "$datastore $conf get /" 0 "^$xml$"
new "datastore $name put top create" new "datastore get"
expectfn "$datastore $conf put create <config><x/></config>" 0 "" # error expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
# Single key operations new "datastore put all delete"
# leaf expectfn "$clixon_util_datastore $conf put remove <config/>" 0 ""
new "datastore $name put all delete"
expectfn "$datastore $conf delete" 0 ""
new "datastore $name init" new "datastore get"
expectfn "$datastore $conf init" 0 "" expectfn "$clixon_util_datastore $conf get /" 0 "^<config/>$"
new "datastore $name create leaf" new "datastore put all create"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" ret=$($clixon_util_datastore $conf put create "$xml")
expectmatch "$ret" $? "0" ""
new "datastore $name create leaf" new "datastore get"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$"
new "datastore $name delete leaf" new "datastore put top create"
expectfn "$datastore $conf put delete <config><x><y><a>1</a><b>3</b></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put create <config><x/></config>" 0 "" # error
new "datastore $name replace leaf" # Single key operations
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" # leaf
new "datastore put all delete"
expectfn "$clixon_util_datastore $conf delete" 0 ""
new "datastore $name remove leaf" new "datastore init"
expectfn "$datastore $conf put remove <config><x><g/></x></config>" 0 "" expectfn "$clixon_util_datastore $conf init" 0 ""
new "datastore $name remove leaf" new "datastore create leaf"
expectfn "$datastore $conf put remove <config><x><y><a>1</a><b>3</b><c/></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name delete leaf" new "datastore create leaf"
expectfn "$datastore $conf put delete <config><x><g/></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name merge leaf" new "datastore delete leaf"
expectfn "$datastore $conf put merge <config><x><g>nalle</g></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put delete <config><x><y><a>1</a><b>3</b></y></x></config>" 0 ""
new "datastore $name replace leaf" new "datastore replace leaf"
expectfn "$datastore $conf put replace <config><x><g>nalle</g></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore $name merge leaf" new "datastore remove leaf"
expectfn "$datastore $conf put merge <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put remove <config><x><g/></x></config>" 0 ""
new "datastore $name replace leaf" new "datastore remove leaf"
expectfn "$datastore $conf put replace <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put remove <config><x><y><a>1</a><b>3</b><c/></y></x></config>" 0 ""
new "datastore $name create leaf" new "datastore delete leaf"
expectfn "$datastore $conf put create <config><x><h><j>aaa</j></h></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put delete <config><x><g/></x></config>" 0 ""
new "datastore $name create leaf" new "datastore merge leaf"
expectfn "$datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 "" expectfn "$clixon_util_datastore $conf put merge <config><x><g>nalle</g></x></config>" 0 ""
new "datastore other db init" new "datastore replace leaf"
expectfn "$datastore -d kalle -b $mydir -p ../datastore/$name/$name.so -y $dir/ietf-ip.yang init" 0 "" expectfn "$clixon_util_datastore $conf put replace <config><x><g>nalle</g></x></config>" 0 ""
new "datastore other db copy" new "datastore merge leaf"
expectfn "$datastore $conf copy kalle" 0 "" expectfn "$clixon_util_datastore $conf put merge <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
diff $mydir/kalle_db $mydir/candidate_db new "datastore replace leaf"
expectfn "$clixon_util_datastore $conf put replace <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore lock" new "datastore create leaf"
expectfn "$datastore $conf lock 756" 0 "" expectfn "$clixon_util_datastore $conf put create <config><x><h><j>aaa</j></h></x></config>" 0 ""
new "datastore create leaf"
expectfn "$clixon_util_datastore $conf put create <config><x><y><a>1</a><b>3</b><c>newentry</c></y></x></config>" 0 ""
new "datastore other db init"
expectfn "$clixon_util_datastore -d kalle -b $mydir -p $clixon_datastore_lib -y $dir/ietf-ip.yang init" 0 ""
new "datastore other db copy"
expectfn "$clixon_util_datastore $conf copy kalle" 0 ""
diff $mydir/kalle_db $mydir/candidate_db
new "datastore lock"
expectfn "$clixon_util_datastore $conf lock 756" 0 ""
#leaf-list #leaf-list
rm -rf $mydir rm -rf $mydir
}
run text
rm -rf $dir rm -rf $dir

View file

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
# Yang features. if-feature. and schema resources according to RFC7895 # Yang features. if-feature. and schema resources according to RFC7895
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/test.yang fyang=$dir/test.yang

View file

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
# Identity and identityref tests # Identity and identityref tests
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/example-my-crypto.yang fyang=$dir/example-my-crypto.yang

View file

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
# Install test # Install system test
# include err() and new() functions and creates $dir # Magic line must be first in script (see README.md)
. ./lib.sh s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
new "Set up installdir $dir" new "Set up installdir $dir"

View file

@ -2,21 +2,21 @@
# Test: JSON parser tests # Test: JSON parser tests
# Note that nmbers shouldnot be quoted. See test_restconf2.sh for typed # Note that nmbers shouldnot be quoted. See test_restconf2.sh for typed
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_json" #PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_json"
PROG=../util/clixon_util_json # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# include err() and new() functions and creates $dir : ${clixon_util_json:=clixon_util_json}
. ./lib.sh
new "json parse to xml" new "json parse to xml"
expecteofx "$PROG" 0 '{"foo": -23}' "<foo>-23</foo>" expecteofx "$clixon_util_json" 0 '{"foo": -23}' "<foo>-23</foo>"
new "json parse to json" # should be {"foo": -23} new "json parse to json" # should be {"foo": -23}
expecteofx "$PROG -j" 0 '{"foo": -23}' '{"foo": "-23"}' expecteofx "$clixon_util_json -j" 0 '{"foo": -23}' '{"foo": "-23"}'
new "json parse list xml" new "json parse list xml"
expecteofx "$PROG" 0 '{"a":[0,1,2,3]}' "<a>0</a><a>1</a><a>2</a><a>3</a>" expecteofx "$clixon_util_json" 0 '{"a":[0,1,2,3]}' "<a>0</a><a>1</a><a>2</a><a>3</a>"
new "json parse list json" # should be {"a":[0,1,2,3]} new "json parse list json" # should be {"a":[0,1,2,3]}
expecteofx "$PROG -j" 0 '{"a":[0,1,2,3]}' '{"a": "0"}{"a": "1"}{"a": "2"}{"a": "3"}' expecteofx "$clixon_util_json -j" 0 '{"a":[0,1,2,3]}' '{"a": "0"}{"a": "1"}{"a": "2"}{"a": "3"}'
rm -rf $dir rm -rf $dir

View file

@ -1,8 +1,11 @@
#!/bin/bash #!/bin/bash
# Test7: Yang specifics: leafref # Yang leafref test
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/leafref.yang fyang=$dir/leafref.yang

View file

@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
# Yang list / leaf-list operations. min/max-elements # Yang list / leaf-list operations. min/max-elements
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/test.yang fyang=$dir/test.yang

View file

@ -3,9 +3,12 @@
# See RFC 8341 A.2 # See RFC 8341 A.2
# But replaced ietf-netconf-monitoring with * # But replaced ietf-netconf-monitoring with *
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh # Common NACM scripts
. ./nacm.sh . ./nacm.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml

View file

@ -4,9 +4,11 @@
# See RFC 8341 A.2 # See RFC 8341 A.2
# But replaced ietf-netconf-monitoring with * # But replaced ietf-netconf-monitoring with *
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir # Common NACM scripts
. ./lib.sh
. ./nacm.sh . ./nacm.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml

View file

@ -18,9 +18,12 @@
# all content in the server. No subsequent rule will match for the # all content in the server. No subsequent rule will match for the
# "admin" group because of this module rule # "admin" group because of this module rule
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh # Common NACM scripts
. ./nacm.sh . ./nacm.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml

View file

@ -20,9 +20,12 @@
# update | p/d | p/d | p/d # update | p/d | p/d | p/d
# delete | p/d | p/d | p/d # delete | p/d | p/d | p/d
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh # Common NACM scripts
. ./nacm.sh . ./nacm.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml

View file

@ -23,9 +23,12 @@
# Which means that restconf -X DELETE /data translates to edit-config + commit # Which means that restconf -X DELETE /data translates to edit-config + commit
# which is allowed. # which is allowed.
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh # Common NACM scripts
. ./nacm.sh . ./nacm.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml

View file

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
# Test2: backend and netconf basic functionality # Basic Netconf functionality
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
tmp=$dir/tmp.x tmp=$dir/tmp.x

View file

@ -7,15 +7,11 @@
# - Env-var MODELS should be 1 # - Env-var MODELS should be 1
# - Env-var OPENCONFIG should point to checkout place. (define it in site.sh for example) # - Env-var OPENCONFIG should point to checkout place. (define it in site.sh for example)
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
if [ $MODELS -eq 0 ]; then
exit
fi
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/test.yang fyang=$dir/test.yang
@ -104,7 +100,7 @@ for f in $files; do
exit exit
fi fi
done done
echo "m:$ms s:$ss"
new "Openconfig test: $clixon_cli -1f $cfg -y $f show version ($m modules)" new "Openconfig test: $clixon_cli -1f $cfg -y $f show version ($m modules)"
for f in $files; do for f in $files; do
if [ -n "$(head -1 $f|grep '^module')" ]; then if [ -n "$(head -1 $f|grep '^module')" ]; then

View file

@ -5,9 +5,12 @@
# The ordered-by user MUST be the order it is entered. # The ordered-by user MUST be the order it is entered.
# No test of ordered-by system is done yet # No test of ordered-by system is done yet
# (we may want to sort them alphabetically for better performance). # (we may want to sort them alphabetically for better performance).
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/order.yang fyang=$dir/order.yang
tmp=$dir/tmp.x tmp=$dir/tmp.x
@ -36,7 +39,6 @@ cat <<EOF > $cfg
<CLICON_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION> <CLICON_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION>
<CLICON_XMLDB_DIR>$dbdir</CLICON_XMLDB_DIR> <CLICON_XMLDB_DIR>$dbdir</CLICON_XMLDB_DIR>
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN> <CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN>
<CLICON_XML_SORT>true</CLICON_XML_SORT>
</config> </config>
EOF EOF
@ -152,7 +154,7 @@ EOF
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "$(cat $tmp)" '<rpc-reply><data><state xmlns="urn:example:clixon"><op>42</op><op>41</op><op>43</op></state></data></rpc-reply>]]>]]>' expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "$(cat $tmp)" '<rpc-reply><data><state xmlns="urn:example:clixon"><op>42</op><op>41</op><op>43</op></state></data></rpc-reply>]]>]]>'
# Check as file # Check as file
new "verify running from start, should be: c,l,y0,y1,y2,y3; y1 and y3 sorted. Note this fails if CLICON_XML_SORT set to false" new "verify running from start, should be: c,l,y0,y1,y2,y3; y1 and y3 sorted."
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' '^<rpc-reply><data><c xmlns="urn:example:order"><d>hej</d></c><l xmlns="urn:example:order">hopp</l><y0 xmlns="urn:example:order">d</y0><y0 xmlns="urn:example:order">b</y0><y0 xmlns="urn:example:order">c</y0><y0 xmlns="urn:example:order">a</y0><y1 xmlns="urn:example:order">a</y1><y1 xmlns="urn:example:order">b</y1><y1 xmlns="urn:example:order">c</y1><y1 xmlns="urn:example:order">d</y1><y2 xmlns="urn:example:order"><k>d</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>a</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>c</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>b</k><a>bar</a></y2><y3 xmlns="urn:example:order"><k>a</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>b</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>c</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>d</k><a>bar</a></y3><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>lo</name><type>ex:loopback</type><enabled>true</enabled></interface></interfaces></data></rpc-reply>]]>]]>$' expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><get-config><source><running/></source></get-config></rpc>]]>]]>' '^<rpc-reply><data><c xmlns="urn:example:order"><d>hej</d></c><l xmlns="urn:example:order">hopp</l><y0 xmlns="urn:example:order">d</y0><y0 xmlns="urn:example:order">b</y0><y0 xmlns="urn:example:order">c</y0><y0 xmlns="urn:example:order">a</y0><y1 xmlns="urn:example:order">a</y1><y1 xmlns="urn:example:order">b</y1><y1 xmlns="urn:example:order">c</y1><y1 xmlns="urn:example:order">d</y1><y2 xmlns="urn:example:order"><k>d</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>a</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>c</k><a>bar</a></y2><y2 xmlns="urn:example:order"><k>b</k><a>bar</a></y2><y3 xmlns="urn:example:order"><k>a</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>b</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>c</k><a>bar</a></y3><y3 xmlns="urn:example:order"><k>d</k><a>bar</a></y3><interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"><interface><name>lo</name><type>ex:loopback</type><enabled>true</enabled></interface></interfaces></data></rpc-reply>]]>]]>$'
new "get each ordered-by user leaf-list" new "get each ordered-by user leaf-list"

View file

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# Scaling test # Scaling/ performance tests
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
number=5000 number=5000
req=100 req=100
@ -15,8 +18,6 @@ else
exit 1 # Scaling exit 1 # Scaling
fi fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/scaling-conf.xml cfg=$dir/scaling-conf.xml
fyang=$dir/scaling.yang fyang=$dir/scaling.yang

View file

@ -1,9 +1,12 @@
#!/bin/bash #!/bin/bash
# Restconf basic functionality # Restconf basic functionality
# Assume http server setup, such as nginx described in apps/restconf/README.md # Assume http server setup, such as nginx described in apps/restconf/README.md
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf.xml cfg=$dir/conf.xml
# Use yang in example # Use yang in example

View file

@ -1,9 +1,12 @@
#!/bin/bash #!/bin/bash
# Restconf basic functionality # Restconf basic functionality
# Assume http server setup, such as nginx described in apps/restconf/README.md # Assume http server setup, such as nginx described in apps/restconf/README.md
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf.xml cfg=$dir/conf.xml
fyang=$dir/restconf.yang fyang=$dir/restconf.yang

View file

@ -5,10 +5,12 @@
# Use the example application that has one mandatory input arg, # Use the example application that has one mandatory input arg,
# At the end is an alternative Yang without mandatory arg for # At the end is an alternative Yang without mandatory arg for
# valid empty input and output. # valid empty input and output.
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf.xml cfg=$dir/conf.xml
# Use yang in example # Use yang in example

View file

@ -5,9 +5,12 @@
# - An extra xml configuration file starts with an "extra" interface # - An extra xml configuration file starts with an "extra" interface
# - running db starts with a "run" interface # - running db starts with a "run" interface
# - startup db starts with a "start" interface # - startup db starts with a "start" interface
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_startup.xml cfg=$dir/conf_startup.xml
cat <<EOF > $cfg cat <<EOF > $cfg
@ -29,7 +32,6 @@ cat <<EOF > $cfg
<CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN> <CLICON_XMLDB_PLUGIN>/usr/local/lib/xmldb/text.so</CLICON_XMLDB_PLUGIN>
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING> <CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE> <CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
<CLICON_XML_SORT>true</CLICON_XML_SORT>
</config> </config>
EOF EOF

View file

@ -20,16 +20,15 @@
# 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications # 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications
# Note the sleeps are mainly for valgrind usage # Note the sleeps are mainly for valgrind usage
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
UTIL=../util/clixon_util_stream : ${clixon_util_stream:=clixon_util_stream}
NCWAIT=5 # Wait (netconf valgrind may need more time) NCWAIT=5 # Wait (netconf valgrind may need more time)
if [ ! -x $UTIL ]; then
(cd ../util; make clixon_util_stream)
fi
DATE=$(date +"%Y-%m-%d") DATE=$(date +"%Y-%m-%d")
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf.xml cfg=$dir/conf.xml
fyang=$dir/stream.yang fyang=$dir/stream.yang
xml=$dir/xml.xml xml=$dir/xml.xml
@ -181,7 +180,7 @@ expectwait 'curl -s -X GET -H "Accept: text/event-stream" -H "Cache-Control: no-
# 2a) start subscription 8s - expect 1-2 notifications # 2a) start subscription 8s - expect 1-2 notifications
new "2a) start subscriptions 8s - expect 1-2 notifications" new "2a) start subscriptions 8s - expect 1-2 notifications"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 8) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 8)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")
@ -197,7 +196,7 @@ sleep 2
# 2b) start subscription 8s - stoptime after 5s - expect 1-2 notifications # 2b) start subscription 8s - stoptime after 5s - expect 1-2 notifications
new "2b) start subscriptions 8s - stoptime after 5s - expect 1-2 notifications" new "2b) start subscriptions 8s - stoptime after 5s - expect 1-2 notifications"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 8 -e +10) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 8 -e +10)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")
if [ -z "$match" ]; then if [ -z "$match" ]; then
@ -210,7 +209,7 @@ fi
# 2c # 2c
new "2c) start sub 8s - replay from start -8s - expect 3-4 notifications" new "2c) start sub 8s - replay from start -8s - expect 3-4 notifications"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 10 -s -8) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 10 -s -8)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")
if [ -z "$match" ]; then if [ -z "$match" ]; then
@ -223,7 +222,7 @@ fi
# 2d) start sub 8s - replay from start -8s to stop +4s - expect 3 notifications # 2d) start sub 8s - replay from start -8s to stop +4s - expect 3 notifications
new "2d) start sub 8s - replay from start -8s to stop +4s - expect 3 notifications" new "2d) start sub 8s - replay from start -8s to stop +4s - expect 3 notifications"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 10 -s -30 -e +4) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 10 -s -30 -e +4)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")
if [ -z "$match" ]; then if [ -z "$match" ]; then
@ -236,7 +235,7 @@ fi
# 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications # 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications
new "2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications" new "2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 10 -s -90 -e +0) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 10 -s -90 -e +0)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")
if [ -z "$match" ]; then if [ -z "$match" ]; then
@ -254,7 +253,7 @@ curl -s -X GET -H "Accept: text/event-stream" -H "Cache-Control: no-cache" -H "
PID=$! PID=$!
new "Start subscriptions in parallell" new "Start subscriptions in parallell"
ret=$($UTIL -u http://localhost/streams/EXAMPLE -t 8) ret=$($clixon_util_stream -u http://localhost/streams/EXAMPLE -t 8)
expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>" expect="data: <notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>${DATE}T[0-9:.]*Z</eventTime><event><event-class>fault</event-class><reportingEntity><card>Ethernet0</card></reportingEntity><severity>major</severity></event>"
match=$(echo "$ret" | grep -Eo "$expect") match=$(echo "$ret" | grep -Eo "$expect")

View file

@ -2,10 +2,11 @@
# Advanced union types and generated code # Advanced union types and generated code
# and enum w values # and enum w values
# XXX NO SUPPORT FOR lists of ranges and lengths !!! # XXX NO SUPPORT FOR lists of ranges and lengths !!!
APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/type.yang fyang=$dir/type.yang

View file

@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
# Advanced union types and generated code # Advanced union types and generated code
# and enum w values # and enum w values
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/type.yang fyang=$dir/type.yang

View file

@ -2,9 +2,10 @@
# Yang when and must conditional xpath specification # Yang when and must conditional xpath specification
# Testing of validation phase. # Testing of validation phase.
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/test.yang fyang=$dir/test.yang

View file

@ -3,43 +3,42 @@
# @see https://www.w3.org/TR/2008/REC-xml-20081126 # @see https://www.w3.org/TR/2008/REC-xml-20081126
# https://www.w3.org/TR/2009/REC-xml-names-20091208 # https://www.w3.org/TR/2009/REC-xml-names-20091208
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_xml" #PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_xml"
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# include err() and new() functions and creates $dir : ${clixon_util_xml:=clixon_util_xml}
. ./lib.sh
PROG="../util/clixon_util_xml -D $DBG"
new "xml parse" new "xml parse"
expecteof "$PROG" 0 "<a><b/></a>" "^<a><b/></a>$" expecteof "$clixon_util_xml" 0 "<a><b/></a>" "^<a><b/></a>$"
new "xml parse to json" new "xml parse to json"
expecteof "$PROG -j" 0 "<a><b/></a>" '{"a": {"b": null}}' expecteof "$clixon_util_xml -j" 0 "<a><b/></a>" '{"a": {"b": null}}'
new "xml parse strange names" new "xml parse strange names"
expecteof "$PROG" 0 "<_-><b0.><c-.-._/></b0.></_->" "<_-><b0.><c-.-._/></b0.></_->" expecteof "$clixon_util_xml" 0 "<_-><b0.><c-.-._/></b0.></_->" "<_-><b0.><c-.-._/></b0.></_->"
new "xml parse name errors" new "xml parse name errors"
expecteof "$PROG" 255 "<-a/>" "" expecteof "$clixon_util_xml" 255 "<-a/>" ""
new "xml parse name errors" new "xml parse name errors"
expecteof "$PROG" 255 "<9/>" "" expecteof "$clixon_util_xml" 255 "<9/>" ""
new "xml parse name errors" new "xml parse name errors"
expecteof "$PROG" 255 "<a%/>" "" expecteof "$clixon_util_xml" 255 "<a%/>" ""
LF=' LF='
' '
new "xml parse content with CR LF -> LF, CR->LF (see https://www.w3.org/TR/REC-xml/#sec-line-ends)" new "xml parse content with CR LF -> LF, CR->LF (see https://www.w3.org/TR/REC-xml/#sec-line-ends)"
ret=$(echo "<x>a b${LF}c ${LF}d</x>" | $PROG) ret=$(echo "<x>a b${LF}c ${LF}d</x>" | $clixon_util_xml)
if [ "$ret" != "<x>a${LF}b${LF}c${LF}d</x>" ]; then if [ "$ret" != "<x>a${LF}b${LF}c${LF}d</x>" ]; then
err '<x>a$LFb$LFc</x>' "$ret" err '<x>a$LFb$LFc</x>' "$ret"
fi fi
new "xml simple CDATA" new "xml simple CDATA"
expecteofx "$PROG" 0 '<a><![CDATA[a text]]></a>' '<a><![CDATA[a text]]></a>' expecteofx "$clixon_util_xml" 0 '<a><![CDATA[a text]]></a>' '<a><![CDATA[a text]]></a>'
new "xml simple CDATA to json" new "xml simple CDATA to json"
expecteofx "$PROG -j" 0 '<a><![CDATA[a text]]></a>' '{"a": "a text"}' expecteofx "$clixon_util_xml -j" 0 '<a><![CDATA[a text]]></a>' '{"a": "a text"}'
new "xml complex CDATA" new "xml complex CDATA"
XML=$(cat <<EOF XML=$(cat <<EOF
@ -56,7 +55,7 @@ XML=$(cat <<EOF
EOF EOF
) )
expecteof "$PROG" 0 "$XML" "^<a><description>An example of escaped CENDs</description><sometext> expecteof "$clixon_util_xml" 0 "$XML" "^<a><description>An example of escaped CENDs</description><sometext>
<![CDATA[ They're saying \"x < y\" & that \"z > y\" so I guess that means that z > x ]]> <![CDATA[ They're saying \"x < y\" & that \"z > y\" so I guess that means that z > x ]]>
</sometext><data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data><alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative></a>$" </sometext><data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data><alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative></a>$"
@ -65,89 +64,89 @@ JSON=$(cat <<EOF
EOF EOF
) )
new "xml complex CDATA to json" new "xml complex CDATA to json"
expecteofx "$PROG -j" 0 "$XML" "$JSON" expecteofx "$clixon_util_xml -j" 0 "$XML" "$JSON"
XML=$(cat <<EOF XML=$(cat <<EOF
<message>Less than: &lt; , greater than: &gt; ampersand: &amp; </message> <message>Less than: &lt; , greater than: &gt; ampersand: &amp; </message>
EOF EOF
) )
new "xml encode <>&" new "xml encode <>&"
expecteof "$PROG" 0 "$XML" "$XML" expecteof "$clixon_util_xml" 0 "$XML" "$XML"
new "xml encode <>& to json" new "xml encode <>& to json"
expecteof "$PROG -j" 0 "$XML" '{"message": "Less than: < , greater than: > ampersand: & "}' expecteof "$clixon_util_xml -j" 0 "$XML" '{"message": "Less than: < , greater than: > ampersand: & "}'
XML=$(cat <<EOF XML=$(cat <<EOF
<message>single-quote character ' represented as &apos; and double-quote character as &quot;</message> <message>single-quote character ' represented as &apos; and double-quote character as &quot;</message>
EOF EOF
) )
new "xml single and double quote" new "xml single and double quote"
expecteof "$PROG" 0 "$XML" "<message>single-quote character ' represented as ' and double-quote character as \"</message>" expecteof "$clixon_util_xml" 0 "$XML" "<message>single-quote character ' represented as ' and double-quote character as \"</message>"
JSON=$(cat <<EOF JSON=$(cat <<EOF
{"message": "single-quote character ' represented as ' and double-quote character as \""} {"message": "single-quote character ' represented as ' and double-quote character as \""}
EOF EOF
) )
new "xml single and double quotes to json" new "xml single and double quotes to json"
expecteofx "$PROG -j" 0 "$XML" "$JSON" expecteofx "$clixon_util_xml -j" 0 "$XML" "$JSON"
new "xml backspace" new "xml backspace"
expecteofx "$PROG" 0 "<a>a\b</a>" "<a>a\b</a>" expecteofx "$clixon_util_xml" 0 "<a>a\b</a>" "<a>a\b</a>"
new "xml backspace to json" new "xml backspace to json"
expecteofx "$PROG -j" 0 "<a>a\b</a>" '{"a": "a\\b"}' expecteofx "$clixon_util_xml -j" 0 "<a>a\b</a>" '{"a": "a\\b"}'
new "Double quotes for attributes" new "Double quotes for attributes"
expecteof "$PROG" 0 '<x a="t"/>' '<x a="t"/>' expecteof "$clixon_util_xml" 0 '<x a="t"/>' '<x a="t"/>'
new "Single quotes for attributes (returns double quotes but at least parses right)" new "Single quotes for attributes (returns double quotes but at least parses right)"
expecteof "$PROG" 0 "<x a='t'/>" '<x a="t"/>' expecteof "$clixon_util_xml" 0 "<x a='t'/>" '<x a="t"/>'
new "Mixed quotes" new "Mixed quotes"
expecteof "$PROG" 0 "<x a='t' b=\"q\"/>" '<x a="t" b="q"/>' expecteof "$clixon_util_xml" 0 "<x a='t' b=\"q\"/>" '<x a="t" b="q"/>'
new "XMLdecl version" new "XMLdecl version"
expecteof "$PROG" 0 '<?xml version="1.0"?><a/>' '<a/>' expecteof "$clixon_util_xml" 0 '<?xml version="1.0"?><a/>' '<a/>'
new "XMLdecl version, single quotes" new "XMLdecl version, single quotes"
expecteof "$PROG" 0 "<?xml version='1.0'?><a/>" '<a/>' expecteof "$clixon_util_xml" 0 "<?xml version='1.0'?><a/>" '<a/>'
new "XMLdecl version no element" new "XMLdecl version no element"
expecteof "$PROG" 255 '<?xml version="1.0"?>' '' expecteof "$clixon_util_xml" 255 '<?xml version="1.0"?>' ''
new "XMLdecl no version" new "XMLdecl no version"
expecteof "$PROG" 255 '<?xml ?><a/>' '' expecteof "$clixon_util_xml" 255 '<?xml ?><a/>' ''
new "XMLdecl misspelled version" new "XMLdecl misspelled version"
expecteof "$PROG -l o" 255 '<?xml verion="1.0"?><a/>' '' expecteof "$clixon_util_xml -l o" 255 '<?xml verion="1.0"?><a/>' ''
new "XMLdecl version + encoding" new "XMLdecl version + encoding"
expecteof "$PROG" 0 '<?xml version="1.0" encoding="UTF-16"?><a/>' '<a/>' expecteof "$clixon_util_xml" 0 '<?xml version="1.0" encoding="UTF-16"?><a/>' '<a/>'
new "XMLdecl version + misspelled encoding" new "XMLdecl version + misspelled encoding"
expecteof "$PROG -l o" 255 '<?xml version="1.0" encding="UTF-16"?><a/>' 'syntax error: at or before: e' expecteof "$clixon_util_xml -l o" 255 '<?xml version="1.0" encding="UTF-16"?><a/>' 'syntax error: at or before: e'
new "XMLdecl version + standalone" new "XMLdecl version + standalone"
expecteof "$PROG" 0 '<?xml version="1.0" standalone="yes"?><a/>' '<a/>' expecteof "$clixon_util_xml" 0 '<?xml version="1.0" standalone="yes"?><a/>' '<a/>'
new "PI - Processing instruction empty" new "PI - Processing instruction empty"
expecteof "$PROG" 0 '<?foo ?><a/>' '<a/>' expecteof "$clixon_util_xml" 0 '<?foo ?><a/>' '<a/>'
new "PI some content" new "PI some content"
expecteof "$PROG" 0 '<?foo something else ?><a/>' '<a/>' expecteof "$clixon_util_xml" 0 '<?foo something else ?><a/>' '<a/>'
new "prolog element misc*" new "prolog element misc*"
expecteof "$PROG" 0 '<?foo something ?><a/><?bar more stuff ?><!-- a comment-->' '<a/>' expecteof "$clixon_util_xml" 0 '<?foo something ?><a/><?bar more stuff ?><!-- a comment-->' '<a/>'
# We allow it as an internal necessity for parsing of xml fragments # We allow it as an internal necessity for parsing of xml fragments
#new "double element error" #new "double element error"
#expecteof "$PROG" 255 '<a/><b/>' '' #expecteof "$clixon_util_xml" 255 '<a/><b/>' ''
new "namespace: DefaultAttName" new "namespace: DefaultAttName"
expecteof "$PROG" 0 '<x xmlns="n1">hello</x>' '<x xmlns="n1">hello</x>' expecteof "$clixon_util_xml" 0 '<x xmlns="n1">hello</x>' '<x xmlns="n1">hello</x>'
new "namespace: PrefixedAttName" new "namespace: PrefixedAttName"
expecteof "$PROG" 0 '<x xmlns:n2="urn:example:des"><n2:y>hello</n2:y></x>' '^<x xmlns:n2="urn:example:des"><n2:y>hello</n2:y></x>$' expecteof "$clixon_util_xml" 0 '<x xmlns:n2="urn:example:des"><n2:y>hello</n2:y></x>' '^<x xmlns:n2="urn:example:des"><n2:y>hello</n2:y></x>$'
new "First example 6.1 from https://www.w3.org/TR/2009/REC-xml-names-20091208" new "First example 6.1 from https://www.w3.org/TR/2009/REC-xml-names-20091208"
XML=$(cat <<EOF XML=$(cat <<EOF
@ -161,7 +160,7 @@ XML=$(cat <<EOF
</html:html> </html:html>
EOF EOF
) )
expecteof "$PROG" 0 "$XML" "$XML" expecteof "$clixon_util_xml" 0 "$XML" "$XML"
new "Second example 6.1 from https://www.w3.org/TR/2009/REC-xml-names-20091208" new "Second example 6.1 from https://www.w3.org/TR/2009/REC-xml-names-20091208"
XML=$(cat <<EOF XML=$(cat <<EOF
@ -174,7 +173,7 @@ XML=$(cat <<EOF
</bk:book> </bk:book>
EOF EOF
) )
expecteof "$PROG" 0 "$XML" "$XML" expecteof "$clixon_util_xml" 0 "$XML" "$XML"
rm -rf $dir rm -rf $dir

View file

@ -1,10 +1,11 @@
#!/bin/bash #!/bin/bash
# Test: XPATH tests # Test: XPATH tests
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_xpath" #PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_xpath"
PROG=../util/clixon_util_xpath
# include err() and new() functions and creates $dir # Magic line must be first in script (see README.md)
. ./lib.sh s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${clixon_util_xpath:=clixon_util_xpath}
# XML file (alt provide it in stdin after xpath) # XML file (alt provide it in stdin after xpath)
xml=$dir/xml.xml xml=$dir/xml.xml
@ -76,117 +77,117 @@ cat <<EOF > $xml3
EOF EOF
new "xpath /" new "xpath /"
expecteof "$PROG -f $xml -p /" 0 "" "^nodeset:0:<aaa><bbb x=\"hello\"><ccc>42</ccc></bbb><bbb x=\"bye\"><ccc>99</ccc></bbb><ddd><ccc>22</ccc></ddd></aaa>$" expecteof "$clixon_util_xpath -f $xml -p /" 0 "" "^nodeset:0:<aaa><bbb x=\"hello\"><ccc>42</ccc></bbb><bbb x=\"bye\"><ccc>99</ccc></bbb><ddd><ccc>22</ccc></ddd></aaa>$"
new "xpath /aaa" new "xpath /aaa"
expecteof "$PROG -f $xml -p /aaa" 0 "" "^nodeset:0:<aaa><bbb x=\"hello\"><ccc>42</ccc></bbb><bbb x=\"bye\"><ccc>99</ccc></bbb><ddd><ccc>22</ccc></ddd></aaa>$" expecteof "$clixon_util_xpath -f $xml -p /aaa" 0 "" "^nodeset:0:<aaa><bbb x=\"hello\"><ccc>42</ccc></bbb><bbb x=\"bye\"><ccc>99</ccc></bbb><ddd><ccc>22</ccc></ddd></aaa>$"
new "xpath /bbb" new "xpath /bbb"
expecteof "$PROG -f $xml -p /bbb" 0 "" "^nodeset:$" expecteof "$clixon_util_xpath -f $xml -p /bbb" 0 "" "^nodeset:$"
new "xpath /aaa/bbb" new "xpath /aaa/bbb"
expecteof "$PROG -f $xml -p /aaa/bbb" 0 "" "^0:<bbb x=\"hello\"><ccc>42</ccc></bbb> expecteof "$clixon_util_xpath -f $xml -p /aaa/bbb" 0 "" "^0:<bbb x=\"hello\"><ccc>42</ccc></bbb>
1:<bbb x=\"bye\"><ccc>99</ccc></bbb>$" 1:<bbb x=\"bye\"><ccc>99</ccc></bbb>$"
new "xpath //bbb" new "xpath //bbb"
expecteof "$PROG -f $xml -p //bbb" 0 "" "0:<bbb x=\"hello\"><ccc>42</ccc></bbb> expecteof "$clixon_util_xpath -f $xml -p //bbb" 0 "" "0:<bbb x=\"hello\"><ccc>42</ccc></bbb>
1:<bbb x=\"bye\"><ccc>99</ccc></bbb>" 1:<bbb x=\"bye\"><ccc>99</ccc></bbb>"
new "xpath //b?b" new "xpath //b?b"
#expecteof "$PROG -f $xml" 0 "//b?b" "" #expecteof "$clixon_util_xpath -f $xml" 0 "//b?b" ""
new "xpath //b*" new "xpath //b*"
#expecteof "$PROG -f $xml" 0 "//b*" "" #expecteof "$clixon_util_xpath -f $xml" 0 "//b*" ""
new "xpath //b*/ccc" new "xpath //b*/ccc"
#expecteof "$PROG -f $xml" 0 "//b*/ccc" "" #expecteof "$clixon_util_xpath -f $xml" 0 "//b*/ccc" ""
new "xpath //bbb[0]" new "xpath //bbb[0]"
expecteof "$PROG -f $xml -p //bbb[0]" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>42</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml -p //bbb[0]" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>42</ccc></bbb>$"
new "xpath //bbb[ccc=99]" new "xpath //bbb[ccc=99]"
expecteof "$PROG -f $xml -p //bbb[ccc=99]" 0 "" "^nodeset:0:<bbb x=\"bye\"><ccc>99</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml -p //bbb[ccc=99]" 0 "" "^nodeset:0:<bbb x=\"bye\"><ccc>99</ccc></bbb>$"
new "xpath ../connection-type = 'responder-only'" new "xpath ../connection-type = 'responder-only'"
expecteof "$PROG -f $xml2 -p ../connection-type='responder-only' -i /aaa/bbb/here" 0 "" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -p ../connection-type='responder-only' -i /aaa/bbb/here" 0 "" "^bool:true$"
new "xpath ../connection-type = 'no-responder'" new "xpath ../connection-type = 'no-responder'"
expecteof "$PROG -f $xml2 -p ../connection-type='no-responder' -i /aaa/bbb/here" 0 "" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -p ../connection-type='no-responder' -i /aaa/bbb/here" 0 "" "^bool:false$"
new "xpath . <= 0.75 * ../max-rtr-adv-interval" new "xpath . <= 0.75 * ../max-rtr-adv-interval"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here" 0 ". <= 0.75 * ../max-rtr-adv-interval" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here" 0 ". <= 0.75 * ../max-rtr-adv-interval" "^bool:true$"
new "xpath . > 0.75 * ../max-rtr-adv-interval" new "xpath . > 0.75 * ../max-rtr-adv-interval"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here" 0 ". > 0.75 * ../max-rtr-adv-interval" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here" 0 ". > 0.75 * ../max-rtr-adv-interval" "^bool:false$"
new "xpath . <= ../valid-lifetime" new "xpath . <= ../valid-lifetime"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here" 0 ". <= ../valid-lifetime" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here" 0 ". <= ../valid-lifetime" "^bool:true$"
new "xpath ../../rt:address-family = 'v6ur:ipv6-unicast'" new "xpath ../../rt:address-family = 'v6ur:ipv6-unicast'"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here" 0 "../../rt:address-family = 'v6ur:ipv6-unicast'" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here" 0 "../../rt:address-family = 'v6ur:ipv6-unicast'" "^bool:true$"
new "xpath ../../../rt:address-family = 'v6ur:ipv6-unicast'" new "xpath ../../../rt:address-family = 'v6ur:ipv6-unicast'"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here2/here" 0 "../../../rt:address-family = 'v6ur:ipv6-unicast'" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here2/here" 0 "../../../rt:address-family = 'v6ur:ipv6-unicast'" "^bool:true$"
new "xpath /if:interfaces/if:interface[if:name=current()/rt:name]/ip:ipv6/ip:enabled='true'" new "xpath /if:interfaces/if:interface[if:name=current()/rt:name]/ip:ipv6/ip:enabled='true'"
expecteof "$PROG -f $xml2" 0 "/if:interfaces/if:interface[if:name=current()/rt:name]/ip:ipv6/ip:enabled='true'" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2" 0 "/if:interfaces/if:interface[if:name=current()/rt:name]/ip:ipv6/ip:enabled='true'" "^bool:true$"
new "xpath rt:address-family='v6ur:ipv6-unicast'" new "xpath rt:address-family='v6ur:ipv6-unicast'"
expecteof "$PROG -f $xml2 -i /aaa" 0 "rt:address-family='v6ur:ipv6-unicast'" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa" 0 "rt:address-family='v6ur:ipv6-unicast'" "^bool:true$"
new "xpath ../type='rt:static'" new "xpath ../type='rt:static'"
expecteof "$PROG -f $xml2 -i /aaa/bbb/here" 0 "../type='rt:static'" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb/here" 0 "../type='rt:static'" "^bool:true$"
new "xpath rib-name != ../../name" new "xpath rib-name != ../../name"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "rib-name != ../../name" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "rib-name != ../../name" "^bool:true$"
new "xpath routing/ribs/rib[name=current()/rib-name]/address-family=../../address-family" new "xpath routing/ribs/rib[name=current()/rib-name]/address-family=../../address-family"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "routing/ribs/rib[name=current()/rib-name]/address-family=../../address-family" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "routing/ribs/rib[name=current()/rib-name]/address-family=../../address-family" "^bool:true$"
new "xpath ifType = \"ethernet\" or ifMTU = 1500" new "xpath ifType = \"ethernet\" or ifMTU = 1500"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" or ifMTU = 1500" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" or ifMTU = 1500" "^bool:true$"
new "xpath ifType != \"ethernet\" or ifMTU = 1500" new "xpath ifType != \"ethernet\" or ifMTU = 1500"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" or ifMTU = 1500" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" or ifMTU = 1500" "^bool:true$"
new "xpath ifType = \"ethernet\" or ifMTU = 1400" new "xpath ifType = \"ethernet\" or ifMTU = 1400"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" or ifMTU = 1400" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" or ifMTU = 1400" "^bool:true$"
new "xpath ifType != \"ethernet\" or ifMTU = 1400" new "xpath ifType != \"ethernet\" or ifMTU = 1400"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" or ifMTU = 1400" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" or ifMTU = 1400" "^bool:false$"
new "xpath ifType = \"ethernet\" and ifMTU = 1500" new "xpath ifType = \"ethernet\" and ifMTU = 1500"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" and ifMTU = 1500" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" and ifMTU = 1500" "^bool:true$"
new "xpath ifType != \"ethernet\" and ifMTU = 1500" new "xpath ifType != \"ethernet\" and ifMTU = 1500"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" and ifMTU = 1500" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" and ifMTU = 1500" "^bool:false$"
new "xpath ifType = \"ethernet\" and ifMTU = 1400" new "xpath ifType = \"ethernet\" and ifMTU = 1400"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" and ifMTU = 1400" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType = \"ethernet\" and ifMTU = 1400" "^bool:false$"
new "xpath ifType != \"ethernet\" and ifMTU = 1400" new "xpath ifType != \"ethernet\" and ifMTU = 1400"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" and ifMTU = 1400" "^bool:false$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"ethernet\" and ifMTU = 1400" "^bool:false$"
new "xpath ifType != \"atm\" or (ifMTU <= 17966 and ifMTU >= 64)" new "xpath ifType != \"atm\" or (ifMTU <= 17966 and ifMTU >= 64)"
expecteof "$PROG -f $xml2 -i /aaa/bbb" 0 "ifType != \"atm\" or (ifMTU <= 17966 and ifMTU >= 64)" "^bool:true$" expecteof "$clixon_util_xpath -f $xml2 -i /aaa/bbb" 0 "ifType != \"atm\" or (ifMTU <= 17966 and ifMTU >= 64)" "^bool:true$"
new "xpath .[name='bar']" new "xpath .[name='bar']"
expecteof "$PROG -f $xml2 -p .[name='bar'] -i /aaa/bbb/routing/ribs/rib" 0 "" "^nodeset:0:<rib><name>bar</name><address-family>myfamily</address-family></rib>$" expecteof "$clixon_util_xpath -f $xml2 -p .[name='bar'] -i /aaa/bbb/routing/ribs/rib" 0 "" "^nodeset:0:<rib><name>bar</name><address-family>myfamily</address-family></rib>$"
new "Multiple entries" new "Multiple entries"
new "xpath bbb[ccc='foo']" new "xpath bbb[ccc='foo']"
expecteof "$PROG -f $xml3 -p bbb[ccc='foo']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>1:<bbb x=\"bye\"><ccc>99</ccc><ccc>foo</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='foo']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>1:<bbb x=\"bye\"><ccc>99</ccc><ccc>foo</ccc></bbb>$"
new "xpath bbb[ccc='42']" new "xpath bbb[ccc='42']"
expecteof "$PROG -f $xml3 -p bbb[ccc='42']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='42']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>$"
new "xpath bbb[ccc=99] (number w/o quotes)" new "xpath bbb[ccc=99] (number w/o quotes)"
expecteof "$PROG -f $xml3 -p bbb[ccc=99]" 0 "" "^nodeset:0:<bbb x=\"bye\"><ccc>99</ccc><ccc>foo</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc=99]" 0 "" "^nodeset:0:<bbb x=\"bye\"><ccc>99</ccc><ccc>foo</ccc></bbb>$"
new "xpath bbb[ccc='bar']" new "xpath bbb[ccc='bar']"
expecteof "$PROG -f $xml3 -p bbb[ccc='bar']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>$" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='bar']" 0 "" "^nodeset:0:<bbb x=\"hello\"><ccc>foo</ccc><ccc>42</ccc><ccc>bar</ccc></bbb>$"
new "xpath bbb[ccc='fie']" new "xpath bbb[ccc='fie']"
expecteof "$PROG -f $xml3 -p bbb[ccc='fie']" 0 "" "^nodeset:$" expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='fie']" 0 "" "^nodeset:$"
rm -rf $dir rm -rf $dir

View file

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
# Yang specifics: multi-keys and empty type # Yang test: multi-keys and empty type
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/$APPNAME.yang fyang=$dir/$APPNAME.yang

View file

@ -4,9 +4,11 @@
# as well as revisions # as well as revisions
# Test is made by having different config files and then try to set configure # Test is made by having different config files and then try to set configure
# options available in specific modules # options available in specific modules
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang1=$dir/$APPNAME@2018-12-02.yang fyang1=$dir/$APPNAME@2018-12-02.yang

View file

@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
# Test two modules example1 and example2 with overlapping statements x.
APPNAME=example
# test two modules example1 and example2 with overlapping statements x.
# x is leaf in example1 and list on example2. # x is leaf in example1 and list on example2.
# Test netconf and restconf # Test netconf and restconf
# BTW, this is not supported in generated CLI # BTW, this is not supported in generated CLI
. ./lib.sh # Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
APPNAME=example
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang1=$dir/example1.yang fyang1=$dir/example1.yang

View file

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
# Parse yangmodels from https://github.com/YangModels/yang # Parse yangmodels from https://github.com/YangModels/yang
# Notes: # Notes:
# - Env-var MODELS should be 1
# - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example) # - Env variable YANGMODELS should point to checkout place. (define it in site.sh for example)
# - Only cisco/nx/9.2-2 # Many other versions # - Only cisco/nx/9.2-2 # Many other versions
# - Only cisco/xe/1631 # Many other versions # - Only cisco/xe/1631 # Many other versions
@ -17,16 +16,12 @@
#./vendor/cisco/xe/check.sh #./vendor/cisco/xe/check.sh
#./vendor/cisco/nx/check.sh #./vendor/cisco/nx/check.sh
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
# Yang specifics: multi-keys and empty type # Yang specifics: multi-keys and empty type
APPNAME=example APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
if [ $MODELS -eq 0 ]; then
exit
fi
cfg=$dir/conf_yang.xml cfg=$dir/conf_yang.xml
fyang=$dir/test.yang fyang=$dir/test.yang

View file

@ -43,6 +43,7 @@ libexecdir = @libexecdir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
HOST_VENDOR = @host_vendor@ HOST_VENDOR = @host_vendor@
with_restconf = @with_restconf@
SH_SUFFIX = @SH_SUFFIX@ SH_SUFFIX = @SH_SUFFIX@
@ -70,12 +71,14 @@ APPSRC = clixon_util_xml.c
APPSRC += clixon_util_json.c APPSRC += clixon_util_json.c
APPSRC += clixon_util_yang.c APPSRC += clixon_util_yang.c
APPSRC += clixon_util_xpath.c APPSRC += clixon_util_xpath.c
# APPSRC += clixon_util_stream.c # Needs curl APPSRC += clixon_util_datastore.c
ifeq ($(with_restconf),yes)
APPSRC += clixon_util_stream.c # Needs curl
endif
APPS = $(APPSRC:.c=) APPS = $(APPSRC:.c=)
all: $(APPS) all: $(APPS)
@echo "You may want to make clixon_util_stream separately (curl dependency)"
clean: clean:
rm -f $(APPS) clixon_util_stream *.core rm -f $(APPS) clixon_util_stream *.core
@ -96,13 +99,15 @@ clixon_util_xpath: clixon_util_xpath.c $(MYLIB)
clixon_util_stream: clixon_util_stream.c $(MYLIB) clixon_util_stream: clixon_util_stream.c $(MYLIB)
$(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lcurl -o $@ $(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -lcurl -o $@
clixon_util_datastore: clixon_util_datastore.c $(MYLIB)
$(CC) $(INCLUDES) $(CPPFLAGS) @CFLAGS@ $(LDFLAGS) $^ $(LIBS) -o $@
distclean: clean distclean: clean
rm -f Makefile *~ .depend rm -f Makefile *~ .depend
install: install:
# install -d -m 0755 $(DESTDIR)$(bindir) install -d -m 0755 $(DESTDIR)$(bindir)
# install -m 0755 $(INSTALLFLAGS) $(APPS) $(DESTDIR)$(bindir) install -m 0755 $(INSTALLFLAGS) $(APPS) $(DESTDIR)$(bindir)
install-include: install-include:

View file

@ -117,7 +117,7 @@ main(int argc, char **argv)
cbuf *cbret = NULL; cbuf *cbret = NULL;
/* In the startup, logs to stderr & debug flag set later */ /* In the startup, logs to stderr & debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR); clicon_log_init(__FILE__, LOG_INFO, CLICON_LOG_STDERR);
argv0 = argv[0]; argv0 = argv[0];
/* Defaults */ /* Defaults */
@ -157,7 +157,7 @@ main(int argc, char **argv)
/* /*
* Logs, error and debug to stderr, set debug level * Logs, error and debug to stderr, set debug level
*/ */
clicon_log_init(__PROGRAM__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR); clicon_log_init(__FILE__, debug?LOG_DEBUG:LOG_INFO, CLICON_LOG_STDERR);
clicon_debug_init(debug, NULL); clicon_debug_init(debug, NULL);
argc -= optind; argc -= optind;