From 0e5ec5b26073cb204c1f01899733bc219fa163c6 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 4 Sep 2020 23:21:21 +0200 Subject: [PATCH 1/9] link executor: Refactor VLAN iface management Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 9921840..9751987 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -43,19 +43,15 @@ pre-up) ip link add "${IFACE}" type dummy fi - ;; -up|down) - if is_vlan; then - ADD_DEL="add" - [ "$PHASE" = "down" ] && ADD_DEL="delete" - if [ "$PHASE" = "up" -a -e /sys/class/net/$IFACE ]; then + if is_vlan; then + if [ -d "/sys/class/net/${IFACE}" ]; then exit 0 fi - if [ -z "$MOCK" ]; then - if ! ip link show "$IF_VLAN_RAW_DEVICE" >/dev/null; then - echo "Device $IF_VLAN_RAW_DEVICE for $IFACE does not exist" + if [ -z "${MOCK}" ]; then + if [ ! -d "/sys/class/net/${IF_VLAN_RAW_DEVICE}" ]; then + echo "Underlay device ${IF_VLAN_RAW_DEVICE} for ${IFACE} does not exist" exit 1 fi @@ -65,10 +61,10 @@ up|down) fi fi - ${MOCK} ip link $ADD_DEL link "$IF_VLAN_RAW_DEVICE" name "$IFACE" type vlan id "$IF_VLAN_ID" - [ "$PHASE" = "down" ] && exit 0 + ${MOCK} ip link add link "${IF_VLAN_RAW_DEVICE}" name "${IFACE}" type vlan id "${IF_VLAN_ID}" fi - + ;; +up|down) ${MOCK} ip link set $PHASE dev $IFACE $IF_LINK_OPTIONS # Set alias is configured @@ -77,7 +73,7 @@ up|down) fi ;; post-down) - if [ "${IF_LINK_TYPE}" = "dummy" ]; then + if [ "${IF_LINK_TYPE}" = "dummy" -o is_vlan ]; then if [ -d "/sys/class/net/${IFACE}" ]; then ip link del "${IFACE}" fi From a6b95d495ca0c3b1b5890e61bdec113ae9216046 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 4 Sep 2020 23:32:51 +0200 Subject: [PATCH 2/9] link executor: Only gather and set IFACE_OPTIONS on up. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 9751987..9a716e1 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -4,10 +4,6 @@ set -e [ -n "$VERBOSE" ] && set -x -IF_LINK_OPTIONS="$IF_LINK_OPTIONS" -[ -n "$IF_MTU" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS mtu $IF_MTU" -[ -n "$IF_HWADDRESS" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS address $IF_HWADDRESS" - is_vlan() { case "$IFACE" in *#*) return 1 ;; @@ -64,14 +60,21 @@ pre-up) ${MOCK} ip link add link "${IF_VLAN_RAW_DEVICE}" name "${IFACE}" type vlan id "${IF_VLAN_ID}" fi ;; -up|down) - ${MOCK} ip link set $PHASE dev $IFACE $IF_LINK_OPTIONS +up) + IF_LINK_OPTIONS="$IF_LINK_OPTIONS" + [ -n "$IF_MTU" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS mtu $IF_MTU" + [ -n "$IF_HWADDRESS" ] && IF_LINK_OPTIONS="$IF_LINK_OPTIONS address $IF_HWADDRESS" + + ${MOCK} ip link set up dev "${IFACE}" ${IF_LINK_OPTIONS} # Set alias is configured if [ "${IF_ALIAS}" ]; then ${MOCK} ip link set alias "${IF_ALIAS}" dev "${IFACE}" fi ;; +down) + ${MOCK} ip link set down dev "${IFACE}" + ;; post-down) if [ "${IF_LINK_TYPE}" = "dummy" -o is_vlan ]; then if [ -d "/sys/class/net/${IFACE}" ]; then From 2e6b3ca1ff4a5a21164a97c6531b2eeac5cd760b Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 4 Sep 2020 23:33:27 +0200 Subject: [PATCH 3/9] link executor: Better error message on conflicting link types. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 9a716e1..62e222e 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -32,8 +32,9 @@ pre-up) if [ "${IF_LINK_TYPE}" = "dummy" ]; then if [ -d "/sys/class/net/${IFACE}" ]; then iface_type=$(ip -d link show dev "${IFACE}" | head -n3 | tail -n1 | awk '{ print $1 }') - if [ "${iface_type}" = 'dummy' ]; then - exit 0 + if [ "${iface_type}" != 'dummy' ]; then + echo "Interface ${IFACE} exists but is of type ${iface_type} instead of dummy" + exit 1 fi fi From 58f010fe91b25430c858177cde861a02b10b173c Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Fri, 4 Sep 2020 23:45:49 +0200 Subject: [PATCH 4/9] tests: Reflect latest link executor changes Signed-off-by: Maximilian Wilhelm --- tests/linux/link_test | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/linux/link_test b/tests/linux/link_test index 505adcd..e25d1d1 100755 --- a/tests/linux/link_test +++ b/tests/linux/link_test @@ -8,10 +8,10 @@ tests_init \ down \ mtu \ hwaddress \ - vlan_explicit_up \ - vlan_explicit_down \ - vlan_guessed_up \ - vlan_guessed_down \ + vlan_explicit_pre_up \ + vlan_explicit_post_down \ + vlan_guessed_pre_up \ + vlan_guessed_post_down \ vlan_explicit_depend \ vlan_guessed_depend @@ -39,29 +39,29 @@ hwaddress_body() { ${EXECUTOR} } -vlan_explicit_up_body() { - export IFACE=servers PHASE=up MOCK=echo \ +vlan_explicit_pre_up_body() { + export IFACE=servers PHASE=pre-up MOCK=echo \ IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123" atf_check -s exit:0 -o match:'ip link add link eth0 name servers type vlan id 123' \ ${EXECUTOR} } -vlan_explicit_down_body() { - export IFACE=servers PHASE=down MOCK=echo \ +vlan_explicit_post_down_body() { + export IFACE=servers PHASE=post-down MOCK=echo \ IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123" - atf_check -s exit:0 -o match:'ip link delete link eth0 name servers type vlan id 123' \ + atf_check -s exit:0 -o match:'ip link del servers' \ ${EXECUTOR} } -vlan_guessed_up_body() { - export IFACE=eth0.8 PHASE=up MOCK=echo +vlan_guessed_pre_up_body() { + export IFACE=eth0.8 PHASE=pre-up MOCK=echo atf_check -s exit:0 -o match:'ip link add link eth0 name eth0.8 type vlan id 8' \ ${EXECUTOR} } -vlan_guessed_down_body() { - export IFACE=eth0.8 PHASE=down MOCK=echo - atf_check -s exit:0 -o match:'ip link delete link eth0 name eth0.8 type vlan id 8' \ +vlan_guessed_post_down_body() { + export IFACE=eth0.8 PHASE=post-down MOCK=echo + atf_check -s exit:0 -o match:'ip link del eth0.8' \ ${EXECUTOR} } From 37a7d8f09710093d26fb9620679e763b83113db3 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sat, 5 Sep 2020 00:15:01 +0200 Subject: [PATCH 5/9] link executor: Make vlan disposal MOCKable again Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 62e222e..14d8d9e 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -77,10 +77,12 @@ down) ${MOCK} ip link set down dev "${IFACE}" ;; post-down) - if [ "${IF_LINK_TYPE}" = "dummy" -o is_vlan ]; then - if [ -d "/sys/class/net/${IFACE}" ]; then - ip link del "${IFACE}" + if [ "${IF_LINK_TYPE}" = "dummy" ] || is_vlan; then + if [ -z "${MOCK}" -a ! -d "/sys/class/net/${IFACE}" ]; then + exit 0 fi + + ip link del "${IFACE}" fi ;; depend) From d24b4ab3e603114339e7dfde2eba9d3f0851b95e Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sat, 5 Sep 2020 00:15:26 +0200 Subject: [PATCH 6/9] link executor: Make dummy creation MOCKable, too Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 14d8d9e..2c1472f 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -38,7 +38,7 @@ pre-up) fi fi - ip link add "${IFACE}" type dummy + ${MOCK} ip link add "${IFACE}" type dummy fi if is_vlan; then From aa3e94acf83df565d2bec870b1d91efdb38595a8 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sat, 5 Sep 2020 00:18:43 +0200 Subject: [PATCH 7/9] link executor: Make link deletion MOCKable again. Signed-off-by: Maximilian Wilhelm --- executor-scripts/linux/link | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor-scripts/linux/link b/executor-scripts/linux/link index 2c1472f..7211d70 100755 --- a/executor-scripts/linux/link +++ b/executor-scripts/linux/link @@ -82,7 +82,7 @@ post-down) exit 0 fi - ip link del "${IFACE}" + ${MOCK} ip link del "${IFACE}" fi ;; depend) From 4a05010539c02aac3b0a87db047bd953d7920743 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sat, 5 Sep 2020 00:24:40 +0200 Subject: [PATCH 8/9] tests: Fix vlan_explicit_depend_body. Signed-off-by: Maximilian Wilhelm --- tests/linux/link_test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/linux/link_test b/tests/linux/link_test index e25d1d1..c4389f4 100755 --- a/tests/linux/link_test +++ b/tests/linux/link_test @@ -66,7 +66,7 @@ vlan_guessed_post_down_body() { } vlan_explicit_depend_body() { - export IFACE=servers PHASE=up MOCK=echo \ + export IFACE=servers PHASE=depend \ IF_VLAN_RAW_DEVICE="eth0" IF_VLAN_ID="123" atf_check -s exit:0 -o match:'eth0' \ ${EXECUTOR} From 32b7dda832c8cfb9965e70d34cd98aa112a9f752 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Sat, 5 Sep 2020 00:28:12 +0200 Subject: [PATCH 9/9] tests: Add test for dummy link creation. Signed-off-by: Maximilian Wilhelm --- tests/linux/link_test | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/linux/link_test b/tests/linux/link_test index c4389f4..db3e787 100755 --- a/tests/linux/link_test +++ b/tests/linux/link_test @@ -13,7 +13,8 @@ tests_init \ vlan_guessed_pre_up \ vlan_guessed_post_down \ vlan_explicit_depend \ - vlan_guessed_depend + vlan_guessed_depend \ + dummy_pre_up up_body() { export IFACE=lo PHASE=up MOCK=echo @@ -77,3 +78,9 @@ vlan_guessed_depend_body() { atf_check -s exit:0 -o match:'eth0' \ ${EXECUTOR} } + +dummy_pre_up_body() { + export IFACE=yolo IF_LINK_TYPE=dummy PHASE=pre-up MOCK=echo + atf_check -s exit:0 -o match:'ip link add yolo type dummy' \ + ${EXECUTOR} +}