mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-03 22:33:02 +02:00
Add implementation to control test mode functions using an action
This intoduce a new sysrepo plugin to handle a new YANG model 'infix-test'. Today only contains the actions. This is required to run tests on infix using infamy. This is a part of #561 Signed-off-by: Mattias Walström <lazzer@gmail.com>
This commit is contained in:
@@ -159,6 +159,7 @@ BR2_PACKAGE_TETRIS=y
|
||||
BR2_PACKAGE_ROUSETTE=y
|
||||
BR2_PACKAGE_LIBINPUT=y
|
||||
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
|
||||
BR2_PACKAGE_TEST_MODE=y
|
||||
DISK_IMAGE_BOOT_BIN=y
|
||||
TRUSTED_KEYS=y
|
||||
TRUSTED_KEYS_DEVELOPMENT=y
|
||||
|
||||
@@ -201,6 +201,7 @@ BR2_PACKAGE_PODMAN_DRIVER_VFS=y
|
||||
BR2_PACKAGE_TETRIS=y
|
||||
BR2_PACKAGE_ROUSETTE=y
|
||||
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
|
||||
# BR2_PACKAGE_TEST_MODE is not set
|
||||
TRUSTED_KEYS=y
|
||||
TRUSTED_KEYS_DEVELOPMENT=y
|
||||
# GNS3_APPLIANCE is not set
|
||||
|
||||
@@ -192,6 +192,7 @@ BR2_PACKAGE_PODMAN_DRIVER_VFS=y
|
||||
BR2_PACKAGE_TETRIS=y
|
||||
BR2_PACKAGE_ROUSETTE=y
|
||||
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
|
||||
# BR2_PACKAGE_TEST_MODE is not set
|
||||
TRUSTED_KEYS=y
|
||||
TRUSTED_KEYS_DEVELOPMENT=y
|
||||
# GNS3_APPLIANCE is not set
|
||||
|
||||
@@ -161,6 +161,7 @@ BR2_PACKAGE_PODMAN_DRIVER_VFS=y
|
||||
BR2_PACKAGE_TETRIS=y
|
||||
BR2_PACKAGE_ROUSETTE=y
|
||||
BR2_PACKAGE_HOST_PYTHON_YANGDOC=y
|
||||
BR2_PACKAGE_TEST_MODE=y
|
||||
TRUSTED_KEYS=y
|
||||
TRUSTED_KEYS_DEVELOPMENT=y
|
||||
GNS3_APPLIANCE_RAM=512
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
menu "Packages"
|
||||
source "$BR2_EXTERNAL_INFIX_PATH/package/confd/Config.in"
|
||||
source "$BR2_EXTERNAL_INFIX_PATH/package/test-mode/Config.in"
|
||||
source "$BR2_EXTERNAL_INFIX_PATH/package/curios-httpd/Config.in"
|
||||
source "$BR2_EXTERNAL_INFIX_PATH/package/execd/Config.in"
|
||||
source "$BR2_EXTERNAL_INFIX_PATH/package/gencert/Config.in"
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
config BR2_PACKAGE_TEST_MODE
|
||||
bool "test-mode"
|
||||
select BR2_PACKAGE_LIBITE
|
||||
select BR2_PACKAGE_LIBYANG
|
||||
select BR2_PACKAGE_SYSREPO
|
||||
select BR2_PACKAGE_LIBSRX
|
||||
select BR2_PACKAGE_CONFD
|
||||
help
|
||||
A plugin to sysrepo that provides functionality required to
|
||||
run tests with infamy.
|
||||
@@ -0,0 +1,32 @@
|
||||
TEST_MODE_VERSION = 1.0
|
||||
TEST_MODE_SITE_METHOD = local
|
||||
TEST_MODE_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/test-mode
|
||||
TEST_MODE_LICENSE = BSD-3-Clause
|
||||
TEST_MODE_LICENSE_FILES = LICENSE
|
||||
TEST_MODE_REDISTRIBUTE = NO
|
||||
TEST_MODE_DEPENDENCIES = sysrepo libite libyang confd
|
||||
TEST_MODE_AUTORECONF = YES
|
||||
TEST_MODE_SYSREPO_SHM_PREFIX = sr_buildroot$(subst /,_,$(CONFIG_DIR))_test_mode
|
||||
|
||||
COMMON_SYSREPO_ENV = \
|
||||
SYSREPO_SHM_PREFIX=$(CONFD_SYSREPO_SHM_PREFIX) \
|
||||
SYSREPOCTL_EXECUTABLE="$(HOST_DIR)/bin/sysrepoctl" \
|
||||
SYSREPOCFG_EXECUTABLE="$(HOST_DIR)/bin/sysrepocfg" \
|
||||
SEARCH_PATH="$(TARGET_DIR)/usr/share/yang/modules/confd/"
|
||||
|
||||
define TEST_MODE_INSTALL_YANG_MODULES
|
||||
$(COMMON_SYSREPO_ENV) \
|
||||
SEARCH_PATH="$(TARGET_DIR)/usr/share/yang/modules/test-mode/" $(BR2_EXTERNAL_INFIX_PATH)/utils/sysrepo-load-modules.sh $(@D)/yang/test-mode.inc
|
||||
endef
|
||||
define TEST_MODE_PERMISSIONS
|
||||
/etc/sysrepo/data/ r 660 root wheel - - - - -
|
||||
/etc/sysrepo/data d 770 root wheel - - - - -
|
||||
endef
|
||||
define TEST_MODE_CLEANUP
|
||||
rm -f /dev/shm/$(TEST_MODE_SYSREPO_SHM_PREFIX)*
|
||||
endef
|
||||
|
||||
TEST_MODE_PRE_INSTALL_TARGET_HOOKS += TEST_MODE_CLEANUP
|
||||
TEST_MODE_POST_INSTALL_TARGET_HOOKS += TEST_MODE_INSTALL_YANG_MODULES
|
||||
|
||||
$(eval $(autotools-package))
|
||||
@@ -142,13 +142,13 @@ gen_failure_cfg
|
||||
|
||||
if [ -f "/mnt/aux/test-mode" ]; then
|
||||
gen_test_cfg
|
||||
sysrepoctl -c infix-test -e test-mode-enable
|
||||
fi
|
||||
|
||||
if [ -n "$TESTING" ]; then
|
||||
echo "Done."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p /etc/sysrepo/
|
||||
if [ -f "$FACTORY_CFG" ]; then
|
||||
cp "$FACTORY_CFG" "$INIT_DATA"
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
Copyright (c) 2023 The KernelKit Authors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,4 @@
|
||||
SUBDIRS = src yang
|
||||
dist_doc_DATA = LICENSE
|
||||
DISTCLEANFILES = *~ *.d
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
autoreconf -W portability -vifm
|
||||
@@ -0,0 +1,71 @@
|
||||
AC_PREREQ(2.61)
|
||||
AC_INIT([test-mode], [1.0], [https://github.com/kernelkit/infix/issues])
|
||||
AM_INIT_AUTOMAKE(1.11 foreign subdir-objects)
|
||||
AM_SILENT_RULES(yes)
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
src/Makefile
|
||||
yang/Makefile
|
||||
])
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_INSTALL
|
||||
LT_INIT
|
||||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36])
|
||||
PKG_CHECK_MODULES([libite], [libite >= 2.5.0])
|
||||
|
||||
# Plugin installation path for sysrepo-plugind
|
||||
PKG_CHECK_VAR([srpdplugindir], [sysrepo], [SRPD_PLUGINS_PATH])
|
||||
AC_SUBST(srpdplugindir)
|
||||
|
||||
test "x$prefix" = xNONE && prefix=$ac_default_prefix
|
||||
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
|
||||
|
||||
YANGDIR=`eval echo $datarootdir/yang/modules/test-mode`
|
||||
AC_SUBST(YANGDIR)
|
||||
|
||||
LIBDIR=`eval echo $libdir`
|
||||
LIBDIR=`eval echo $LIBDIR`
|
||||
AC_SUBST(LIBDIR)
|
||||
|
||||
LOCALSTATEDIR=`eval echo $localstatedir`
|
||||
LOCALSTATEDIR=`eval echo $LOCALSTATEDIR`
|
||||
AC_SUBST(LOCALSTATEDIR)
|
||||
|
||||
RUNSTATEDIR=`eval echo $runstatedir`
|
||||
RUNSTATEDIR=`eval echo $RUNSTATEDIR`
|
||||
AC_SUBST(RUNSTATEDIR)
|
||||
|
||||
SYSCONFDIR=`eval echo $sysconfdir`
|
||||
SYSCONFDIR=`eval echo $SYSCONFDIR`
|
||||
AC_SUBST(SYSCONFDIR)
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
cat <<EOF
|
||||
|
||||
------------------ Summary ------------------
|
||||
$PACKAGE_NAME version $PACKAGE_VERSION
|
||||
Prefix................: $prefix
|
||||
Exec prefix...........: $eprefix
|
||||
Sysconfdir............: `eval echo $sysconfdir`
|
||||
Localstatedir.........: `eval echo $localstatedir`
|
||||
Default fstab.........: `eval echo $fstab`
|
||||
System environment....: ${sysconfig_path:-${sysconfig}}
|
||||
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
|
||||
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
|
||||
|
||||
------------- Compiler version --------------
|
||||
$($CC --version || true)
|
||||
-------------- Linker version ---------------
|
||||
$($LD --version || true)
|
||||
---------------------------------------------
|
||||
|
||||
Check the above options and compile with:
|
||||
${MAKE-make}
|
||||
|
||||
EOF
|
||||
@@ -0,0 +1,16 @@
|
||||
AM_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -D_GNU_SOURCE
|
||||
plugindir = $(srpdplugindir)
|
||||
plugin_LTLIBRARIES = test-mode-plugin.la
|
||||
|
||||
test_mode_plugin_la_LDFLAGS = -module -avoid-version -shared
|
||||
|
||||
test_mode_plugin_la_CFLAGS = \
|
||||
$(sysrepo_CFLAGS) \
|
||||
$(libite_CFLAGS) \
|
||||
$(CFLAGS)
|
||||
|
||||
test_mode_plugin_la_LIBADD = \
|
||||
$(sysrepo_LIBS) \
|
||||
$(libite_LIBS)
|
||||
|
||||
test_mode_plugin_la_SOURCES = test-mode.c
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* RPC control for test mode. This was first intended to be inside confd,
|
||||
* but it was tricky to apply new config in RPC (due to the behaviour of
|
||||
* sr_replace_config), it called all callbacks for the new config and got
|
||||
* stuck there until timeout. Maybe this change in the future, and this
|
||||
* can live in confd.
|
||||
*/
|
||||
|
||||
#include <libyang/tree_data.h>
|
||||
#include <sysrepo.h>
|
||||
#include <syslog.h>
|
||||
#include <libite/lite.h>
|
||||
#include <sysrepo_types.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <srx/common.h>
|
||||
#define SYSREPO_TIMEOUT 60000 /* 60s, this is the timeout we use in our frontends. */
|
||||
|
||||
sr_subscription_ctx_t *sub;
|
||||
sr_conn_ctx_t *conn;
|
||||
|
||||
#define TEST_CONFIG_PATH "/etc/test-config.cfg"
|
||||
|
||||
static int test_reset(sr_session_ctx_t *session, uint32_t sub_id, const char *path,
|
||||
const sr_val_t *input, const size_t input_cnt,
|
||||
sr_event_t event, unsigned request_id,
|
||||
sr_val_t **output, size_t *output_cnt,
|
||||
void *priv)
|
||||
{
|
||||
int rc = SR_ERR_OK;
|
||||
struct lyd_node *tree = NULL;
|
||||
const struct ly_ctx *ly_ctx;
|
||||
sr_conn_ctx_t *conn = sr_session_get_connection(session);
|
||||
|
||||
ly_ctx = sr_acquire_context(conn);
|
||||
rc = lyd_parse_data_path(ly_ctx, TEST_CONFIG_PATH, LYD_JSON, LYD_PARSE_STRICT, LYD_VALIDATE_NO_STATE, &tree);
|
||||
if (rc != LY_SUCCESS)
|
||||
{
|
||||
ERROR("Failed to parse new configuration data");
|
||||
return SR_ERR_INTERNAL;
|
||||
}
|
||||
rc = sr_session_switch_ds(session, SR_DS_RUNNING);
|
||||
if(rc)
|
||||
{
|
||||
ERROR("Failed to switch datastore");
|
||||
goto out;
|
||||
}
|
||||
rc = sr_replace_config(session, NULL, tree, SYSREPO_TIMEOUT);
|
||||
if (rc) {
|
||||
ERROR("Failed to replace configuration: %s", sr_strerror(rc));
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int test_override(sr_session_ctx_t *session, uint32_t sub_id, const char *path,
|
||||
const sr_val_t *input, const size_t input_cnt,
|
||||
sr_event_t event, unsigned request_id,
|
||||
sr_val_t **output, size_t *output_cnt,
|
||||
void *priv)
|
||||
{
|
||||
touch("/mnt/aux/test-override-startup");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
|
||||
{
|
||||
int rc = SR_ERR_SYS;
|
||||
|
||||
if (!fexist("/mnt/aux/test-mode"))
|
||||
return SR_ERR_OK;
|
||||
rc = sr_rpc_subscribe(session, "/infix-test:test/reset", test_reset, NULL, 0, SR_SUBSCR_DEFAULT, &sub);
|
||||
if (rc) {
|
||||
ERROR("Failed subscribe for test-reset");
|
||||
goto out;
|
||||
}
|
||||
rc = sr_rpc_subscribe(session, "/infix-test:test/override-startup", test_override, NULL, 0, SR_SUBSCR_DEFAULT, &sub);
|
||||
if (rc) {
|
||||
ERROR("Failed subscribe for test-override");
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *priv)
|
||||
{
|
||||
if (fexist("/mnt/aux/test-mode"))
|
||||
sr_unsubscribe(sub);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
yangdir = $(YANGDIR)
|
||||
yang_DATA = $(wildcard *.yang)
|
||||
@@ -0,0 +1,33 @@
|
||||
module infix-test {
|
||||
yang-version 1.1;
|
||||
namespace "urn:infix:test:ns:yang:1.0";
|
||||
prefix infix-test;
|
||||
|
||||
import ietf-netconf-acm {
|
||||
prefix nacm;
|
||||
}
|
||||
|
||||
organization "KernelKit";
|
||||
contact "kernelkit@googlegroups.com";
|
||||
description "Infix model for system testing.";
|
||||
|
||||
revision 2024-08-16 {
|
||||
description "Initial revision.";
|
||||
reference "internal";
|
||||
}
|
||||
feature test-mode-enable {
|
||||
description
|
||||
"Enable test mode for infix tests";
|
||||
}
|
||||
container test {
|
||||
if-feature "test-mode-enable";
|
||||
action reset {
|
||||
nacm:default-deny-all;
|
||||
description "Reset the running-config datastore to test configuration";
|
||||
}
|
||||
action override-startup {
|
||||
nacm:default-deny-all;
|
||||
description "Start from startup datastore once, instead of the default test configuration";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- sh -*-
|
||||
MODULES=(
|
||||
"infix-test@2024-08-16.yang"
|
||||
)
|
||||
Reference in New Issue
Block a user