From ba2ad348ffd8c0df29b8343a31b4baff31b4c9fc Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 18 Aug 2020 16:10:48 -0600 Subject: [PATCH 1/3] executor scripts: add vrf executor --- Makefile | 3 ++- executor-scripts/linux/vrf | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 executor-scripts/linux/vrf diff --git a/Makefile b/Makefile index ef9acff..3874745 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,8 @@ EXECUTOR_SCRIPTS_CORE ?= \ link \ EXECUTOR_SCRIPTS_OPT ?= \ - bridge + bridge \ + vrf EXECUTOR_SCRIPTS ?= ${EXECUTOR_SCRIPTS_CORE} ${EXECUTOR_SCRIPTS_OPT} diff --git a/executor-scripts/linux/vrf b/executor-scripts/linux/vrf new file mode 100755 index 0000000..2696d0f --- /dev/null +++ b/executor-scripts/linux/vrf @@ -0,0 +1,25 @@ +#!/bin/sh +handle_init() { + ${MOCK} /sbin/ip link $1 $IFACE type vrf table $IF_VRF_TABLE + ${MOCK} /sbin/ip rule $1 iif $IFACE table $IF_VRF_TABLE + ${MOCK} /sbin/ip rule $1 oif $IFACE table $IF_VRF_TABLE +} + +handle_member() { + ${MOCK} /sbin/ip link set $IFACE master $IF_VRF_MEMBER +} + +[ -n "$VERBOSE" ] && set -x + +case "$PHASE" in +pre-up) + [ -n "$IF_VRF_TABLE" ] && handle_init "add" + [ -n "$IF_VRF_MEMBER" ] && handle_member + ;; +post-down) + [ -n "$IF_VRF_TABLE" ] && handle_init "del" + ;; +*) + exit 0 + ;; +esac From ba98705c8ff13842cbd8c8d0ce5f29a265e65c60 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 18 Aug 2020 16:28:34 -0600 Subject: [PATCH 2/3] tests: add tests for VRF executor --- executor-scripts/linux/vrf | 4 ++++ tests/linux/Kyuafile | 1 + tests/linux/vrf_test | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100755 tests/linux/vrf_test diff --git a/executor-scripts/linux/vrf b/executor-scripts/linux/vrf index 2696d0f..3f3d552 100755 --- a/executor-scripts/linux/vrf +++ b/executor-scripts/linux/vrf @@ -1,4 +1,6 @@ #!/bin/sh +set -e + handle_init() { ${MOCK} /sbin/ip link $1 $IFACE type vrf table $IF_VRF_TABLE ${MOCK} /sbin/ip rule $1 iif $IFACE table $IF_VRF_TABLE @@ -15,9 +17,11 @@ case "$PHASE" in pre-up) [ -n "$IF_VRF_TABLE" ] && handle_init "add" [ -n "$IF_VRF_MEMBER" ] && handle_member + exit 0 ;; post-down) [ -n "$IF_VRF_TABLE" ] && handle_init "del" + exit 0 ;; *) exit 0 diff --git a/tests/linux/Kyuafile b/tests/linux/Kyuafile index 49b3201..22bb701 100644 --- a/tests/linux/Kyuafile +++ b/tests/linux/Kyuafile @@ -6,3 +6,4 @@ atf_test_program{name='link_test'} atf_test_program{name='ipv6-ra_test'} atf_test_program{name='dhcp_test'} atf_test_program{name='static_test'} +atf_test_program{name='vrf_test'} diff --git a/tests/linux/vrf_test b/tests/linux/vrf_test new file mode 100755 index 0000000..942a539 --- /dev/null +++ b/tests/linux/vrf_test @@ -0,0 +1,34 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/../test_env.sh +EXECUTOR="$(atf_get_srcdir)/../../executor-scripts/linux/vrf" + +tests_init \ + leader_bringup \ + leader_teardown \ + member_bringup + +leader_bringup_body() { + export MOCK=echo IFACE=vrf-red PHASE=pre-up IF_VRF_TABLE=1 IF_VRF_MEMBER= + atf_check -s exit:0 \ + -o match:'ip link add vrf-red type vrf table 1' \ + -o match:'ip rule add iif vrf-red table 1' \ + -o match:'ip rule add oif vrf-red table 1' \ + ${EXECUTOR} +} + +leader_teardown_body() { + export MOCK=echo IFACE=vrf-red PHASE=post-down IF_VRF_TABLE=1 IF_VRF_MEMBER= + atf_check -s exit:0 \ + -o match:'ip link del vrf-red type vrf table 1' \ + -o match:'ip rule del iif vrf-red table 1' \ + -o match:'ip rule del oif vrf-red table 1' \ + ${EXECUTOR} +} + +member_bringup_body() { + export MOCK=echo IFACE=eth0 PHASE=pre-up IF_VRF_MEMBER=vrf-red IF_VRF_TABLE= + atf_check -s exit:0 \ + -o match:'ip link set eth0 master vrf-red' \ + ${EXECUTOR} +} From 2c37b22d7005e8f18e6f58c9569326644dbe764e Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Tue, 18 Aug 2020 16:52:11 -0600 Subject: [PATCH 3/3] tests: add fixture & test for VRF topology learning --- executor-scripts/linux/vrf | 3 +++ tests/fixtures/vrf.interfaces | 7 +++++++ tests/ifquery_test | 8 +++++++- tests/test_env.sh | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/vrf.interfaces diff --git a/executor-scripts/linux/vrf b/executor-scripts/linux/vrf index 3f3d552..c42b000 100755 --- a/executor-scripts/linux/vrf +++ b/executor-scripts/linux/vrf @@ -23,6 +23,9 @@ post-down) [ -n "$IF_VRF_TABLE" ] && handle_init "del" exit 0 ;; +depend) + echo "$IF_VRF_MEMBER" + ;; *) exit 0 ;; diff --git a/tests/fixtures/vrf.interfaces b/tests/fixtures/vrf.interfaces new file mode 100644 index 0000000..bfcf11b --- /dev/null +++ b/tests/fixtures/vrf.interfaces @@ -0,0 +1,7 @@ +iface vrf-red + vrf-table 1 + +auto eth0 +iface eth0 + use dhcp + vrf-member vrf-red diff --git a/tests/ifquery_test b/tests/ifquery_test index 64e8718..0b557d7 100755 --- a/tests/ifquery_test +++ b/tests/ifquery_test @@ -18,7 +18,8 @@ tests_init \ learned_executor \ inheritance_0 \ inheritance_1 \ - implicit_vlan + implicit_vlan \ + vrf_dependency noargs_body() { atf_check -s exit:1 -e ignore ifquery -S/dev/null @@ -112,3 +113,8 @@ implicit_vlan_body() { -o match:"use vlan" \ ifquery -E $EXECUTORS -i $FIXTURES/vlan.interfaces eth0.8 } + +vrf_dependency_body() { + atf_check -s exit:0 -o match:"requires vrf-red" \ + ifquery -E $EXECUTORS_LINUX -i $FIXTURES/vrf.interfaces eth0 +} diff --git a/tests/test_env.sh b/tests/test_env.sh index ff44cfa..870dc86 100644 --- a/tests/test_env.sh +++ b/tests/test_env.sh @@ -1,6 +1,7 @@ PATH="$(atf_get_srcdir)/..:$(atf_get_srcdir)/../..:$PATH" FIXTURES="$(atf_get_srcdir)/fixtures" EXECUTORS="$(atf_get_srcdir)/executors" +EXECUTORS_LINUX="$(atf_get_srcdir)/../executor-scripts/linux" tests_init() { TESTS="$@"