From 8c5a5a0fb36dba6603dec5be30a7188fdd888b84 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 7 Dec 2021 20:01:14 +0100 Subject: [PATCH] * New docker build (preliminary) for a development container * Load clixon-clispec on start --- .github/workflows/ci.yml | 4 +- CHANGELOG.md | 5 +- apps/cli/cli_main.c | 5 ++ configure | 5 +- configure.ac | 3 +- docker/README.md | 6 +- docker/clixon-dev/Dockerfile | 86 ++++++++++++++++++++++++++++ docker/clixon-dev/Makefile.in | 74 ++++++++++++++++++++++++ docker/clixon-dev/README.md | 21 +++++++ test/test_cli_varonly.sh | 102 ++++++++++++++++++++++++++++++++++ yang/clixon/Makefile.in | 1 + 11 files changed, 303 insertions(+), 9 deletions(-) create mode 100644 docker/clixon-dev/Dockerfile create mode 100644 docker/clixon-dev/Makefile.in create mode 100644 docker/clixon-dev/README.md create mode 100755 test/test_cli_varonly.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c476810..f2399103 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,12 @@ jobs: # 1) checkout and compile natively - name: install cligen run: (git clone https://github.com/clicon/cligen.git && cd cligen && ./configure && make && sudo make install) - - name: install libevent + - name: install libevent, ssl and nghttp2 run: sudo apt install -y libevent-dev libssl-dev libnghttp2-dev - name: install libevhtp run: (git clone https://github.com/clicon/clixon-libevhtp.git && cd clixon-libevhtp && ./configure && make && sudo make install) - name: configure - run: ./configure --with-restconf=native + run: ./configure # 2) Use docker for tests - name: make test # this is docker test run: make test \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a23840..648f70de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,8 +37,9 @@ Planned: January, 2022 ### Minor features -* Changed typo `configure --with-yang-standard-installdir` to `configure --with-yang-standard-dir -` +* New `clixon-dev` development container (Work-in-progress) +* New `clixon-clispec.yang` for controlling auto-cli (Work-in-progress) +* Changed typo `configure --with-yang-standard-installdir` to `configure --with-yang-standard-dir` ### Corrected Bugs diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 9b2c68d8..68e84ff8 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -268,7 +268,12 @@ autocli_start(clicon_handle h, /* If autocli disabled quit */ if ((autocli_model = clicon_cli_genmodel(h)) == 0) goto ok; + yspec = clicon_dbspec_yang(h); + /* Load clispec for autocli */ + if (yang_spec_parse_module(h, "clixon-clispec", NULL, yspec)< 0) + goto done; + /* Get the autocli type, ie HOW the cli is generated (could be much more here) */ /* Create show_treename cbuf */ if ((show_treename = cbuf_new()) == NULL){ diff --git a/configure b/configure index ab8b7652..753420a9 100755 --- a/configure +++ b/configure @@ -5678,7 +5678,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 example/main/Makefile example/main/example.xml extras/rpm/Makefile docker/Makefile docker/main/Makefile docker/base/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/mandatory/Makefile doc/Makefile test/Makefile test/config.sh test/cicd/Makefile test/vagrant/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 example/main/Makefile example/main/example.xml extras/rpm/Makefile docker/Makefile docker/base/Makefile docker/clixon-dev/Makefile docker/main/Makefile util/Makefile yang/Makefile yang/clixon/Makefile yang/mandatory/Makefile doc/Makefile test/Makefile test/config.sh test/cicd/Makefile test/vagrant/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -6389,8 +6389,9 @@ do "example/main/example.xml") CONFIG_FILES="$CONFIG_FILES example/main/example.xml" ;; "extras/rpm/Makefile") CONFIG_FILES="$CONFIG_FILES extras/rpm/Makefile" ;; "docker/Makefile") CONFIG_FILES="$CONFIG_FILES docker/Makefile" ;; - "docker/main/Makefile") CONFIG_FILES="$CONFIG_FILES docker/main/Makefile" ;; "docker/base/Makefile") CONFIG_FILES="$CONFIG_FILES docker/base/Makefile" ;; + "docker/clixon-dev/Makefile") CONFIG_FILES="$CONFIG_FILES docker/clixon-dev/Makefile" ;; + "docker/main/Makefile") CONFIG_FILES="$CONFIG_FILES docker/main/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 1fb3f34c..83fc588e 100644 --- a/configure.ac +++ b/configure.ac @@ -368,8 +368,9 @@ AC_OUTPUT(Makefile example/main/example.xml extras/rpm/Makefile docker/Makefile + docker/base/Makefile + docker/clixon-dev/Makefile docker/main/Makefile - docker/base/Makefile util/Makefile yang/Makefile yang/clixon/Makefile diff --git a/docker/README.md b/docker/README.md index 4a77944f..1594cbfe 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,6 +2,8 @@ This directory contains sub-directories with examples of Clixon docker images: - * [base](base/README.md) Clixon base image - * [main](main/README.md) Main example and test application used in upstream CI + * [base](base/README.md) Clixon base image + * [clixon-dev](clixon-dev/README.md) Clixon development image + * [main](main/README.md) Main example and test application used in upstream CI + diff --git a/docker/clixon-dev/Dockerfile b/docker/clixon-dev/Dockerfile new file mode 100644 index 00000000..6fc57cde --- /dev/null +++ b/docker/clixon-dev/Dockerfile @@ -0,0 +1,86 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# +# Copyright (C) 2017-2019 Olof Hagsand +# Copyright (C) 2020-2021 Olof Hagsand and Rubicon Communications, LLC(Netgate) +# +# 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 ***** +# + +FROM alpine +MAINTAINER Olof Hagsand + +# For clixon and cligen +RUN apk add --update git make build-base gcc flex bison curl-dev + +# evhtp dependencies +RUN apk add --update libevent libevent-dev + +# nghttp2 dependencies +RUN apk add --update nghttp2 + +# Create a directory to hold source-code, dependencies etc +RUN mkdir /clixon + +# clone libevhtp +WORKDIR /clixon + +RUN git clone https://github.com/clicon/clixon-libevhtp.git +WORKDIR /clixon/clixon-libevhtp +RUN ./configure + +RUN make +RUN mkdir /usr/local/include +RUN make install + +RUN mkdir /clixon/build +WORKDIR /clixon + +# Clone cligen +RUN git clone https://github.com/clicon/cligen.git + +# Build cligen +WORKDIR /clixon/cligen +RUN ./configure --prefix=/clixon/build +RUN make +RUN make install + +# Need to add www user manually +RUN adduser -D -H -G www-data www-data + +# Copy Clixon from local dir +RUN mkdir /clixon/clixon +WORKDIR /clixon/clixon +COPY clixon . + +# Configure, build and install clixon +RUN ./configure --prefix=/clixon/build --with-cligen=/clixon/build --with-restconf=native --enable-nghttp2 --enable-evhtp + +RUN make +RUN make install + diff --git a/docker/clixon-dev/Makefile.in b/docker/clixon-dev/Makefile.in new file mode 100644 index 00000000..e733e7ac --- /dev/null +++ b/docker/clixon-dev/Makefile.in @@ -0,0 +1,74 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# +# Copyright (C) 2017-2019 Olof Hagsand +# Copyright (C) 2020-2021 Olof Hagsand and Rubicon Communications, LLC(Netgate) +# +# 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 ***** +# +VPATH = @srcdir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +CC = @CC@ +CFLAGS = @CFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ + +# docker.hub image. CHANGE THIS IF YOU PUSH YOUR OWN +IMG = clixon/clixon-dev # base image + +SHELL = /bin/sh + +.PHONY: all clean distclean docker push depend install-include install uninstall + +all: + 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: + rm -rf clixon # clone of top-srcdir + +distclean: clean + rm -f Makefile *~ .depend + +docker: clixon Dockerfile + sudo docker build -t $(IMG) . # --no-cache + +push: + sudo docker push $(IMG) +depend: + +install-include: + +install: + +uninstall: + diff --git a/docker/clixon-dev/README.md b/docker/clixon-dev/README.md new file mode 100644 index 00000000..e4da5eb0 --- /dev/null +++ b/docker/clixon-dev/README.md @@ -0,0 +1,21 @@ +# Clixon base development docker image + +This directory contains code for building a clixon base development +docker container that can be used as a stage 1 builder for clixon appplications + +This clixon base container uses native http. + +The clixon docker base image can be used to build clixon +applications. It has the whole code for a clixon release which it +downloads from git. + +## Build + +Perform the build by `make docker`. This copies the latest _committed_ clixon code into the container. + +## Push + +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 ) + diff --git a/test/test_cli_varonly.sh b/test/test_cli_varonly.sh new file mode 100755 index 00000000..bca7bc48 --- /dev/null +++ b/test/test_cli_varonly.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# test for cli when CLICON_CLI_VARONLY is 0 +# I.e., INCLUDE keys + +# 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 + +cfg=$dir/conf.xml +fyang=$dir/example.yang + +# Use yang in example + +cat < $cfg + + $cfg + /usr/local/share/clixon + $IETFRFC + $dir + example + /usr/local/lib/$APPNAME/backend + $APPNAME + /usr/local/lib/$APPNAME/cli + 0 + /usr/local/lib/$APPNAME/clispec + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + $dir + +EOF + +cat < $fyang +module example { + yang-version 1.1; + namespace "urn:example:example"; + prefix ex; + + /* Generic config data */ + container table{ + list parameter{ + key name; + leaf name{ + type string; + } + leaf value{ + type string; + } + } + } +} +EOF + +new "test params: -f $cfg" +if [ $BE -ne 0 ]; then + new "kill old backend" + sudo clixon_backend -z -f $cfg + if [ $? -ne 0 ]; then + err + fi + new "start backend -s init -f $cfg" + start_backend -s init -f $cfg +fi + +new "wait backend" +wait_backend + +new "cli set 42 include keys" +expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg set table parameter 42)" 0 "^$" + +new "cli set 43 exclude keys" +expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg set table parameter 43)" 0 "^$" + +new "cli show 42 43 include" +expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43" + +new "cli show 42 43 exclude" +expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43" + +new "cli expand include keys" +expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=0 -f $cfg 2>&1)" 0 42 43 + +new "cli expand exclude keys" +expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=1 -f $cfg 2>&1)" 0 42 43 + +if [ $BE -ne 0 ]; then + new "Kill backend" + # Check if premature kill + pid=$(pgrep -u root -f clixon_backend) + if [ -z "$pid" ]; then + err "backend already dead" + fi + # kill backend + stop_backend -f $cfg +fi + +rm -rf $dir + +new "endtest" +endtest diff --git a/yang/clixon/Makefile.in b/yang/clixon/Makefile.in index 4bb2b6ef..fa8de963 100644 --- a/yang/clixon/Makefile.in +++ b/yang/clixon/Makefile.in @@ -47,6 +47,7 @@ YANGSPECS += clixon-lib@2021-11-11.yang # 5.4 YANGSPECS += clixon-rfc5277@2008-07-01.yang YANGSPECS += clixon-xml-changelog@2019-03-21.yang YANGSPECS += clixon-restconf@2021-05-20.yang # 5.2 +YANGSPECS += clixon-clispec@2021-12-05.yang APPNAME = clixon # subdir ehere these files are installed