docker base and system images, and trigger docker test from travis.

This commit is contained in:
Olof Hagsand 2019-02-11 15:47:12 +01:00
parent 84d2efdedc
commit dc173e0b4c
14 changed files with 72 additions and 54 deletions

View file

@ -141,8 +141,10 @@ pkg-srpm: dist
example: example:
(cd $@ && $(MAKE) $(MFLAGS) all) (cd $@ && $(MAKE) $(MFLAGS) all)
test: #example # Run a clixon test container.
(cd $@ && $(MAKE) $(MFLAGS) all) # Alt: cd test; ./all.sh
test:
(cd docker/system && $(MAKE) $(MFLAGS) test)
docker: docker:
for i in docker; \ for i in docker; \

View file

@ -20,12 +20,12 @@ support.
* [Datastore](datastore/README.md) * [Datastore](datastore/README.md)
* [Authentication](#auth) * [Authentication](#auth)
* [NACM Access control](#nacm) * [NACM Access control](#nacm)
* [Example](example/) * [Example](example/README.md)
* [Changelog](CHANGELOG.md) * [Changelog](CHANGELOG.md)
* [Runtime](#runtime) * [Runtime](#runtime)
* [Clixon project page](http://www.clicon.org) * [Clixon project page](http://www.clicon.org)
* [Tests](test/) * [Tests](test/README.md)
* [Docker](docker/) * [Docker](docker/README.md)
* [Roadmap](ROADMAP.md) * [Roadmap](ROADMAP.md)
* [Reference manual](#reference) * [Reference manual](#reference)

View file

@ -243,13 +243,20 @@ information on all modules and which features are enabled.
## Can I run Clixon as docker containers? ## Can I run Clixon as docker containers?
Yes, the example works as docker containers as well. There should be a Yes, Clixon has two examples on how to build docker containers. A [base](../docker/base) image and a complete [example system](../docker/system).
prepared container in docker hub for the example where the backend and
CLI is bundled. The base image can only be used as a boilerplate for building clixon
``` applications (it has no applications semantics); whereas the system is
sudo docker run -td olofhagsand/clixon_example a complete example applications with CLI/Netconf/Restconf, and
``` testing.
Look in the example documentation for more info.
For example, the clixon-system container can be used as follows:
* CLI: `sudo docker exec -it clixon-system clixon_cli`
* Netconf: `sudo docker exec -it clixon-system clixon_netconf`
* Restconf: `curl -G http://localhost/restconf`
* Run tests: `sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test; exec ./all.sh'`
See [../docker](../docker) for more info.
## Does Clixon support event streams? ## Does Clixon support event streams?

View file

@ -1,6 +1,7 @@
# Clixon base docker image # Clixon and dockers
This directory contains sub-directories with examples of Clixon docker images: This directory contains sub-directories with examples of Clixon docker images:
* [base] Clixon base image (pulls code from github)
* [system] Example and test application (builds from local dir) * [base](base/README.md) Clixon base image
* [system](system/README.md) Example and test application

View file

@ -44,9 +44,8 @@ RUN apt-get update && apt-get install -y \
RUN mkdir /clixon RUN mkdir /clixon
WORKDIR /clixon WORKDIR /clixon
# Clone cligen and clixon # Clone cligen
RUN git clone https://github.com/olofhagsand/cligen.git RUN git clone https://github.com/olofhagsand/cligen.git
RUN git clone https://github.com/clicon/clixon.git
# Build cligen # Build cligen
WORKDIR /clixon/cligen WORKDIR /clixon/cligen
@ -54,8 +53,12 @@ RUN ./configure
RUN make RUN make
RUN make install RUN make install
# Build clixon # Copy Clixon from local dir
RUN mkdir /clixon/clixon
WORKDIR /clixon/clixon WORKDIR /clixon/clixon
COPY clixon .
# Build clixon
RUN ./configure RUN ./configure
RUN make RUN make
RUN make install RUN make install

View file

@ -48,12 +48,16 @@ SHELL = /bin/sh
all: all:
echo "Run make docker to build docker image" echo "Run make docker to build docker image"
# (recursively) clone the repo from top-level - NOTE changes must be committed
clixon:
git clone file://$(realpath ${top_srcdir})
clean: clean:
distclean: clean distclean: clean
rm -f Makefile *~ .depend rm -f Makefile *~ .depend
docker: Dockerfile docker: clixon Dockerfile
sudo docker build -t $(IMG) . # --no-cache sudo docker build -t $(IMG) . # --no-cache
push: push:

View file

@ -6,15 +6,14 @@ the IMAGE in Makefile.in and push it to another name.
The clixon docker base image can be used to build clixon The clixon docker base image can be used to build clixon
applications. It has all the whole code for a clixon release which it applications. It has all the whole code for a clixon release which it
downloads from git - it does not use local code (note it may even use downloads from git.
develop branch).
See [../system/README.md] for how to build the clixon example application using the base image. 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`.
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 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 run the container directly by going directly to example and
the docker runtime scripts there the docker runtime scripts there

View file

@ -45,8 +45,8 @@ RUN apt-get update && apt-get install -y \
# Application-specific # Application-specific
RUN apt-get update && apt-get install -y nginx RUN apt-get update && apt-get install -y nginx
# Test-specific # Test-specific (for test scripts)
RUN apt-get update && apt-get install -y sudo curl procps # for test scripts RUN apt-get update && apt-get install -y sudo curl procps time
# The example uses "clicon" group # The example uses "clicon" group
RUN groupadd clicon RUN groupadd clicon

View file

@ -43,7 +43,7 @@ IMG = clixon/clixon-system
SHELL = /bin/sh SHELL = /bin/sh
.PHONY: all clean depend install docker push clixon-system .PHONY: all clean distclean docker test push depend install-include install uninstall
all: all:
echo "Run make docker to build docker image" echo "Run make docker to build docker image"
@ -61,6 +61,11 @@ distclean: clean
docker: clixon Dockerfile docker: clixon Dockerfile
sudo docker build -t $(IMG) . # --no-cache sudo docker build -t $(IMG) . # --no-cache
# Start the clixon system container and run the test script
test: docker
./start.sh
sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test; exec ./all.sh'
push: push:
depend: depend:

View file

@ -48,3 +48,5 @@ To check status and then kill it:
$ sudo docker ps --all $ sudo docker ps --all
$ ./cleanup.sh $ ./cleanup.sh
``` ```
You can also trigger the test scripts inside the container using `make test`.

View file

@ -43,9 +43,6 @@ SHELL = /bin/sh
.PHONY: all clean distclean depend install uninstall .PHONY: all clean distclean depend install uninstall
all: all:
./test_xml.sh
./test_json.sh
# ./all.sh
clean: clean:

View file

@ -69,25 +69,25 @@ run(){
case $mode in case $mode in
readlist) readlist)
time -p for (( i=0; i<$reqs; i++ )); do /usr/bin/time -p for (( i=0; i<$reqs; i++ )); do
rnd=$(( ( RANDOM % $nr ) )) rnd=$(( ( RANDOM % $nr ) ))
echo "<rpc><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/x/y[a=$rnd][b=$rnd]\" /></get-config></rpc>]]>]]>" echo "<rpc><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/x/y[a=$rnd][b=$rnd]\" /></get-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null
;; ;;
writelist) writelist)
time -p for (( i=0; i<$reqs; i++ )); do /usr/bin/time -p for (( i=0; i<$reqs; i++ )); do
rnd=$(( ( RANDOM % $nr ) )) rnd=$(( ( RANDOM % $nr ) ))
echo "<rpc><edit-config><target><candidate/></target><config><x><y><a>$rnd</a><b>$rnd</b></y></x></config></edit-config></rpc>]]>]]>" echo "<rpc><edit-config><target><candidate/></target><config><x><y><a>$rnd</a><b>$rnd</b></y></x></config></edit-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null
;; ;;
restreadlist) restreadlist)
time -p for (( i=0; i<$reqs; i++ )); do /usr/bin/time -p for (( i=0; i<$reqs; i++ )); do
rnd=$(( ( RANDOM % $nr ) )) rnd=$(( ( RANDOM % $nr ) ))
curl -sSG http://localhost/restconf/data/x/y=$rnd,$rnd > /dev/null curl -sSG http://localhost/restconf/data/x/y=$rnd,$rnd > /dev/null
done done
;; ;;
writeleaflist) writeleaflist)
time -p for (( i=0; i<$reqs; i++ )); do /usr/bin/time -p for (( i=0; i<$reqs; i++ )); do
rnd=$(( ( RANDOM % $nr ) )) rnd=$(( ( RANDOM % $nr ) ))
echo "<rpc><edit-config><target><candidate/></target><config><x><c>$rnd</c></x></config></edit-config></rpc>]]>]]>" echo "<rpc><edit-config><target><candidate/></target><config><x><c>$rnd</c></x></config></edit-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null

View file

@ -94,52 +94,52 @@ echo "</x></config></edit-config></rpc>]]>]]>" >> $fconfig
echo "$clixon_netconf -qf $cfg -y $fyang" echo "$clixon_netconf -qf $cfg -y $fyang"
new "netconf write large config" new "netconf write large config"
expecteof_file "time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof_file "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
#echo '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' | $clixon_netconf -qf $cfg -y $fyang #echo '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' | $clixon_netconf -qf $cfg -y $fyang
new "netconf write large config again" new "netconf write large config again"
expecteof_file "time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof_file "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
#echo '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' | $clixon_netconf -qf $cfg -y $fyang #echo '<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>' | $clixon_netconf -qf $cfg -y $fyang
rm $fconfig rm $fconfig
new "netconf commit large config" new "netconf commit large config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf commit large config again" new "netconf commit large config again"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf add small (1 entry) config" new "netconf add small (1 entry) config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>x</a><b>y</b></y></x></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><y><a>x</a><b>y</b></y></x></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf get $req small config" new "netconf get $req small config"
time -p for (( i=0; i<$req; i++ )); do /usr/bin/time -p for (( i=0; i<$req; i++ )); do
rnd=$(( ( RANDOM % $number ) )) rnd=$(( ( RANDOM % $number ) ))
echo "<rpc><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/x/y[a=$rnd][b=$rnd]\" /></get-config></rpc>]]>]]>" echo "<rpc><get-config><source><candidate/></source><filter type=\"xpath\" select=\"/x/y[a=$rnd][b=$rnd]\" /></get-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null
new "netconf get $req restconf small config" new "netconf get $req restconf small config"
time -p for (( i=0; i<$req; i++ )); do /usr/bin/time -p for (( i=0; i<$req; i++ )); do
rnd=$(( ( RANDOM % $number ) )) rnd=$(( ( RANDOM % $number ) ))
#XXX curl -sX PUT -d {"y":{"a":"$rnd","b":"$rnd"}} http://localhost/restconf/data/x/y=$rnd,$rnd #XXX curl -sX PUT -d {"y":{"a":"$rnd","b":"$rnd"}} http://localhost/restconf/data/x/y=$rnd,$rnd
done done
new "netconf add $req small config" new "netconf add $req small config"
time -p for (( i=0; i<$req; i++ )); do /usr/bin/time -p for (( i=0; i<$req; i++ )); do
rnd=$(( ( RANDOM % $number ) )) rnd=$(( ( RANDOM % $number ) ))
echo "<rpc><edit-config><target><candidate/></target><config><x xmlns=\"urn:example:clixon\"><y><a>$rnd</a><b>$rnd</b></y></x></config></edit-config></rpc>]]>]]>" echo "<rpc><edit-config><target><candidate/></target><config><x xmlns=\"urn:example:clixon\"><y><a>$rnd</a><b>$rnd</b></y></x></config></edit-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null
new "netconf add $req restconf small config" new "netconf add $req restconf small config"
time -p for (( i=0; i<$req; i++ )); do /usr/bin/time -p for (( i=0; i<$req; i++ )); do
rnd=$(( ( RANDOM % $number ) )) rnd=$(( ( RANDOM % $number ) ))
curl -sG http://localhost/restconf/data/x/y=$rnd,$rnd > /dev/null curl -sG http://localhost/restconf/data/x/y=$rnd,$rnd > /dev/null
done done
new "netconf get large config" new "netconf get large config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>" '^<rpc-reply><data><x xmlns="urn:example:clixon"><y><a>0</a><b>0</b></y><y><a>1</a><b>1</b>' expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>" '^<rpc-reply><data><x xmlns="urn:example:clixon"><y><a>0</a><b>0</b></y><y><a>1</a><b>1</b>'
new "generate large leaf-list config" new "generate large leaf-list config"
echo -n "<rpc><edit-config><target><candidate/></target><default-operation>replace</default-operation><config><x xmlns=\"urn:example:clixon\">" > $fconfig echo -n "<rpc><edit-config><target><candidate/></target><default-operation>replace</default-operation><config><x xmlns=\"urn:example:clixon\">" > $fconfig
@ -149,27 +149,27 @@ done
echo "</x></config></edit-config></rpc>]]>]]>" >> $fconfig echo "</x></config></edit-config></rpc>]]>]]>" >> $fconfig
new "netconf replace large list-leaf config" new "netconf replace large list-leaf config"
expecteof_file "time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof_file "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" "$fconfig" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
rm $fconfig rm $fconfig
new "netconf commit large leaf-list config" new "netconf commit large leaf-list config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf add $req small leaf-list config" new "netconf add $req small leaf-list config"
time -p for (( i=0; i<$req; i++ )); do /usr/bin/time -p for (( i=0; i<$req; i++ )); do
rnd=$(( ( RANDOM % $number ) )) rnd=$(( ( RANDOM % $number ) ))
echo "<rpc><edit-config><target><candidate/></target><config><x xmlns=\"urn:example:clixon\"><c>$rnd</c></x></config></edit-config></rpc>]]>]]>" echo "<rpc><edit-config><target><candidate/></target><config><x xmlns=\"urn:example:clixon\"><c>$rnd</c></x></config></edit-config></rpc>]]>]]>"
done | $clixon_netconf -qf $cfg -y $fyang > /dev/null done | $clixon_netconf -qf $cfg -y $fyang > /dev/null
new "netconf add small leaf-list config" new "netconf add small leaf-list config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><c>x</c></x></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 '<rpc><edit-config><target><candidate/></target><config><x xmlns="urn:example:clixon"><c>x</c></x></config></edit-config></rpc>]]>]]>' "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf commit small leaf-list config" new "netconf commit small leaf-list config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$" expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf get large leaf-list config" new "netconf get large leaf-list config"
expecteof "time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>" '^<rpc-reply><data><x xmlns="urn:example:clixon"><c>0</c><c>1</c>' expecteof "/usr/bin/time -f %e $clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>" '^<rpc-reply><data><x xmlns="urn:example:clixon"><c>0</c><c>1</c>'
new "Kill restconf daemon" new "Kill restconf daemon"
sudo pkill -u www-data -f "/www-data/clixon_restconf" sudo pkill -u www-data -f "/www-data/clixon_restconf"

View file

@ -10,7 +10,5 @@ sudo make install-include
sudo groupadd clicon sudo groupadd clicon
sudo usermod -a -G clicon $(whoami) sudo usermod -a -G clicon $(whoami)
sudo usermod -a -G clicon www-data sudo usermod -a -G clicon www-data
# Build and start the system docker container # Build the system docker container (make test may trigger it)
(cd docker/system && make docker && ./start.sh) (cd docker/system && make docker)
# Run clixon testcases
(cd docker/system && sudo docker exec -it clixon-system bash -c 'cd /clixon/clixon/test; exec ./all.sh')