Skip to content

Commit

Permalink
tests/gnrc_dhcpv6_client: honor configured IFACE in Kea config
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Sep 2, 2021
1 parent a7c19f2 commit 389138c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions tests/gnrc_dhcpv6_client/Makefile
Expand Up @@ -41,6 +41,7 @@ include $(RIOTBASE)/Makefile.include

.PHONY: dhcpv6_server

dhcpv6_server: IFACE := ${IFACE}
dhcpv6_server:
$(CURDIR)/dhcpv6_server.sh $(DHCPV6_SERVER_PORT) $(CURDIR)/kea-dhcp6.conf

Expand Down
4 changes: 3 additions & 1 deletion tests/gnrc_dhcpv6_client/README.md
Expand Up @@ -21,7 +21,9 @@ If you use any platform other than `native`, you need to use `ethos`, otherwise
`netdev_tap` is chosen.

An instance of Kea that configured via [kea-dhcp6.conf](kea-dhcp6.conf) is
started in parallel to `make term`/`make test-with-config`.
started in parallel to `make term`/`make test-with-config`. The
`{{ env.IFACE }}` template variable will be replaced by the `dhcpv6_server.sh`
script.

Read the [Kea documentation] on the configuration file for more information.

Expand Down
13 changes: 6 additions & 7 deletions tests/gnrc_dhcpv6_client/dhcpv6_server.sh
Expand Up @@ -25,26 +25,25 @@ _kea_version_lesser_1_7_10() {

_dhcpv6_server() {
TMPDIR="$(mktemp -u | xargs dirname)/${APPLICATION}_kea"
CONFIG="${TMPDIR}/kea-dhcp6.config"

# only used `mktemp` with dry-run above to get temp directory name, so we
# still need to create the directory
mkdir -p "${TMPDIR}"
if _kea_version_lesser_1_7_10; then
config=$2
else
sed "s/\"{{\s*env\.IFACE\s*}}\"/\"${IFACE}\"/" "$2" > "${CONFIG}"
if ! _kea_version_lesser_1_7_10; then
# Top-level "Logging" config is not supported by Kea >=1.7.10, so move
# that config to Dhcp6 map, see
# https://kea.readthedocs.io/en/kea-1.7.10/arm/config.html#json-syntax
config="${TMPDIR}/kea-dhcp6.config"
convert_json="$(cat <<EOF
import json
with open('$2') as c:
with open('$CONFIG') as c:
config = json.load(c)
logging = config.pop('Logging', None)
if logging is not None:
config['Dhcp6'].update(logging)
with open('$config', 'w') as c:
with open('$CONFIG', 'w') as c:
json.dump(config, c)
EOF
)"
Expand All @@ -53,7 +52,7 @@ EOF
sleep 1 # sleep to let TAP become active
cd "$TMPDIR" || exit 1
KEA_PIDFILE_DIR=. KEA_LOCKFILE_DIR=. \
kea-dhcp6 -p "$1" -c "$config" &
kea-dhcp6 -p "$1" -c "$CONFIG" &
}

# no need to kill from external, kea handles double instances gracefully
Expand Down
4 changes: 2 additions & 2 deletions tests/gnrc_dhcpv6_client/kea-dhcp6.conf
Expand Up @@ -2,7 +2,7 @@
"Dhcp6":
{
"interfaces-config": {
"interfaces": [ "tapbr0" ]
"interfaces": [ "{{ env.IFACE }}" ]
},
"data-directory": ".",
"lease-database": {
Expand All @@ -22,7 +22,7 @@
"renew-timer": 1000,
"rebind-timer": 2000,
"subnet6": [
{ "interface": "tapbr0",
{ "interface": "{{ env.IFACE }}",
"subnet": "2001:db8::/32",
"pools": [ { "pool": "2001:db8:1::/64" } ],
"pd-pools": [ { "prefix": "2001:db8:8000::",
Expand Down

0 comments on commit 389138c

Please sign in to comment.