Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvasko committed Jun 6, 2018
2 parents befbfe1 + 208cbcd commit db2933f
Show file tree
Hide file tree
Showing 34 changed files with 1,559 additions and 898 deletions.
9 changes: 5 additions & 4 deletions .travis-deps-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make -j2 && sudo make install
cd ../..

# CMocka
wget https://cmocka.org/files/1.0/cmocka-1.0.1.tar.xz
tar -xJf cmocka-1.0.1.tar.xz
mkdir cmocka-1.0.1/build && cd cmocka-1.0.1/build
wget https://cmocka.org/files/1.1/cmocka-1.1.1.tar.xz
tar -xJf cmocka-1.1.1.tar.xz
mkdir cmocka-1.1.1/build && cd cmocka-1.1.1/build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make -j2 && sudo make install
cd ../..

git clone -b $TRAVIS_BRANCH https://github.com/CESNET/libyang.git
if [[ "$TRAVIS_BRANCH" = "master" ]]; then LY_BRANCH="master"; else LY_BRANCH="devel"; fi
git clone -b $LY_BRANCH https://github.com/CESNET/libyang.git
mkdir libyang/build && cd libyang/build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. && make -j2 && sudo make install
cd ../..
4 changes: 2 additions & 2 deletions .travis-deps-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ set -e
#install dependencies using homebrew
brew update
brew upgrade openssl
brew upgrade pcre

# libssh
wget https://git.libssh.org/projects/libssh.git/snapshot/libssh-0.7.5.tar.gz
Expand All @@ -19,7 +18,8 @@ mkdir cmocka/build && cd cmocka/build
cmake .. && make -j2 && sudo make install
cd ../..

git clone -b $TRAVIS_BRANCH https://github.com/CESNET/libyang.git
if [[ "$TRAVIS_BRANCH" = "master" ]]; then LY_BRANCH="master"; else LY_BRANCH="devel"; fi
git clone -b $LY_BRANCH https://github.com/CESNET/libyang.git
mkdir libyang/build && cd libyang/build
cmake .. && make -j2 && sudo make install
cd ../..
19 changes: 14 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ matrix:
dist: trusty
sudo: required
compiler: gcc
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
- os: osx
compiler: gcc
allow_failures:
Expand All @@ -21,17 +29,18 @@ branches:
- devel

before_install:
- eval "${MATRIX_EVAL}"
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then bash .travis-deps-linux.sh; fi
- if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then bash .travis-deps-osx.sh; fi

script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then export OPENSSLFLAGS="-DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include"; fi
- cd $TRAVIS_BUILD_DIR && mkdir build_none && cd build_none ; cmake -DENABLE_TLS=OFF -DENABLE_SSH=OFF -DENABLE_DNSSEC=OFF .. && make -j2 && ctest -V
- cd $TRAVIS_BUILD_DIR && mkdir build_tls && cd build_tls ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=OFF -DENABLE_DNSSEC=OFF .. && make -j2 && ctest -V
- cd $TRAVIS_BUILD_DIR && mkdir build_ssh && cd build_ssh ; cmake $OPENSSLFLAGS -DENABLE_TLS=OFF -DENABLE_SSH=ON -DENABLE_DNSSEC=OFF .. && make -j2 && ctest -V
- cd $TRAVIS_BUILD_DIR && mkdir build_ssh_tls && cd build_ssh_tls ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=ON -DENABLE_DNSSEC=OFF .. && make -j2 && ctest -V
- cd $TRAVIS_BUILD_DIR && mkdir build_all && cd build_all ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=ON -DENABLE_DNSSEC=ON .. && make -j2 && ctest -V
- cd $TRAVIS_BUILD_DIR && mkdir build_none && cd build_none ; cmake -DENABLE_TLS=OFF -DENABLE_SSH=OFF -DENABLE_DNSSEC=OFF .. && make -j2 && ctest --output-on-failure
- cd $TRAVIS_BUILD_DIR && mkdir build_tls && cd build_tls ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=OFF -DENABLE_DNSSEC=OFF .. && make -j2 && ctest --output-on-failure
- cd $TRAVIS_BUILD_DIR && mkdir build_ssh && cd build_ssh ; cmake $OPENSSLFLAGS -DENABLE_TLS=OFF -DENABLE_SSH=ON -DENABLE_DNSSEC=OFF .. && make -j2 && ctest --output-on-failure
- cd $TRAVIS_BUILD_DIR && mkdir build_ssh_tls && cd build_ssh_tls ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=ON -DENABLE_DNSSEC=OFF .. && make -j2 && ctest --output-on-failure
- cd $TRAVIS_BUILD_DIR && mkdir build_all && cd build_all ; cmake $OPENSSLFLAGS -DENABLE_TLS=ON -DENABLE_SSH=ON -DENABLE_DNSSEC=ON .. && make -j2 && ctest --output-on-failure
- cd -

after_success:
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ if(NOT UNIX)
message(FATAL_ERROR "Only *nix like systems are supported.")
endif()

# osx specific
set(CMAKE_MACOSX_RPATH TRUE)

set(INCLUDE_INSTALL_SUBDIR ${CMAKE_INSTALL_INCLUDEDIR}/libnetconf2)
set(DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/libnetconf2)

Expand All @@ -28,8 +31,8 @@ set(CMAKE_C_FLAGS_DEBUG "-g -O0")

# set version
set(LIBNETCONF2_MAJOR_VERSION 0)
set(LIBNETCONF2_MINOR_VERSION 10)
set(LIBNETCONF2_MICRO_VERSION 30)
set(LIBNETCONF2_MINOR_VERSION 11)
set(LIBNETCONF2_MICRO_VERSION 37)
set(LIBNETCONF2_VERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION}.${LIBNETCONF2_MICRO_VERSION})
set(LIBNETCONF2_SOVERSION ${LIBNETCONF2_MAJOR_VERSION}.${LIBNETCONF2_MINOR_VERSION})

Expand All @@ -41,6 +44,7 @@ option(ENABLE_PYTHON "Include bindings for Python 3" OFF)
set(READ_INACTIVE_TIMEOUT 20 CACHE STRING "Maximum number of seconds waiting for new data once some data have arrived")
set(READ_ACTIVE_TIMEOUT 300 CACHE STRING "Maximum number of seconds for receiving a full message")
set(MAX_PSPOLL_THREAD_COUNT 6 CACHE STRING "Maximum number of threads that could simultaneously access a ps_poll structure")
set(SCHEMAS_DIR "${CMAKE_INSTALL_PREFIX}/${DATA_INSTALL_DIR}" CACHE STRING "Directory with internal lnc2 schemas")

if(ENABLE_DNSSEC AND NOT ENABLE_SSH)
message(WARNING "DNSSEC SSHFP retrieval cannot be used without SSH support.")
Expand Down
1 change: 1 addition & 0 deletions libnetconf2.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Libs: -L${libdir} -lnetconf2
Cflags: -I${includedir}

LNC2_MAX_THREAD_COUNT=@MAX_PSPOLL_THREAD_COUNT@
LNC2_SCHEMAS_DIR=@SCHEMAS_DIR@
12 changes: 12 additions & 0 deletions packages/debian.control.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ Depends: @PACKAGE_NAME@ (= @LIBNETCONF2_VERSION@)
Section: debug
Architecture: any
Description: Debug symbols for libnetconf2 library.

Package: python3-netconf2@COMPAT_PACKAGES@
Depends: @PACKAGE_NAME@ (= @LIBNETCONF2_VERSION@)
Section: libs
Architecture: any
Description: Bindings of libyang library to python3 language.

Package: python3-netconf2@COMPAT_PACKAGES@-dbg
Depends: python3-netconf2@COMPAT_PACKAGES@ (= @LIBNETCONF2_VERSION@)
Section: debug
Architecture: any
Description: Debug symbols of python3 bidings of libnetconf2 library.
1 change: 1 addition & 0 deletions packages/debian.python3-netconf2-experimental.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib*/python*/*-packages/*
5 changes: 3 additions & 2 deletions packages/debian.rules.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export DH_VERBOSE=1
dh $@

override_dh_strip:
dh_strip --dbg-package=@PACKAGE_NAME@-dbg
dh_strip -p@PACKAGE_NAME@ --dbg-package=@PACKAGE_NAME@-dbg
dh_strip -ppython3-netconf2@COMPAT_PACKAGES@ --dbg-package=python3-netconf2@COMPAT_PACKAGES@-dbg

override_dh_auto_configure:
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -D CMAKE_BUILD_TYPE:String="@BUILD_TYPE@" .
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DENABLE_PYTHON=ON -DCMAKE_BUILD_TYPE:String="@BUILD_TYPE@" .

override_dh_auto_test:
ctest --output-on-failure
4 changes: 2 additions & 2 deletions packages/libnetconf2.dsc.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Format: 3.0 (quilt)
Source: @PACKAGE_NAME@
Binary: @PACKAGE_NAME@, @PACKAGE_NAME@-dbg, @PACKAGE_NAME@-dev
Binary: @PACKAGE_NAME@, @PACKAGE_NAME@-dbg, @PACKAGE_NAME@-dev, python3-netconf2@COMPAT_PACKAGES@, python3-netconf2@COMPAT_PACKAGES@-dbg
Maintainer: CESNET <[email protected]>
Version: @LIBNETCONF2_VERSION@
Architecture: any
Standards-Version: 3.8.2
Homepage: https://github.com/CESNET/libnetconf2
Vcs-Git: https://github.com/CESNET/libnetconf2
Build-Depends: debhelper (>= 9), make, gcc, cmake, pkg-config, libcmocka-dev, libyang@COMPAT_PACKAGES@-dev, libssh-dev (>= 0.7.1), openssl
Build-Depends: debhelper (>= 9), make, gcc, cmake, pkg-config, libcmocka-dev, libyang@COMPAT_PACKAGES@-dev, libssh-dev (>= 0.7.1), openssl, python3-dev (>= 3.4)
37 changes: 22 additions & 15 deletions packages/libnetconf2.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Source: %{url}/archive/@[email protected]
License: BSD-3-Clause
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}

Requires: libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@ = %{version}-%{release}
Requires: libyang@COMPAT_PACKAGES@
BuildRequires: libyang@COMPAT_PACKAGES@-devel
BuildRequires: libssh-devel >= 0.7.1
BuildRequires: openssl-devel
Expand All @@ -18,32 +18,37 @@ BuildRequires: gcc
%if 0%{?suse_version}
BuildRequires: timezone
%endif
Conflicts: @CONFLICT_PACKAGE_NAME@

%package -n libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@
Summary: Libnetconf2 library
Requires: libyang@COMPAT_PACKAGES@
Requires: %{name} = %{version}-%{release}
%if 0%{?suse_version} + 0%{?fedora} > 0
BuildRequires: python3-devel
%else
BuildRequires: python34-devel
%endif
Conflicts: @CONFLICT_PACKAGE_NAME@

%package devel
Summary: Headers of libnetconf2 library
Requires: %{name} = %{version}-%{release}
Requires: libssh-devel

%description -n libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@
Libnetconf2 is a NETCONF library in C intended for building NETCONF clients and servers.
%package -n python3-netconf2@COMPAT_PACKAGES@
Summary: Bindings to python3
Requires: %{name} = %{version}-%{release}

%description devel
Headers of libnetconf2 library.

%description -n python3-netconf2@COMPAT_PACKAGES@
Bindings of libnetconf2 library to python3 language.

%description
Libnetconf2 is a NETCONF library in C intended for building NETCONF clients and servers.

%prep
%setup -n libnetconf2-@BRANCH@

%build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -D CMAKE_BUILD_TYPE:String="@BUILD_TYPE@" -D ENABLE_VALGRIND_TESTS:BOOL=FALSE .
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_BUILD_TYPE:String="@BUILD_TYPE@" -DENABLE_PYTHON=ON -DENABLE_VALGRIND_TESTS:BOOL=FALSE .
make

%check
Expand All @@ -52,17 +57,15 @@ ctest --output-on-failure
%install
make DESTDIR=%{buildroot} install

%post -n libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@ -p /sbin/ldconfig
%post -p /sbin/ldconfig

%postun -n libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@ -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%files
%{_datadir}/libnetconf2/*
%dir %{_datadir}/libnetconf2/

%files -n libnetconf2-@LIBNETCONF2_MAJOR_VERSION@_@LIBNETCONF2_MINOR_VERSION@
%defattr(-,root,root)
%{_libdir}/libnetconf2.so.*
%{_datadir}/libnetconf2/*
%dir %{_datadir}/libnetconf2/

%files devel
%defattr(-,root,root)
Expand All @@ -73,4 +76,8 @@ make DESTDIR=%{buildroot} install
%{_includedir}/nc_server.h
%dir %{_includedir}/libnetconf2/

%files -n python3-netconf2@COMPAT_PACKAGES@
%defattr(-,root,root)
/usr/lib*/python*/*-packages/*

%changelog
5 changes: 3 additions & 2 deletions packages/local-deb.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ cp build-packages/debian.control debian/control
echo '9' >debian/compat
echo '3.0 (quilt)' >debian/source/format
cp "@PROJECT_SOURCE_DIR@/LICENSE" debian/copyright
cp "@PROJECT_SOURCE_DIR@/packages/debian.libnetconf2.install" debian/@[email protected]
cp "@PROJECT_SOURCE_DIR@/packages/debian.libnetconf2-dev.install" debian/@[email protected]
cp "@PROJECT_SOURCE_DIR@/packages/debian.libnetconf2-experimental.install" debian/@[email protected]
cp "@PROJECT_SOURCE_DIR@/packages/debian.libnetconf2-experimental-dev.install" debian/@[email protected]
cp "@PROJECT_SOURCE_DIR@/packages/debian.python3-netconf2-experimental.install" debian/python3-netconf2@[email protected]
echo -e "@PACKAGE_NAME@ (@LIBNETCONF2_VERSION@) stable; urgency=low\n" >debian/changelog
git log -10 --pretty=format:' * %s (%aN)%n' 2>/dev/null >>debian/changelog || echo -e " * unknown changes \n" >>debian/changelog
git log -1 --pretty=format:'%n -- %aN <%aE> %aD%n' >>debian/changelog 2>/dev/null || echo " -- ${USER} <${USER}@`hostname`> `date -R`" >>debian/changelog
Expand Down
4 changes: 3 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ if (PYTHON)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/docs/Makefile.in ${CMAKE_CURRENT_SOURCE_DIR}/docs/Makefile)
add_custom_target(pyapi ALL COMMAND ${PYTHON} ${SETUP_PY} build -b ${PYAPI_BUILD_DIR} ${DEBUG})
add_custom_target(pyapidoc COMMAND make -f ${CMAKE_CURRENT_SOURCE_DIR}/docs/Makefile html)
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build -b ${PYAPI_BUILD_DIR} install --prefix=${CMAKE_INSTALL_PREFIX})")
execute_process(COMMAND ${PYTHON} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific=True))"
OUTPUT_VARIABLE PYTHON_MODULE_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
install(CODE "execute_process(COMMAND ${PYTHON} ${SETUP_PY} build -b ${PYAPI_BUILD_DIR} install --install-lib=\$ENV{DESTDIR}/${PYTHON_MODULE_PATH})")
endif()
28 changes: 24 additions & 4 deletions python/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,30 @@ ncErrFree(ncErrObject *self)
Py_TYPE(self)->tp_free((PyObject*)self);
}

static char *
escape_quotes(char *strbuf, size_t strbuf_size, const char *text)
{
size_t i, o;
for (i = o = 0; i < strbuf_size; i++) {
if (text[i] == '"') {
strbuf[o++] = '\\';
}
strbuf[o++] = text[i];
if (!text[i]) {
/* end of the text */
break;
}
}
return strbuf;
}

static PyObject *
ncErrStr(ncErrObject *self)
{
uint16_t u, f = 0;
char *str = NULL;
#define BUFSIZE 4096
char buf[BUFSIZE];

if (self->err->type) {
asprintf(&str, "\"type\":\"%s\"", self->err->type);
Expand All @@ -46,13 +65,13 @@ ncErrStr(ncErrObject *self)
asprintf(&str, "%s%s\"severity\":\"%s\"", str ? str : "", str ? "," : "", self->err->severity);
}
if (self->err->apptag) {
asprintf(&str, "%s%s\"app-tag\":\"%s\"", str ? str : "", str ? "," : "", self->err->apptag);
asprintf(&str, "%s%s\"app-tag\":\"%s\"", str ? str : "", str ? "," : "", escape_quotes(buf, BUFSIZE, self->err->apptag));
}
if (self->err->path) {
asprintf(&str, "%s%s\"path\":\"%s\"", str ? str : "", str ? "," : "", self->err->path);
asprintf(&str, "%s%s\"path\":\"%s\"", str ? str : "", str ? "," : "", escape_quotes(buf, BUFSIZE, self->err->path));
}
if (self->err->message) {
asprintf(&str, "%s%s\"message\":\"%s", str ? str : "", str ? "," : "", self->err->message);
asprintf(&str, "%s%s\"message\":\"%s", str ? str : "", str ? "," : "", escape_quotes(buf, BUFSIZE, self->err->message));
if (self->err->message_lang) {
asprintf(&str, "%s (%s)\"", str, self->err->message_lang);
} else {
Expand Down Expand Up @@ -92,7 +111,8 @@ ncErrStr(ncErrObject *self)
}
if (self->err->other_count) {
for (u = 0; u < self->err->other_count; u++) {
asprintf(&str, "%s%s\"%s\":\"%s\"", str, f ? "," : "", self->err->other[u]->name, self->err->other[u]->content);
asprintf(&str, "%s%s\"%s\":\"%s\"", str, f ? "," : "", self->err->other[u]->name,
escape_quotes(buf, BUFSIZE, self->err->other[u]->content));
}
f = 1;
}
Expand Down
65 changes: 65 additions & 0 deletions python/examples/editconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/python3

import sys
import os
import getpass
import json
import yang
import netconf2 as nc

def interactive_auth(name, instruct, prompt, data):
print(name)
return getpass.getpass(prompt)

def password_auth(user, host, data):
return getpass.getpass((user if user else os.getlogin()) + '@' + host + ' password : ')

def hostkey_check(hostname, state, keytype, hexa, priv):
return True

#
# get know where to connect
#
host = input("hostname: ")
try:
port = int(input("port : "))
except:
port = 0;
user = input("username: ")

#
# set SSH settings
#
if user:
ssh = nc.SSH(username=user)
else:
ssh = nc.SSH()
ssh.setAuthInteractiveClb(interactive_auth)
ssh.setAuthPasswordClb(password_auth)
ssh.setAuthHostkeyCheckClb(hostkey_check)

#
# create NETCONF session to the server
#
try:
session = nc.Session(host, port, ssh)
except Exception as e:
print(e)
sys.exit(1)

# prepare config content as string or data tree
tm = session.context.get_module("turing-machine")
# config = "<turing-machine xmlns=\"http://example.net/turing-machine\"><transition-function><delta><label>left summand</label><input><state>0</state></input></delta></transition-function></turing-machine>"
config = yang.Data_Node(session.context, "/turing-machine:turing-machine/transition-function/delta[label='left summand']/input/state", "5", 0, 0)

# perform <edit-config> and print result
try:
session.rpcEditConfig(nc.DATASTORE_RUNNING, config)
except nc.ReplyError as e:
reply = {'success':False, 'error': []}
for err in e.args[0]:
reply['error'].append(json.loads(str(err)))
print(json.dumps(reply))
sys.exit(1)

# print(data.print_mem(ly.LYD_XML, ly.LYP_FORMAT | ly.LYP_WITHSIBLINGS))
Loading

0 comments on commit db2933f

Please sign in to comment.