diff --git a/.gitignore b/.gitignore index 0a54c94a..3fe9e62a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,9 @@ lex.*_parse.c Makefile apps/Makefile apps/*/Makefile +datastore/Makefile docker/Makefile -docker/base/Makefile -docker/system/Makefile +docker/*/Makefile etc/Makefile example/Makefile lib/Makefile @@ -34,10 +34,6 @@ apps/netconf/clixon_netconf apps/restconf/clixon_restconf apps/xmldb/clixon_xmldb -docker/backend/Dockerfile -docker/cli/Dockerfile -docker/netconf/Dockerfile - etc/clixonrc include/clixon_config.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 410dc887..1a8f08cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,7 @@ * XML prolog syntax for 'well-formed' XML * ` #include #include - #include #include #include #include +#include /* chmod */ /* cligen */ #include @@ -694,6 +694,11 @@ main(int argc, clicon_err(OE_CFG, errno, "FCGX_OpenSocket"); 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){ clicon_err(OE_CFG, errno, "FCGX_InitRequest"); goto done; diff --git a/configure b/configure index 317af820..645b63d8 100755 --- a/configure +++ b/configure @@ -715,6 +715,7 @@ with_cligen enable_stdyangs enable_publish with_restconf +with_wwwuser with_configfile ' ac_precious_vars='build_alias @@ -1362,6 +1363,7 @@ Optional Packages: --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-cligen=dir Use CLIGEN here --without-restconf disable support for restconf + --with-wwwuser= Set www user different from www-data --with-configfile=FILE set default path to config file Some influential environment variables: @@ -4170,6 +4172,18 @@ 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 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 # 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/base/Makefile") CONFIG_FILES="$CONFIG_FILES docker/base/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" ;; "yang/Makefile") CONFIG_FILES="$CONFIG_FILES yang/Makefile" ;; "yang/clixon/Makefile") CONFIG_FILES="$CONFIG_FILES yang/clixon/Makefile" ;; diff --git a/configure.ac b/configure.ac index 3261210c..c2d64ca8 100644 --- a/configure.ac +++ b/configure.ac @@ -191,6 +191,14 @@ if test "x${with_restconf}" == xyes; then AC_CHECK_LIB(fcgi, FCGX_Init,, AC_MSG_ERROR([libfcgi-dev missing])) fi +# This is for changing web user default www-data +AC_ARG_WITH([wwwuser], + [AS_HELP_STRING([--with-wwwuser=],[Set www user different from www-data])]) +if test "${with_wwwuser}"; then + wwwuser=${with_wwwuser} +fi +echo "wwwuser:$wwwuser" + # Set default config file location CLIXON_DEFAULT_CONFIG=/usr/local/etc/clixon.xml AC_ARG_WITH([configfile], @@ -245,7 +253,6 @@ AC_OUTPUT(Makefile docker/system/Makefile docker/base/Makefile datastore/Makefile - datastore/text/Makefile util/Makefile yang/Makefile yang/clixon/Makefile diff --git a/datastore/Makefile.in b/datastore/Makefile.in index 5adde268..9eadb121 100644 --- a/datastore/Makefile.in +++ b/datastore/Makefile.in @@ -30,7 +30,6 @@ # # ***** END LICENSE BLOCK ***** # -VPATH = @srcdir@ prefix = @prefix@ datarootdir = @datarootdir@ srcdir = @srcdir@ @@ -43,78 +42,60 @@ mandir = @mandir@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ sysconfdir = @sysconfdir@ +HOST_VENDOR = @host_vendor@ + +VPATH = @srcdir@ CC = @CC@ -CFLAGS = @CFLAGS@ -INSTALLFLAGS = @INSTALLFLAGS@ +CFLAGS = @CFLAGS@ -rdynamic -fPIC +INSTALLFLAGS = @INSTALLFLAGS@ LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ -with_restconf = @with_restconf@ - -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) - +LIBS = @LIBS@ +DATASTORE = text 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 -APPOBJ = $(APPSRC:.c=.o) -APPL = datastore_client +all: $(PLUGIN) -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: .c .o -.c.o: - $(CC) $(INCLUDES) -D__PROGRAM__=\"$(APPL)\" $(CPPFLAGS) $(CFLAGS) -c $< +.c.o: $(SRC) + $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -$(APPL) : $(APPOBJ) $(LIBDEPS) - $(CC) $(LDFLAGS) $(APPOBJ) $(LIBS) -o $@ - - -depend: - for i in $(SUBDIRS); \ - do (cd $$i; $(MAKE) $(MFLAGS) $@); done - -$(SUBDIRS): - (cd $@; $(MAKE) $(MFLAGS) all) +install: $(PLUGIN) + install -d -m 0755 $(DESTDIR)$(libdir)/xmldb + install -m 0644 $(INSTALLFLAGS) $(PLUGIN) $(DESTDIR)$(libdir)/xmldb install-include: - for i in $(SUBDIRS); \ - do (cd $$i ; $(MAKE) $(MFLAGS) $@)||exit 1; done; -install: - for i in $(SUBDIRS); \ - 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 +uninstall: + rm -rf $(DESTDIR)$(libdir)/xmldb/$(PLUGIN) TAGS: - find $(srcdir) -name '*.[chyl]' -print | etags - + find . -name '*.[chyl]' -print | etags - + +depend: + $(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(SRC) > .depend + +#include .depend + diff --git a/datastore/text/clixon_xmldb_text.c b/datastore/clixon_xmldb_text.c similarity index 100% rename from datastore/text/clixon_xmldb_text.c rename to datastore/clixon_xmldb_text.c diff --git a/datastore/text/clixon_xmldb_text.h b/datastore/clixon_xmldb_text.h similarity index 100% rename from datastore/text/clixon_xmldb_text.h rename to datastore/clixon_xmldb_text.h diff --git a/datastore/text/Makefile.in b/datastore/text/Makefile.in deleted file mode 100644 index 9eadb121..00000000 --- a/datastore/text/Makefile.in +++ /dev/null @@ -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 - diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 589beea2..76cc1520 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -37,11 +37,9 @@ MAINTAINER Olof Hagsand # For clixon and cligen RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev - # Create a directory to hold source-code, dependencies etc RUN mkdir /clixon RUN mkdir /clixon/build - WORKDIR /clixon # Clone cligen @@ -58,37 +56,54 @@ RUN mkdir /clixon/clixon WORKDIR /clixon/clixon COPY clixon . -# Build clixon (without restconf if you dont have nginx) -RUN ./configure --without-restconf --prefix=/clixon/build --with-cligen=/clixon/build +# 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 install RUN make install-include +# Build and install the clixon example (not really necessary for base) WORKDIR /clixon/clixon/example -RUN DESTDIR=/clixon/build make +RUN make RUN make install +RUN install example.xml /clixon/build/etc/clixon.xml # # Stage 2 # - FROM alpine MAINTAINER Olof Hagsand # 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 adduser nginx clicon +RUN adduser www-data clicon COPY --from=0 /clixon/build/ /usr/local/ +COPY --from=0 /www-data /www-data -# For debug -#RUN apk add --update bash nano - - - - +# Manually created +RUN chown www-data /www-data +RUN chgrp www-data /www-data diff --git a/docker/base/README.md b/docker/base/README.md index 83f1407d..de26e094 100644 --- a/docker/base/README.md +++ b/docker/base/README.md @@ -12,23 +12,24 @@ See [clixon-system](../system/README.md) for a more complete clixon image. ## Build and push -Perform the build by `make docker`. -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). +Perform the build by `make docker`. This copies the latest _committed_ clixon code into the container. -You may run the container directly by going directly to example and -the docker runtime scripts there +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 have to login for push with sudo docker login -u ) ## Example run -The following shows a simple example of how to run the example -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 base container is a minimal and primitive example. Look at the [clixon-system](../system) for a more stream-lined application. +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 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 + $ sudo docker run --rm --name clixon-base -d clixon/clixon clixon_backend -Fs init +``` +Then a CLI is started, and finally the container is removed: +``` + $ sudo docker exec -it clixon-base clixon_cli > set interfaces interface e > show configuration interfaces { @@ -38,10 +39,10 @@ application. First,the container is started, then the backend is startend in the } } > 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 application, such as plugins, cli syntax files, yang models, etc, you need to extend the base container with your own additions. diff --git a/docker/base/start.sh b/docker/base/start.sh new file mode 100755 index 00000000..9b3f222c --- /dev/null +++ b/docker/base/start.sh @@ -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" + + + + diff --git a/docker/system/Dockerfile b/docker/system/Dockerfile index 8a011295..b99a71cc 100644 --- a/docker/system/Dockerfile +++ b/docker/system/Dockerfile @@ -31,34 +31,23 @@ # ***** END LICENSE BLOCK ***** # -# This application could use the base image, but it does not at this point. -FROM debian +FROM alpine MAINTAINER Olof Hagsand -# Clixon dependenies (not needed if build from base) -RUN apt-get update && apt-get install -y \ - 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 +# For clixon and cligen +RUN apk add --update git make build-base gcc flex bison fcgi-dev curl-dev # Create a directory to hold source-code, dependencies etc RUN mkdir /clixon +RUN mkdir /clixon/build WORKDIR /clixon -# Clone and build cligen (not necessary if use base image) +# Clone cligen RUN git clone https://github.com/olofhagsand/cligen.git + +# Build cligen WORKDIR /clixon/cligen -RUN ./configure +RUN ./configure --prefix=/clixon/build RUN make RUN make install @@ -67,30 +56,69 @@ RUN mkdir /clixon/clixon WORKDIR /clixon/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 install 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 RUN make 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 WORKDIR /clixon 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 + +# 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 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. CMD /usr/local/bin/startsystem.sh - - - - - diff --git a/docker/system/Makefile.in b/docker/system/Makefile.in index 19fb28db..7f034a9b 100644 --- a/docker/system/Makefile.in +++ b/docker/system/Makefile.in @@ -67,7 +67,7 @@ push: # Start the clixon system container and run the test script test: docker ./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: diff --git a/docker/system/README.md b/docker/system/README.md index 7cf3aa6b..7e67f791 100644 --- a/docker/system/README.md +++ b/docker/system/README.md @@ -52,7 +52,7 @@ As restconf using curl on exposed port 80: ``` 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: diff --git a/docker/system/startsystem.sh b/docker/system/startsystem.sh index 3bb57cef..077008da 100755 --- a/docker/system/startsystem.sh +++ b/docker/system/startsystem.sh @@ -11,6 +11,8 @@ DBG=${DBG:-0} +WWWUSER=${WWWUSER:-www-data} + # Initiate clixon configuration (env variable) 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" # nginx site config file -cat < /etc/nginx/sites-enabled/default +cat < /etc/nginx/conf.d/default.conf # server { listen 80 default_server; @@ -28,7 +30,6 @@ server { server_name localhost; server_name _; location / { - root /usr/share/nginx/html/restconf; fastcgi_pass unix:/www-data/fastcgi_restconf.sock; include fastcgi_params; } @@ -46,13 +47,17 @@ server { EOF # This is a clixon site test file. Disable all model testing. -cat < /clixon/clixon/test/site.sh +cat < /usr/local/bin/test/site.sh # Add your local site specific env variables (or tests) here. -MODELS=0 # Dont run yangmodels/openconfig tests -IETFRFC=/clixon/clixon/yang/standard +SKIPLIST="test_yangmodels.sh test_openconfig.sh test_install.sh test_order.sh" +#IETFRFC= EOF +chmod 775 /usr/local/bin/test/site.sh +if [ ! -d /run/nginx ]; then + mkdir /run/nginx +fi # Start nginx #/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf @@ -60,9 +65,12 @@ EOF >&2 echo "nginx started" # 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" +# Set grp write XXX do this when creating +chmod g+w /www-data/fastcgi_restconf.sock + # Start clixon backend >&2 echo "start clixon_backend:" /usr/local/sbin/clixon_backend -FD $DBG -s running -l e # logs on docker logs diff --git a/test/README.md b/test/README.md index fc012036..422f0006 100644 --- a/test/README.md +++ b/test/README.md @@ -21,7 +21,22 @@ application. Assumes setup of http daemon as describe under apps/restonf - test_datastore.sh Datastore tests - 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. @@ -37,14 +52,16 @@ Run all tests but continue after errors and only print a summary test output ide all.sh summary ``` -You need to start nginx. There are instructions in [the example](../example/README.md) - 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 diff --git a/test/all.sh b/test/all.sh index 23d5424f..e1842fa8 100755 --- a/test/all.sh +++ b/test/all.sh @@ -7,12 +7,11 @@ if [ $# -gt 0 ]; then exit -1 fi -# include err() and new() functions -. ./lib.sh err=0 +testnr=0 for test in test*.sh; do - echo "Running $test" - ./$test + testfile=$test + . ./$test errcode=$? if [ $errcode -ne 0 ]; then err=1 diff --git a/test/lib.sh b/test/lib.sh index 1689cc14..148b439d 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -12,18 +12,34 @@ #set -e -# Probe nginx -#sudo systemctl status nginx.service > /dev/null -#if [ $? -ne 0 ]; then -# sudo systemctl start nginx.service -#fi +# Testfile (not including path) +: ${testfile:=$(basename $0)} + +# Add test to this list that you dont want run +# Typically add them in your site file +: ${SKIPLIST:=""} + +>&2 echo "Running $testfile" # Site file, an example of this file in README.md if [ -x ./site.sh ]; then + . ./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 -testnr=0 +# Running test number +: ${testnr:=0} + +# Single test. Set by "new" testname= # 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" : ${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 # Recommended: checkout yangmodels elsewhere in the tree and set the env # to that diff --git a/test/sum.sh b/test/sum.sh index 257c2bff..6ce3b18b 100755 --- a/test/sum.sh +++ b/test/sum.sh @@ -7,16 +7,14 @@ if [ $# -gt 0 ]; then exit -1 fi -# include err() and new() functions -. ./lib.sh err=0 -for test in test*.sh; do - echo "Running $test" - ./$test > /dev/null 2>&1 +for testfile in test*.sh; do # For lib.sh the variable must be called testfile + echo "Running $testfile" + ./$testfile > /dev/null 2>&1 errcode=$? if [ $errcode -ne 0 ]; then err=1 - echo -e "\e[31mError in $test errcode=$errcode" + echo -e "\e[31mError in $testfile errcode=$errcode" echo -ne "\e[0m" fi done diff --git a/test/test_choice.sh b/test/test_choice.sh index ea4e2677..71fe751f 100755 --- a/test/test_choice.sh +++ b/test/test_choice.sh @@ -6,9 +6,10 @@ # Use-case: The ietf-netconf edit-config has a shorthand version of choice w mandatory: # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/choice.xml fyang=$dir/type.yang @@ -95,7 +96,7 @@ if [ $BE -ne 0 ]; then if [ $? -ne 0 ]; then err fi - pkill clixon_backend # to be sure + sudo pkill clixon_backend # to be sure new "start backend -s init -f $cfg -y $fyang" sudo $clixon_backend -s init -f $cfg -y $fyang diff --git a/test/test_cli.sh b/test/test_cli.sh index b9ff9fc7..bfe9e6fb 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Test1: backend and cli basic functionality # Start backend server # Add an ethernet interface and an address @@ -8,9 +7,13 @@ # Set the mandatory type # 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 + # include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf_yang.xml # Use yang in example diff --git a/test/test_compat.sh b/test/test_compat.sh index 10579b6d..887de956 100755 --- a/test/test_compat.sh +++ b/test/test_compat.sh @@ -3,9 +3,11 @@ # 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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf_startup.xml # Use yang in example @@ -29,7 +31,6 @@ cat < $cfg /usr/local/lib/xmldb/text.so 0 init - true EOF diff --git a/test/test_datastore.sh b/test/test_datastore.sh index 9744413d..a2424ffc 100755 --- a/test/test_datastore.sh +++ b/test/test_datastore.sh @@ -1,12 +1,15 @@ #!/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. -# include err() and new() functions and creates $dir -. ./lib.sh 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 < $fyang module ietf-ip{ @@ -46,126 +49,124 @@ module ietf-ip{ } EOF - - xml='12first-entry13second-entry23third-entryabcastring' -run(){ - name=$1 - mydir=$dir/$name - if [ ! -d $mydir ]; then - mkdir $mydir - fi - rm -rf $mydir/* +name=text - 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" - ret=$($datastore $conf put replace "$xml") - expectmatch "$ret" $? "0" "" +mydir=$dir/$name - new "datastore $name get" - expectfn "$datastore $conf get /" 0 "^$xml$" +if [ ! -d $mydir ]; then + mkdir $mydir +fi +rm -rf $mydir/* - new "datastore $name put all remove" - expectfn "$datastore $conf put remove " 0 "" +# XXX static link +conf="-d candidate -b $mydir -p $clixon_datastore_lib -y $dir/ietf-ip.yang" - new "datastore $name get" - expectfn "$datastore $conf get /" 0 "^$" +new "datastore init" +expectfn "$clixon_util_datastore $conf init" 0 "" - new "datastore $name put all merge" - ret=$($datastore $conf put merge "$xml") - expectmatch "$ret" $? "0" "" - -# expectfn "$datastore $conf put merge $xml" 0 "" +new "datastore put all replace" +ret=$($clixon_util_datastore $conf put replace "$xml") +expectmatch "$ret" $? "0" "" - new "datastore $name get" - expectfn "$datastore $conf get /" 0 "^$xml$" +new "datastore get" +expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$" - new "datastore $name put all delete" - expectfn "$datastore $conf put remove " 0 "" +new "datastore put all remove" +expectfn "$clixon_util_datastore $conf put remove " 0 "" - new "datastore $name get" - expectfn "$datastore $conf get /" 0 "^$" +new "datastore get" +expectfn "$clixon_util_datastore $conf get /" 0 "^$" - new "datastore $name put all create" - ret=$($datastore $conf put create "$xml") - expectmatch "$ret" $? "0" "" +new "datastore put all merge" +ret=$($clixon_util_datastore $conf put merge "$xml") +expectmatch "$ret" $? "0" "" - new "datastore $name get" - expectfn "$datastore $conf get /" 0 "^$xml$" +# expectfn "$clixon_util_datastore $conf put merge $xml" 0 "" - new "datastore $name put top create" - expectfn "$datastore $conf put create " 0 "" # error +new "datastore get" +expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$" - # Single key operations - # leaf - new "datastore $name put all delete" - expectfn "$datastore $conf delete" 0 "" +new "datastore put all delete" +expectfn "$clixon_util_datastore $conf put remove " 0 "" - new "datastore $name init" - expectfn "$datastore $conf init" 0 "" +new "datastore get" +expectfn "$clixon_util_datastore $conf get /" 0 "^$" - new "datastore $name create leaf" - expectfn "$datastore $conf put create 13newentry" 0 "" +new "datastore put all create" +ret=$($clixon_util_datastore $conf put create "$xml") +expectmatch "$ret" $? "0" "" - new "datastore $name create leaf" - expectfn "$datastore $conf put create 13newentry" 0 "" +new "datastore get" +expectfn "$clixon_util_datastore $conf get /" 0 "^$xml$" - new "datastore $name delete leaf" - expectfn "$datastore $conf put delete 13" 0 "" +new "datastore put top create" +expectfn "$clixon_util_datastore $conf put create " 0 "" # error - new "datastore $name replace leaf" - expectfn "$datastore $conf put create 13newentry" 0 "" +# Single key operations +# leaf +new "datastore put all delete" +expectfn "$clixon_util_datastore $conf delete" 0 "" - new "datastore $name remove leaf" - expectfn "$datastore $conf put remove " 0 "" +new "datastore init" +expectfn "$clixon_util_datastore $conf init" 0 "" - new "datastore $name remove leaf" - expectfn "$datastore $conf put remove 13" 0 "" +new "datastore create leaf" +expectfn "$clixon_util_datastore $conf put create 13newentry" 0 "" - new "datastore $name delete leaf" - expectfn "$datastore $conf put delete " 0 "" +new "datastore create leaf" +expectfn "$clixon_util_datastore $conf put create 13newentry" 0 "" - new "datastore $name merge leaf" - expectfn "$datastore $conf put merge nalle" 0 "" +new "datastore delete leaf" +expectfn "$clixon_util_datastore $conf put delete 13" 0 "" - new "datastore $name replace leaf" - expectfn "$datastore $conf put replace nalle" 0 "" +new "datastore replace leaf" +expectfn "$clixon_util_datastore $conf put create 13newentry" 0 "" - new "datastore $name merge leaf" - expectfn "$datastore $conf put merge 13newentry" 0 "" +new "datastore remove leaf" +expectfn "$clixon_util_datastore $conf put remove " 0 "" - new "datastore $name replace leaf" - expectfn "$datastore $conf put replace 13newentry" 0 "" +new "datastore remove leaf" +expectfn "$clixon_util_datastore $conf put remove 13" 0 "" - new "datastore $name create leaf" - expectfn "$datastore $conf put create aaa" 0 "" +new "datastore delete leaf" +expectfn "$clixon_util_datastore $conf put delete " 0 "" - new "datastore $name create leaf" - expectfn "$datastore $conf put create 13newentry" 0 "" +new "datastore merge leaf" +expectfn "$clixon_util_datastore $conf put merge nalle" 0 "" - new "datastore other db init" - expectfn "$datastore -d kalle -b $mydir -p ../datastore/$name/$name.so -y $dir/ietf-ip.yang init" 0 "" +new "datastore replace leaf" +expectfn "$clixon_util_datastore $conf put replace nalle" 0 "" - new "datastore other db copy" - expectfn "$datastore $conf copy kalle" 0 "" +new "datastore merge leaf" +expectfn "$clixon_util_datastore $conf put merge 13newentry" 0 "" - diff $mydir/kalle_db $mydir/candidate_db +new "datastore replace leaf" +expectfn "$clixon_util_datastore $conf put replace 13newentry" 0 "" - new "datastore lock" - expectfn "$datastore $conf lock 756" 0 "" +new "datastore create leaf" +expectfn "$clixon_util_datastore $conf put create aaa" 0 "" + +new "datastore create leaf" +expectfn "$clixon_util_datastore $conf put create 13newentry" 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 - rm -rf $mydir -} - -run text +rm -rf $mydir rm -rf $dir diff --git a/test/test_feature.sh b/test/test_feature.sh index dabc8a3c..4725ff68 100755 --- a/test/test_feature.sh +++ b/test/test_feature.sh @@ -1,8 +1,10 @@ #!/bin/bash # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang diff --git a/test/test_identity.sh b/test/test_identity.sh index 862074ac..7bfdb6da 100755 --- a/test/test_identity.sh +++ b/test/test_identity.sh @@ -1,8 +1,10 @@ #!/bin/bash # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/example-my-crypto.yang diff --git a/test/test_install.sh b/test/test_install.sh index 09867c42..172e1545 100755 --- a/test/test_install.sh +++ b/test/test_install.sh @@ -1,8 +1,8 @@ #!/bin/bash -# Install test +# Install system test -# 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 new "Set up installdir $dir" diff --git a/test/test_json.sh b/test/test_json.sh index c20b3d6b..f15b6ca3 100755 --- a/test/test_json.sh +++ b/test/test_json.sh @@ -2,21 +2,21 @@ # Test: JSON parser tests # 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=../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 -. ./lib.sh +: ${clixon_util_json:=clixon_util_json} new "json parse to xml" -expecteofx "$PROG" 0 '{"foo": -23}' "-23" +expecteofx "$clixon_util_json" 0 '{"foo": -23}' "-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" -expecteofx "$PROG" 0 '{"a":[0,1,2,3]}' "0123" +expecteofx "$clixon_util_json" 0 '{"a":[0,1,2,3]}' "0123" 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 diff --git a/test/test_leafref.sh b/test/test_leafref.sh index 66692d54..7bbefbcd 100755 --- a/test/test_leafref.sh +++ b/test/test_leafref.sh @@ -1,8 +1,11 @@ #!/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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf_yang.xml fyang=$dir/leafref.yang diff --git a/test/test_list.sh b/test/test_list.sh index 2b3ef573..cc9a8f89 100755 --- a/test/test_list.sh +++ b/test/test_list.sh @@ -1,9 +1,10 @@ #!/bin/bash # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang diff --git a/test/test_nacm.sh b/test/test_nacm.sh index 7d384410..e513df63 100755 --- a/test/test_nacm.sh +++ b/test/test_nacm.sh @@ -3,9 +3,12 @@ # See RFC 8341 A.2 # 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 -# include err() and new() functions and creates $dir -. ./lib.sh + +# Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml diff --git a/test/test_nacm_ext.sh b/test/test_nacm_ext.sh index 5acd989a..d5d06e07 100755 --- a/test/test_nacm_ext.sh +++ b/test/test_nacm_ext.sh @@ -4,9 +4,11 @@ # See RFC 8341 A.2 # 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 -# include err() and new() functions and creates $dir -. ./lib.sh +# Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml diff --git a/test/test_nacm_module_read.sh b/test/test_nacm_module_read.sh index 92292bbd..083db895 100755 --- a/test/test_nacm_module_read.sh +++ b/test/test_nacm_module_read.sh @@ -18,9 +18,12 @@ # all content in the server. No subsequent rule will match for the # "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 -# include err() and new() functions and creates $dir -. ./lib.sh + +# Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml diff --git a/test/test_nacm_module_write.sh b/test/test_nacm_module_write.sh index 9cdfe6bc..b2e74170 100755 --- a/test/test_nacm_module_write.sh +++ b/test/test_nacm_module_write.sh @@ -20,9 +20,12 @@ # update | 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 -# include err() and new() functions and creates $dir -. ./lib.sh + +# Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml diff --git a/test/test_nacm_protocol.sh b/test/test_nacm_protocol.sh index c06e41ec..267671af 100755 --- a/test/test_nacm_protocol.sh +++ b/test/test_nacm_protocol.sh @@ -23,9 +23,12 @@ # Which means that restconf -X DELETE /data translates to edit-config + commit # 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 -# include err() and new() functions and creates $dir -. ./lib.sh + +# Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml diff --git a/test/test_netconf.sh b/test/test_netconf.sh index 616f9a96..d113cab5 100755 --- a/test/test_netconf.sh +++ b/test/test_netconf.sh @@ -1,8 +1,10 @@ #!/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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml tmp=$dir/tmp.x diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh index 2fd16ae9..e6f1fd9f 100755 --- a/test/test_openconfig.sh +++ b/test/test_openconfig.sh @@ -7,15 +7,11 @@ # - Env-var MODELS should be 1 # - 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 -# include err() and new() functions and creates $dir -. ./lib.sh - -if [ $MODELS -eq 0 ]; then - exit -fi - cfg=$dir/conf_yang.xml fyang=$dir/test.yang @@ -104,7 +100,7 @@ for f in $files; do exit fi done -echo "m:$ms s:$ss" + new "Openconfig test: $clixon_cli -1f $cfg -y $f show version ($m modules)" for f in $files; do if [ -n "$(head -1 $f|grep '^module')" ]; then diff --git a/test/test_order.sh b/test/test_order.sh index ad002d27..2a7cc198 100755 --- a/test/test_order.sh +++ b/test/test_order.sh @@ -5,9 +5,12 @@ # The ordered-by user MUST be the order it is entered. # No test of ordered-by system is done yet # (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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf_yang.xml fyang=$dir/order.yang tmp=$dir/tmp.x @@ -36,7 +39,6 @@ cat < $cfg 1 $dbdir /usr/local/lib/xmldb/text.so - true EOF @@ -152,7 +154,7 @@ EOF expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "$(cat $tmp)" '424143]]>]]>' # 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 ']]>]]>' '^hejhoppdbcaabcddbarabarcbarbbarabarbbarcbardbarloex:loopbacktrue]]>]]>$' new "get each ordered-by user leaf-list" diff --git a/test/test_perf.sh b/test/test_perf.sh index cd54eda8..c545e9b9 100755 --- a/test/test_perf.sh +++ b/test/test_perf.sh @@ -1,5 +1,8 @@ #!/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 req=100 @@ -15,8 +18,6 @@ else exit 1 # Scaling fi APPNAME=example -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/scaling-conf.xml fyang=$dir/scaling.yang diff --git a/test/test_restconf.sh b/test/test_restconf.sh index e585d378..71797f1e 100755 --- a/test/test_restconf.sh +++ b/test/test_restconf.sh @@ -1,9 +1,12 @@ #!/bin/bash # Restconf basic functionality # 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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf.xml # Use yang in example diff --git a/test/test_restconf2.sh b/test/test_restconf2.sh index a80c7eaa..1eda32c2 100755 --- a/test/test_restconf2.sh +++ b/test/test_restconf2.sh @@ -1,9 +1,12 @@ #!/bin/bash # Restconf basic functionality # 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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf.xml fyang=$dir/restconf.yang diff --git a/test/test_rpc.sh b/test/test_rpc.sh index 467e6992..df0de28e 100755 --- a/test/test_rpc.sh +++ b/test/test_rpc.sh @@ -5,10 +5,12 @@ # Use the example application that has one mandatory input arg, # At the end is an alternative Yang without mandatory arg for # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf.xml # Use yang in example diff --git a/test/test_startup.sh b/test/test_startup.sh index fb9b0102..2eaac38a 100755 --- a/test/test_startup.sh +++ b/test/test_startup.sh @@ -5,9 +5,12 @@ # - An extra xml configuration file starts with an "extra" interface # - running db starts with a "run" 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 -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf_startup.xml cat < $cfg @@ -29,7 +32,6 @@ cat < $cfg /usr/local/lib/xmldb/text.so 0 init - true EOF diff --git a/test/test_stream.sh b/test/test_stream.sh index 5d84de13..c50affef 100755 --- a/test/test_stream.sh +++ b/test/test_stream.sh @@ -20,16 +20,15 @@ # 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications # 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 -UTIL=../util/clixon_util_stream +: ${clixon_util_stream:=clixon_util_stream} 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") -# include err() and new() functions and creates $dir -. ./lib.sh + cfg=$dir/conf.xml fyang=$dir/stream.yang 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 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") @@ -197,7 +196,7 @@ sleep 2 # 2b) start subscription 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") if [ -z "$match" ]; then @@ -210,7 +209,7 @@ fi # 2c 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") if [ -z "$match" ]; then @@ -223,7 +222,7 @@ fi # 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") if [ -z "$match" ]; then @@ -236,7 +235,7 @@ fi # 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") if [ -z "$match" ]; then @@ -254,7 +253,7 @@ curl -s -X GET -H "Accept: text/event-stream" -H "Cache-Control: no-cache" -H " PID=$! 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: ${DATE}T[0-9:.]*ZfaultEthernet0major" match=$(echo "$ret" | grep -Eo "$expect") diff --git a/test/test_type.sh b/test/test_type.sh index b9671830..e8efe848 100755 --- a/test/test_type.sh +++ b/test/test_type.sh @@ -2,10 +2,11 @@ # Advanced union types and generated code # and enum w values # 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 fyang=$dir/type.yang diff --git a/test/test_union.sh b/test/test_union.sh index b11e95e6..57cf1eaa 100755 --- a/test/test_union.sh +++ b/test/test_union.sh @@ -1,9 +1,11 @@ #!/bin/bash # Advanced union types and generated code # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/type.yang diff --git a/test/test_when_must.sh b/test/test_when_must.sh index 9c963d43..ee48314c 100755 --- a/test/test_when_must.sh +++ b/test/test_when_must.sh @@ -2,9 +2,10 @@ # Yang when and must conditional xpath specification # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/test.yang diff --git a/test/test_xml.sh b/test/test_xml.sh index 10267443..52784a12 100755 --- a/test/test_xml.sh +++ b/test/test_xml.sh @@ -3,43 +3,42 @@ # @see https://www.w3.org/TR/2008/REC-xml-20081126 # https://www.w3.org/TR/2009/REC-xml-names-20091208 #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 -. ./lib.sh - -PROG="../util/clixon_util_xml -D $DBG" +: ${clixon_util_xml:=clixon_util_xml} new "xml parse" -expecteof "$PROG" 0 "" "^$" +expecteof "$clixon_util_xml" 0 "" "^$" new "xml parse to json" -expecteof "$PROG -j" 0 "" '{"a": {"b": null}}' +expecteof "$clixon_util_xml -j" 0 "" '{"a": {"b": null}}' new "xml parse strange names" -expecteof "$PROG" 0 "<_->" "<_->" +expecteof "$clixon_util_xml" 0 "<_->" "<_->" new "xml parse name errors" -expecteof "$PROG" 255 "<-a/>" "" +expecteof "$clixon_util_xml" 255 "<-a/>" "" new "xml parse name errors" -expecteof "$PROG" 255 "<9/>" "" +expecteof "$clixon_util_xml" 255 "<9/>" "" new "xml parse name errors" -expecteof "$PROG" 255 "" "" +expecteof "$clixon_util_xml" 255 "" "" LF=' ' new "xml parse content with CR LF -> LF, CR->LF (see https://www.w3.org/TR/REC-xml/#sec-line-ends)" -ret=$(echo "a b${LF}c ${LF}d" | $PROG) +ret=$(echo "a b${LF}c ${LF}d" | $clixon_util_xml) if [ "$ret" != "a${LF}b${LF}c${LF}d" ]; then err 'a$LFb$LFc' "$ret" fi new "xml simple CDATA" -expecteofx "$PROG" 0 '' '' +expecteofx "$clixon_util_xml" 0 '' '' new "xml simple CDATA to json" -expecteofx "$PROG -j" 0 '' '{"a": "a text"}' +expecteofx "$clixon_util_xml -j" 0 '' '{"a": "a text"}' new "xml complex CDATA" XML=$(cat <An example of escaped CENDs +expecteof "$clixon_util_xml" 0 "$XML" "^An example of escaped CENDs y\" so I guess that means that z > x ]]> ]]>]]>$" @@ -65,89 +64,89 @@ JSON=$(cat <Less than: < , greater than: > ampersand: & EOF ) new "xml encode <>&" -expecteof "$PROG" 0 "$XML" "$XML" +expecteof "$clixon_util_xml" 0 "$XML" "$XML" 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 <single-quote character ' represented as ' and double-quote character as " EOF ) new "xml single and double quote" -expecteof "$PROG" 0 "$XML" "single-quote character ' represented as ' and double-quote character as \"" +expecteof "$clixon_util_xml" 0 "$XML" "single-quote character ' represented as ' and double-quote character as \"" JSON=$(cat <a\b" "a\b" +expecteofx "$clixon_util_xml" 0 "a\b" "a\b" new "xml backspace to json" -expecteofx "$PROG -j" 0 "a\b" '{"a": "a\\b"}' +expecteofx "$clixon_util_xml -j" 0 "a\b" '{"a": "a\\b"}' new "Double quotes for attributes" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "Single quotes for attributes (returns double quotes but at least parses right)" -expecteof "$PROG" 0 "" '' +expecteof "$clixon_util_xml" 0 "" '' new "Mixed quotes" -expecteof "$PROG" 0 "" '' +expecteof "$clixon_util_xml" 0 "" '' new "XMLdecl version" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "XMLdecl version, single quotes" -expecteof "$PROG" 0 "" '' +expecteof "$clixon_util_xml" 0 "" '' new "XMLdecl version no element" -expecteof "$PROG" 255 '' '' +expecteof "$clixon_util_xml" 255 '' '' new "XMLdecl no version" -expecteof "$PROG" 255 '' '' +expecteof "$clixon_util_xml" 255 '' '' new "XMLdecl misspelled version" -expecteof "$PROG -l o" 255 '' '' +expecteof "$clixon_util_xml -l o" 255 '' '' new "XMLdecl version + encoding" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "XMLdecl version + misspelled encoding" -expecteof "$PROG -l o" 255 '' 'syntax error: at or before: e' +expecteof "$clixon_util_xml -l o" 255 '' 'syntax error: at or before: e' new "XMLdecl version + standalone" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "PI - Processing instruction empty" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "PI some content" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' new "prolog element misc*" -expecteof "$PROG" 0 '' '' +expecteof "$clixon_util_xml" 0 '' '' # We allow it as an internal necessity for parsing of xml fragments #new "double element error" -#expecteof "$PROG" 255 '' '' +#expecteof "$clixon_util_xml" 255 '' '' new "namespace: DefaultAttName" -expecteof "$PROG" 0 'hello' 'hello' +expecteof "$clixon_util_xml" 0 'hello' 'hello' new "namespace: PrefixedAttName" -expecteof "$PROG" 0 'hello' '^hello$' +expecteof "$clixon_util_xml" 0 'hello' '^hello$' new "First example 6.1 from https://www.w3.org/TR/2009/REC-xml-names-20091208" XML=$(cat < 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" XML=$(cat < EOF ) -expecteof "$PROG" 0 "$XML" "$XML" +expecteof "$clixon_util_xml" 0 "$XML" "$XML" rm -rf $dir diff --git a/test/test_xpath.sh b/test/test_xpath.sh index d8fcca34..4ca2dd12 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -1,10 +1,11 @@ #!/bin/bash # Test: XPATH tests #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 -. ./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 + +: ${clixon_util_xpath:=clixon_util_xpath} # XML file (alt provide it in stdin after xpath) xml=$dir/xml.xml @@ -76,117 +77,117 @@ cat < $xml3 EOF new "xpath /" -expecteof "$PROG -f $xml -p /" 0 "" "^nodeset:0:429922$" +expecteof "$clixon_util_xpath -f $xml -p /" 0 "" "^nodeset:0:429922$" new "xpath /aaa" -expecteof "$PROG -f $xml -p /aaa" 0 "" "^nodeset:0:429922$" +expecteof "$clixon_util_xpath -f $xml -p /aaa" 0 "" "^nodeset:0:429922$" 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" -expecteof "$PROG -f $xml -p /aaa/bbb" 0 "" "^0:42 +expecteof "$clixon_util_xpath -f $xml -p /aaa/bbb" 0 "" "^0:42 1:99$" new "xpath //bbb" -expecteof "$PROG -f $xml -p //bbb" 0 "" "0:42 +expecteof "$clixon_util_xpath -f $xml -p //bbb" 0 "" "0:42 1:99" new "xpath //b?b" -#expecteof "$PROG -f $xml" 0 "//b?b" "" +#expecteof "$clixon_util_xpath -f $xml" 0 "//b?b" "" new "xpath //b*" -#expecteof "$PROG -f $xml" 0 "//b*" "" +#expecteof "$clixon_util_xpath -f $xml" 0 "//b*" "" new "xpath //b*/ccc" -#expecteof "$PROG -f $xml" 0 "//b*/ccc" "" +#expecteof "$clixon_util_xpath -f $xml" 0 "//b*/ccc" "" new "xpath //bbb[0]" -expecteof "$PROG -f $xml -p //bbb[0]" 0 "" "^nodeset:0:42$" +expecteof "$clixon_util_xpath -f $xml -p //bbb[0]" 0 "" "^nodeset:0:42$" new "xpath //bbb[ccc=99]" -expecteof "$PROG -f $xml -p //bbb[ccc=99]" 0 "" "^nodeset:0:99$" +expecteof "$clixon_util_xpath -f $xml -p //bbb[ccc=99]" 0 "" "^nodeset:0:99$" 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'" -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" -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" -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" -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'" -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'" -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'" -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'" -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'" -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" -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" -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" -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" -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" -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" -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" -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" -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" -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" -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)" -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']" -expecteof "$PROG -f $xml2 -p .[name='bar'] -i /aaa/bbb/routing/ribs/rib" 0 "" "^nodeset:0:barmyfamily$" +expecteof "$clixon_util_xpath -f $xml2 -p .[name='bar'] -i /aaa/bbb/routing/ribs/rib" 0 "" "^nodeset:0:barmyfamily$" new "Multiple entries" new "xpath bbb[ccc='foo']" -expecteof "$PROG -f $xml3 -p bbb[ccc='foo']" 0 "" "^nodeset:0:foo42bar1:99foo$" +expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='foo']" 0 "" "^nodeset:0:foo42bar1:99foo$" new "xpath bbb[ccc='42']" -expecteof "$PROG -f $xml3 -p bbb[ccc='42']" 0 "" "^nodeset:0:foo42bar$" +expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='42']" 0 "" "^nodeset:0:foo42bar$" new "xpath bbb[ccc=99] (number w/o quotes)" -expecteof "$PROG -f $xml3 -p bbb[ccc=99]" 0 "" "^nodeset:0:99foo$" +expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc=99]" 0 "" "^nodeset:0:99foo$" new "xpath bbb[ccc='bar']" -expecteof "$PROG -f $xml3 -p bbb[ccc='bar']" 0 "" "^nodeset:0:foo42bar$" +expecteof "$clixon_util_xpath -f $xml3 -p bbb[ccc='bar']" 0 "" "^nodeset:0:foo42bar$" 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 diff --git a/test/test_yang.sh b/test/test_yang.sh index e6131381..e12c766c 100755 --- a/test/test_yang.sh +++ b/test/test_yang.sh @@ -1,8 +1,10 @@ #!/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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang=$dir/$APPNAME.yang diff --git a/test/test_yang_load.sh b/test/test_yang_load.sh index a54bac5e..1f6468ad 100755 --- a/test/test_yang_load.sh +++ b/test/test_yang_load.sh @@ -4,9 +4,11 @@ # as well as revisions # Test is made by having different config files and then try to set configure # 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 -# include err() and new() functions and creates $dir -. ./lib.sh cfg=$dir/conf_yang.xml fyang1=$dir/$APPNAME@2018-12-02.yang diff --git a/test/test_yang_namespace.sh b/test/test_yang_namespace.sh index 6f83e94f..d0f78a05 100755 --- a/test/test_yang_namespace.sh +++ b/test/test_yang_namespace.sh @@ -1,12 +1,13 @@ #!/bin/bash - -APPNAME=example -# test two modules example1 and example2 with overlapping statements x. +# Test two modules example1 and example2 with overlapping statements x. # x is leaf in example1 and list on example2. # Test netconf and restconf # 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 fyang1=$dir/example1.yang diff --git a/test/test_yangmodels.sh b/test/test_yangmodels.sh index 8277a848..12d83d3a 100755 --- a/test/test_yangmodels.sh +++ b/test/test_yangmodels.sh @@ -1,7 +1,6 @@ #!/bin/bash # Parse yangmodels from https://github.com/YangModels/yang # Notes: -# - Env-var MODELS should be 1 # - 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/xe/1631 # Many other versions @@ -17,16 +16,12 @@ #./vendor/cisco/xe/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 APPNAME=example -# include err() and new() functions and creates $dir -. ./lib.sh - -if [ $MODELS -eq 0 ]; then - exit -fi - cfg=$dir/conf_yang.xml fyang=$dir/test.yang diff --git a/util/Makefile.in b/util/Makefile.in index 9d4cebc0..b5abfd15 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -43,6 +43,7 @@ libexecdir = @libexecdir@ localstatedir = @localstatedir@ sysconfdir = @sysconfdir@ HOST_VENDOR = @host_vendor@ +with_restconf = @with_restconf@ SH_SUFFIX = @SH_SUFFIX@ @@ -70,12 +71,14 @@ APPSRC = clixon_util_xml.c APPSRC += clixon_util_json.c APPSRC += clixon_util_yang.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=) all: $(APPS) - @echo "You may want to make clixon_util_stream separately (curl dependency)" clean: 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) $(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 rm -f Makefile *~ .depend install: -# install -d -m 0755 $(DESTDIR)$(bindir) -# install -m 0755 $(INSTALLFLAGS) $(APPS) $(DESTDIR)$(bindir) - + install -d -m 0755 $(DESTDIR)$(bindir) + install -m 0755 $(INSTALLFLAGS) $(APPS) $(DESTDIR)$(bindir) install-include: diff --git a/datastore/datastore_client.c b/util/clixon_util_datastore.c similarity index 98% rename from datastore/datastore_client.c rename to util/clixon_util_datastore.c index b2a0a2a8..eb828009 100644 --- a/datastore/datastore_client.c +++ b/util/clixon_util_datastore.c @@ -117,7 +117,7 @@ main(int argc, char **argv) cbuf *cbret = NULL; /* 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]; /* Defaults */ @@ -157,7 +157,7 @@ main(int argc, char **argv) /* * 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); argc -= optind;