From 6c1f07ddfde2269a408ae90cbb9bf99477b778e2 Mon Sep 17 00:00:00 2001 From: Pablo Greco Date: Jul 28 2019 18:05:40 +0000 Subject: Fix bridge test for CentOS8 and improve test cleanup --- diff --git a/tests/p_bridge-utils/00-install_bridge-utils.sh b/tests/p_bridge-utils/00-install_bridge-utils.sh index 69045ed..6ae9b1b 100755 --- a/tests/p_bridge-utils/00-install_bridge-utils.sh +++ b/tests/p_bridge-utils/00-install_bridge-utils.sh @@ -4,4 +4,8 @@ # Install bridge_utils package t_Log "Running $0 - bridge-utils: Installation" +if [ "$centos_ver" -ge 8 ] ; then +t_InstallPackage iproute +else t_InstallPackage bridge-utils +fi diff --git a/tests/p_bridge-utils/05-add_bridge.sh b/tests/p_bridge-utils/05-add_bridge.sh index e21c60b..21ec278 100755 --- a/tests/p_bridge-utils/05-add_bridge.sh +++ b/tests/p_bridge-utils/05-add_bridge.sh @@ -8,20 +8,11 @@ else bridge=$1 fi +. "$(dirname "$0")"/p_bridge-utils-functions + t_Log "Running $0 - Adding a dummy Bridge: $bridge" -bridge_present=`brctl show | grep $bridge` -if ! [ "$bridge_present" ] - then - brctl addbr $bridge - bridge_present=`brctl show | grep $bridge` - if [ "$bridge_present" ] - then - ret_val=0 - else - ret_val=1 - fi -else - ret_val=0 -fi +ret_val=$(bru_add_bridge $bridge) t_CheckExitStatus $ret_val +bru_del_bridge $bridge >/dev/null +exit $ret_val diff --git a/tests/p_bridge-utils/10-delete_bridge.sh b/tests/p_bridge-utils/10-delete_bridge.sh index 1472401..046db4a 100755 --- a/tests/p_bridge-utils/10-delete_bridge.sh +++ b/tests/p_bridge-utils/10-delete_bridge.sh @@ -1,24 +1,14 @@ #!/bin/bash # Author : Madhurranjan Mohaan + +. "$(dirname "$0")"/p_bridge-utils-functions #add bridge bridge=testbridge2 -./tests/p_bridge-utils/05-add_bridge.sh $bridge -#delete the bridge created -bridge_present=`brctl show | grep $bridge` +bru_add_bridge $bridge >/dev/null + t_Log "Running $0 - Deleting the dummy bridge: $bridge" -if ! [ "$bridge_present" ] - then - ret_val=1 -else - t_Log "Deleting bridge $bridge" - brctl delbr $bridge - bridge_present=`brctl show | grep $bridge` - if [ $bridge_present ] - then - ret_val=1 - else - ret_val=0 - fi -fi +t_Log "Deleting bridge $bridge" +ret_val=$(bru_del_bridge $bridge) + t_CheckExitStatus $ret_val diff --git a/tests/p_bridge-utils/p_bridge-utils-functions b/tests/p_bridge-utils/p_bridge-utils-functions new file mode 100644 index 0000000..9f66c02 --- /dev/null +++ b/tests/p_bridge-utils/p_bridge-utils-functions @@ -0,0 +1,96 @@ +#!/bin/bash + +function bru_add_bridge_7 +{ + bridge=$1 + bridge_present=`brctl show | grep $bridge` + if ! [ "$bridge_present" ] + then + brctl addbr $bridge + bridge_present=`brctl show | grep $bridge` + if [ "$bridge_present" ] + then + ret_val=0 + else + ret_val=1 + fi + else + ret_val=0 + fi + echo $ret_val +} +function bru_add_bridge_8 +{ + bridge=$1 + bridge_present=`cat /proc/net/dev | grep $bridge` + if ! [ "$bridge_present" ] + then + ip link add name $bridge type bridge + bridge_present=`cat /proc/net/dev | grep $bridge` + if [ "$bridge_present" ] + then + ret_val=0 + else + ret_val=1 + fi + else + ret_val=0 + fi + echo $ret_val +} + +function bru_del_bridge_7 +{ + bridge=$1 + bridge_present=`brctl show | grep $bridge` + if ! [ "$bridge_present" ] + then + ret_val=1 + else + brctl delbr $bridge + bridge_present=`brctl show | grep $bridge` + if [ $bridge_present ] + then + ret_val=1 + else + ret_val=0 + fi + fi +} +function bru_del_bridge_8 +{ + bridge=$1 + bridge_present=`cat /proc/net/dev | grep $bridge` + if ! [ "$bridge_present" ] + then + ret_val=1 + else + ip link del name $bridge + bridge_present=`cat /proc/net/dev | grep $bridge` + if [ $bridge_present ] + then + ret_val=1 + else + ret_val=0 + fi + fi + echo $ret_val +} + +function bru_add_bridge +{ + if [ "$centos_ver" -ge 8 ] ; then + bru_add_bridge_8 $1 + else + bru_add_bridge_7 $1 + fi +} + +function bru_del_bridge +{ + if [ "$centos_ver" -ge 8 ] ; then + bru_del_bridge_8 $1 + else + bru_del_bridge_7 $1 + fi +}