confd: generate test-config.cfg

Currently, it's not possible to run infix tests from an external
project (based on infix) due to an incompatibility between the
configuration used in the tests (the default configuration
within the image generated by the external project) and the infix
base configuration expected by the test cases. Therefore, a simple
configuration specifically for testing purposes needs to be generated
within an image. This test-config should always be generated
but only loaded when the device is in test mode.

Part of issue #568
This commit is contained in:
Ahmed Karic
2024-08-23 11:15:12 +02:00
committed by Mattias Walström
parent 3fb49cf9dd
commit 4a325af4e4
12 changed files with 66 additions and 7 deletions
+1
View File
@@ -1,3 +1,4 @@
d /run/confd/factory.d - - -
d /run/confd/failure.d - - -
d /run/confd/test.d - - -
d /run/resolvconf/interfaces - - -
+5
View File
@@ -12,15 +12,19 @@ RUN_PATH_=/tmp/confd/run
FACTORY_DEFAULTS_D=../share/factory.d
FAILURE_DEFAULTS_D=../share/failure.d
TEST_DEFAULTS_D=../share/test.d
FACTORY_D=$RUN_PATH_/factory.d
FAILURE_D=$RUN_PATH_/failure.d
TEST_D=$RUN_PATH_/test.d
FACTORY_GEN=$RUN_PATH_/factory-config.gen
FAILURE_GEN=$RUN_PATH_/failure-config.gen
TEST_GEN=$RUN_PATH_/test-config.gen
FACTORY_CFG=$RUN_PATH_/factory-config.cfg
FAILURE_CFG=$RUN_PATH_/failure-config.cfg
TEST_CFG=$RUN_PATH_/test-config.cfg
STARTUP_CFG=$CFG_PATH_/startup-config.cfg
# Uncomment this line in to create a bridge (br0) with all (classified
@@ -32,6 +36,7 @@ STARTUP_CFG=$CFG_PATH_/startup-config.cfg
# Default hostname in Fail Secure mode, plus last three octets in the base
# MAC address, e.g. "failed-c0-ff-ee".
FAIL_HOSTNAME="failed"
TEST_HOSTNAME="test"
# Only needed for testing
mkdir -p "$CFG_PATH_" "$RUN_PATH_" "$FACTORY_D" "$FAILURE_D"
+21 -5
View File
@@ -1,11 +1,11 @@
#!/bin/sh
# Bootstrap system factory-config, failure-config and sysrepo db.
# Bootstrap system factory-config, failure-config, test-config and sysrepo db.
#
########################################################################
# The system factory-config and failure-config are derived from default
# settings snippets, from /usr/share/confd/factory.d, and some generated
# snippets, e.g., hostname (based on base MAC address) and number of
# interfaces.
# The system factory-config, failure-config and test-config are derived
# from default settings snippets, from /usr/share/confd/factory.d, and
# some generated snippets, e.g., hostname (based on base MAC address)
# and number of interfaces.
#
# The resulting factory-config is used to create the syrepo db (below)
# {factory} datastore. Hence, the factory-config file must match the
@@ -127,11 +127,27 @@ failure()
collate "$FAILURE_GEN" "$FAILURE_CFG" "$FAILURE_D"
}
gen_test_cfg()
{
# Fetch defaults, simplifies sort in collate()
cp "$TEST_DEFAULTS_D"/* "$TEST_D"
gen-hostname "$TEST_HOSTNAME" >"$TEST_D/20-hostname.json"
gen-interfaces >"$TEST_D/20-interfaces.json"
gen-version >"$TEST_D/20-version.json"
collate "$TEST_GEN" "$TEST_CFG" "$TEST_D"
}
# Both factory-config and failure-config are generated every boot
# regardless if there is a static /etc/factory-config.cfg or not.
factory "$FACTORY_GEN"
failure "$FAILURE_GEN"
if [ -f "/mnt/aux/test-mode" ]; then
gen_test_cfg
fi
if [ -n "$TESTING" ]; then
echo "Done."
exit 0
+5
View File
@@ -12,19 +12,23 @@ RUN_PATH_=/run/confd
# Static defaults, base Infix and any br2-external derivative.
FACTORY_DEFAULTS_D=/usr/share/confd/factory.d
FAILURE_DEFAULTS_D=/usr/share/confd/failure.d
TEST_DEFAULTS_D=/usr/share/confd/test.d
# Generated config snippets, e.g., hostname, password, and interfaces.
FACTORY_D=$RUN_PATH_/factory.d
FAILURE_D=$RUN_PATH_/failure.d
TEST_D=$RUN_PATH_/test.d
# The default config snippets and generated snippets are collated into
# RAM-only name-config.gen , which are candidates for name-config.cfg
FACTORY_GEN=$RUN_PATH_/factory-config.gen
FAILURE_GEN=$RUN_PATH_/failure-config.gen
TEST_GEN=$RUN_PATH_/test-config.gen
# The resulting .cfg files can be peristent (factory-config) or not.
FACTORY_CFG=$SYS_PATH_/factory-config.cfg
FAILURE_CFG=$SYS_PATH_/failure-config.cfg
TEST_CFG=$SYS_PATH_/test-config.cfg
STARTUP_CFG=$CFG_PATH_/startup-config.cfg
# Uncomment this line in to create a bridge (br0) with all (classified
@@ -36,6 +40,7 @@ STARTUP_CFG=$CFG_PATH_/startup-config.cfg
# Default hostname in Fail Secure mode, plus last three octets in the base
# MAC address, e.g. "failed-c0-ff-ee".
FAIL_HOSTNAME="failed"
TEST_HOSTNAME="test"
# Optional overrides by br2-external
if [ -f /etc/confdrc.local ]; then
+1
View File
@@ -11,6 +11,7 @@ AC_CONFIG_FILES([
share/Makefile
share/factory.d/Makefile
share/failure.d/Makefile
share/test.d/Makefile
share/migrate/Makefile
share/migrate/1.0/Makefile
src/Makefile
+1 -1
View File
@@ -1,2 +1,2 @@
SUBDIRS = factory.d failure.d migrate
SUBDIRS = factory.d failure.d test.d migrate
dist_pkgdata_DATA = README
+1 -1
View File
@@ -1 +1 @@
Templates for generating device-specific factory-config and failure-config.
Templates for generating device-specific factory-config, failure-config and test-config.
@@ -0,0 +1,11 @@
{
"infix-services:mdns": {
"enabled": true
},
"infix-services:web": {
"enabled": true,
"restconf": {
"enabled": true
}
}
}
+1
View File
@@ -0,0 +1 @@
../factory.d/10-nacm.json
+1
View File
@@ -0,0 +1 @@
../factory.d/10-netconf-server.json
+14
View File
@@ -0,0 +1,14 @@
{
"ietf-system:system": {
"hostname": "test",
"authentication": {
"user": [
{
"name": "admin",
"password": "$factory$",
"infix-system:shell": "bash"
}
]
}
}
}
+4
View File
@@ -0,0 +1,4 @@
testdir = $(pkgdatadir)/test.d
dist_test_DATA = 10-nacm.json \
10-netconf-server.json 10-system.json