Blame tests/bridge-utility/runtest.sh

Petr Šabata d9a596
#!/bin/bash
Petr Šabata d9a596
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
Petr Šabata d9a596
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Petr Šabata d9a596
#
Petr Šabata d9a596
#   runtest.sh of /CoreOS/iproute/Sanity/bridge-utility
Petr Šabata d9a596
#   Description: Test basic bridge funcionality
Petr Šabata d9a596
#   Author: David Spurek <dspurek@redhat.com>
Petr Šabata d9a596
#
Petr Šabata d9a596
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Petr Šabata d9a596
#
Petr Šabata d9a596
#   Copyright (c) 2013 Red Hat, Inc. All rights reserved.
Petr Šabata d9a596
#
Petr Šabata d9a596
#   This copyrighted material is made available to anyone wishing
Petr Šabata d9a596
#   to use, modify, copy, or redistribute it subject to the terms
Petr Šabata d9a596
#   and conditions of the GNU General Public License version 2.
Petr Šabata d9a596
#
Petr Šabata d9a596
#   This program is distributed in the hope that it will be
Petr Šabata d9a596
#   useful, but WITHOUT ANY WARRANTY; without even the implied
Petr Šabata d9a596
#   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Petr Šabata d9a596
#   PURPOSE. See the GNU General Public License for more details.
Petr Šabata d9a596
#
Petr Šabata d9a596
#   You should have received a copy of the GNU General Public
Petr Šabata d9a596
#   License along with this program; if not, write to the Free
Petr Šabata d9a596
#   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Petr Šabata d9a596
#   Boston, MA 02110-1301, USA.
Petr Šabata d9a596
#
Petr Šabata d9a596
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Petr Šabata d9a596
Petr Šabata d9a596
# Include Beaker environment
Petr Šabata d9a596
. /usr/bin/rhts-environment.sh || exit 1
Petr Šabata d9a596
. /usr/share/beakerlib/beakerlib.sh || exit 1
Petr Šabata d9a596
Petr Šabata d9a596
PACKAGE="iproute"
Petr Šabata d9a596
Petr Šabata d9a596
PACKAGES="$PACKAGE"
Petr Šabata d9a596
rlIsRHEL 6 && PACKAGES=( ${PACKAGES[@]} "bridge-utils" )
Petr Šabata d9a596
vxlan_name="testvxlan"
Petr Šabata d9a596
bridge_name="testbridge"
Petr Šabata d9a596
lsmod | grep dummy
Petr Šabata d9a596
dummy_loaded=$?
Petr Šabata d9a596
Petr Šabata d9a596
rlJournalStart
Petr Šabata d9a596
    rlPhaseStartSetup
Petr Šabata d9a596
        # Check reqiured packages.
Petr Šabata d9a596
        for P in ${PACKAGES[@]}; do rlCheckRpm $P || rlDie "Package $P is missing"; done
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
Petr Šabata d9a596
        rlRun "pushd $TmpDir"
Petr Šabata d9a596
        no_dummy=0
Petr Šabata d9a596
        if [ $dummy_loaded -eq 1 ] ; then
Petr Šabata d9a596
                # dummy module doesn't loaded before the test
Petr Šabata d9a596
                modprobe dummy numdummies=2
Petr Šabata d9a596
        else
Petr Šabata d9a596
                # dummy module loaded before the test, backup number of loaded dummy devices (nmdumies parameter), it is doesn't show under /sys/module/dummy/parameters
Petr Šabata d9a596
                dummies_count=`ip a | grep dummy | tail -n 1 | sed -r 's/.*dummy([0-9]+).*/\1/'`
Petr Šabata d9a596
                if [ -z $dummies_count] ; then
Petr Šabata d9a596
                        # dummy module is loaded but no dummy device exists
Petr Šabata d9a596
                        no_dummy=1
Petr Šabata d9a596
                else
Petr Šabata d9a596
                        # get correct count, dummy0 is the first
Petr Šabata d9a596
                        let "dummies_count=$dummies_count+1"
Petr Šabata d9a596
                fi
Petr Šabata d9a596
                rmmod dummy
Petr Šabata d9a596
                modprobe dummy numdummies=2
Petr Šabata d9a596
        fi
Petr Šabata d9a596
        rlRun "ip addr flush dev dummy0"
Petr Šabata d9a596
        rlRun "ip link set dummy0 up"
Petr Šabata d9a596
        rlRun "ip addr flush dev dummy1"
Petr Šabata d9a596
        rlRun "ip link set dummy1 up"
Petr Šabata d9a596
        rlRun "ip addr add 127.0.0.13/24 dev dummy0" 0 "Setting IPv4 address to 
Petr Šabata d9a596
dummy0 interface"
Petr Šabata d9a596
        rlRun "ip addr add 127.0.0.14/24 dev dummy1" 0 "Setting IPv4 address to 
Petr Šabata d9a596
dummy1 interface"
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
Petr Šabata d9a596
    rlPhaseStartTest "Test bridge fdb basic funcionality with vxlan device"
Petr Šabata d9a596
        rlRun "ip link add $vxlan_name type vxlan id 10 group 239.0.0.10 ttl 4 dev dummy0" 0 "add vxlan interface"
Petr Šabata d9a596
        rlRun "ip addr add 192.168.1.1/24 broadcast 192.168.1.255 dev $vxlan_name" 0 "setting address to vxlan interface"
Petr Šabata d9a596
        rlRun "ip -d link show $vxlan_name" 0 "show details about vxlan device" 
Petr Šabata d9a596
Petr Šabata d9a596
        vxlan_ether_address=`ip -d link show $vxlan_name | grep link/ether | awk '{print $2}'`
Petr Šabata d9a596
        echo "ethernet address of vxlan device is: $vxlan_ether_address"
Petr Šabata d9a596
Petr Šabata d9a596
        # add new entry to bridge fdb database (device must by type vxlan)
Petr Šabata d9a596
        rlRun "bridge fdb add $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name"
Petr Šabata d9a596
Petr Šabata d9a596
        # check if entry was successfuly added
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        # try replace entry in bridge fdb database
Petr Šabata d9a596
        rlRun "bridge fdb replace $vxlan_ether_address dst 192.19.0.3 dev $vxlan_name"
Petr Šabata d9a596
Petr Šabata d9a596
        # check if entry was successfuly changed
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.3" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "bridge fdb del $vxlan_ether_address dev $vxlan_name"
Petr Šabata d9a596
Petr Šabata d9a596
        # check if entry was successfuly deleted
Petr Šabata d9a596
        # 'default' entry added by ip link command should be still listed
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertNotGrep "$vxlan_ether_address dst 192.19.0.2" bridge_show.out "-i"
Petr Šabata d9a596
        rlAssertGrep "dst 239.0.0.10 via dummy0" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        # add new entry to bridge fdb database with port,vni and via options
Petr Šabata d9a596
        rlRun "bridge fdb add $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name port 10000 vni 100 via dummy0"
Petr Šabata d9a596
        # check if entry was successfuly added
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2 port 10000 vni 100 via dummy0" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "bridge fdb del $vxlan_ether_address dev $vxlan_name"
Petr Šabata d9a596
Petr Šabata d9a596
        # add new entry to bridge fdb database with self option
Petr Šabata d9a596
        rlRun "bridge fdb add $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name self"
Petr Šabata d9a596
        # check if entry was successfuly added
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2 self" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        # replace entry in bridge fdb database with temp option
Petr Šabata d9a596
        rlRun "bridge fdb replace $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name temp"
Petr Šabata d9a596
        # check if entry was successfuly changed
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2 self static" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        # replace entry in bridge fdb database with local option
Petr Šabata d9a596
        rlRun "bridge fdb replace $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name local"
Petr Šabata d9a596
        # check if entry was successfuly changed
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2 self permanent" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        # replace entry in bridge fdb database with router option
Petr Šabata d9a596
        rlRun "bridge fdb replace $vxlan_ether_address dst 192.19.0.2 dev $vxlan_name router"
Petr Šabata d9a596
        # check if entry was successfuly changed
Petr Šabata d9a596
        bridge fdb show dev $vxlan_name &> bridge_show.out
Petr Šabata d9a596
        cat bridge_show.out
Petr Šabata d9a596
        rlAssertGrep "$vxlan_ether_address dst 192.19.0.2 self router permanent" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "bridge fdb del $vxlan_ether_address dev $vxlan_name"
Petr Šabata d9a596
        rlRun "ip link del $vxlan_name" 0
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
Petr Šabata d9a596
    rlPhaseStartTest "Test bridge fdb basic funcionality with bridge device, test bridge link set command"
Petr Šabata d9a596
        # on rhels < 7 must be bridge device added with brctl (add type bridge is not supported)
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link add $bridge_name type bridge" 0 || rlRun "brctl addbr $bridge_name" 0
Petr Šabata d9a596
Petr Šabata d9a596
        if rlIsRHEL '>=7'; then
Petr Šabata d9a596
                rlRun "ip link set dummy0 master $bridge_name" 0 "Add dummy interface to bridge"
Petr Šabata d9a596
                rlRun "bridge link show dev dummy0"
Petr Šabata d9a596
                # test bridge link set, command is not supported on rhel < 7 (->ndo_bridge_setlink() is not in our kernel.)
Petr Šabata d9a596
Petr Šabata d9a596
                rlRun "bridge link set dev dummy0 cost 10"
Petr Šabata d9a596
                rlRun "bridge link show dev dummy0 &> bridge_show.out" 0
Petr Šabata d9a596
                cat bridge_show.out
Petr Šabata d9a596
                rlAssertGrep "dummy0.*cost 10 $" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
                # add new entry to bridge fdb database with self option
Petr Šabata d9a596
                rlRun "bridge fdb add 00:1b:21:55:23:61 dev dummy0 self"
Petr Šabata d9a596
                bridge fdb show dev dummy0 &> bridge_show.out
Petr Šabata d9a596
                cat bridge_show.out
Petr Šabata d9a596
                rlAssertGrep "00:1b:21:55:23:61 self" bridge_show.out "-i"
Petr Šabata d9a596
                # add new entry to bridge fdb database with master option
Petr Šabata d9a596
                rlRun "bridge fdb add 00:1b:21:55:23:62 dev dummy0 master"
Petr Šabata d9a596
                bridge fdb show dev dummy0 &> bridge_show.out
Petr Šabata d9a596
                cat bridge_show.out
Petr Šabata d9a596
                rlAssertGrep "00:1b:21:55:23:62 vlan 1" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
                # add new entry to bridge fdb database with master and self options (entries for both should be added)
Petr Šabata d9a596
                rlRun "bridge fdb add 00:1b:21:55:23:63 dev dummy0 self master"
Petr Šabata d9a596
                bridge fdb show dev dummy0 &> bridge_show.out
Petr Šabata d9a596
                cat bridge_show.out
Petr Šabata d9a596
                rlAssertGrep "00:1b:21:55:23:63 self" bridge_show.out "-i"
Petr Šabata d9a596
                rlAssertGrep "00:1b:21:55:23:63 vlan 1" bridge_show.out "-i"
Petr Šabata d9a596
Petr Šabata d9a596
        else
Petr Šabata d9a596
                rlRun "brctl addif $bridge_name dummy0" 0 "Add dummy interface to bridge"
Petr Šabata d9a596
                rlRun "brctl show $bridge_name"
Petr Šabata d9a596
        fi
Petr Šabata d9a596
        
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link set dummy0 nomaster" 0 "Remove dummy vlan interface from bridge" || rlRun "brctl delif $bridge_name dummy0" 0 "Remove dummy interface from bridge"
Petr Šabata d9a596
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link del $bridge_name" 0 || rlRun "brctl delbr $bridge_name" 0
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
Petr Šabata d9a596
    rlPhaseStartTest "Test bridge vlan basic funcionality"
Petr Šabata d9a596
        # on rhels < 7 must be bridge device added with brctl (add type bridge is not supported)
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link add $bridge_name type bridge" 0 || rlRun "brctl addbr $bridge_name" 0
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "ip link add link dummy0 name dummy0.10 type vlan id 10"
Petr Šabata d9a596
        if rlIsRHEL '>=7' ; then
Petr Šabata d9a596
                rlRun "ip link set dummy0.10 master $bridge_name" 0 "Add dummy vlan interface to bridge"
Petr Šabata d9a596
                rlRun "bridge link show dev dummy0.10"
Petr Šabata d9a596
        else
Petr Šabata d9a596
                rlRun "brctl addif $bridge_name dummy0.10" 0 "Add dummy vlan interface to bridge"
Petr Šabata d9a596
                rlRun "brctl show $bridge_name"
Petr Šabata d9a596
        fi
Petr Šabata d9a596
        # bridge vlan is not supported on rhel < 6.8
Petr Šabata d9a596
        if rlIsRHEL '>=7' || rlIsRHEL '>=6.8' || rlIsFedora; then
Petr Šabata d9a596
            rlRun "bridge vlan add dev dummy0.10 vid 5" 0
Petr Šabata d9a596
        else
Petr Šabata d9a596
            rlRun "bridge vlan add dev dummy0.10 vid 5" 2
Petr Šabata d9a596
        fi
Petr Šabata d9a596
Petr Šabata d9a596
        # test correct funcionality only on rhel 7
Petr Šabata d9a596
        if rlIsRHEL '>=7' ; then
Petr Šabata d9a596
                bridge vlan &> bridge_vlan.out
Petr Šabata d9a596
                cat bridge_vlan.out
Petr Šabata d9a596
                #rlAssertGrep "dummy0.10.*5" bridge_vlan.out "-i"
Petr Šabata d9a596
                #rlAssertGrep "dummy0.10.*10" bridge_vlan.out "-i"
Petr Šabata d9a596
                rlRun "grep -A 2 'dummy0.10' bridge_vlan.out | grep '5'"
Petr Šabata d9a596
Petr Šabata d9a596
                rlRun "bridge vlan del dev dummy0.10 vid 5"
Petr Šabata d9a596
                bridge vlan &> bridge_vlan.out
Petr Šabata d9a596
                cat bridge_vlan.out
Petr Šabata d9a596
                #rlAssertNotGrep "dummy0.10" bridge_vlan.out "-i"
Petr Šabata d9a596
                rlRun "grep -A 2 'dummy0.10' bridge_vlan.out | grep '5'" 1
Petr Šabata d9a596
        fi
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link set dummy0.10 nomaster" 0 "Remove dummy vlan interface from bridge" || rlRun "brctl delif $bridge_name dummy0.10" 0 "Remove dummy vlan interface from bridge"
Petr Šabata d9a596
Petr Šabata d9a596
        rlRun "ip link del dev dummy0.10"
Petr Šabata d9a596
Petr Šabata d9a596
        rlIsRHEL '>=7' && rlRun "ip link del $bridge_name" 0 || rlRun "brctl delbr $bridge_name" 0
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
Petr Šabata d9a596
    rlPhaseStartTest "Test bridge mdb basic funcionality"
Petr Šabata d9a596
        rlRun "bridge mdb show" 0
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
Petr Šabata d9a596
    if rlIsRHEL '>=7'; then
Petr Šabata d9a596
        rlPhaseStartTest
Petr Šabata d9a596
            rlRun "ip link add test_bridge type bridge"
Petr Šabata d9a596
            rlRun "bridge fdb show | grep 'dev test_bridge' | grep 'master test_bridge'"
Petr Šabata d9a596
            rlRun "ip link del test_bridge"
Petr Šabata d9a596
        rlPhaseEnd
Petr Šabata d9a596
    fi
Petr Šabata d9a596
Petr Šabata d9a596
    rlPhaseStartCleanup
Petr Šabata d9a596
        rlRun "ip route flush dev dummy0"
Petr Šabata d9a596
        rlRun "ip link set dummy0 down"
Petr Šabata d9a596
        rlRun "ip addr flush dev dummy0"
Petr Šabata d9a596
        rlRun "ip route flush dev dummy1"
Petr Šabata d9a596
        rlRun "ip link set dummy1 down"
Petr Šabata d9a596
        rlRun "ip addr flush dev dummy1"
Petr Šabata d9a596
        if [ $dummy_loaded -eq 1 ] ; then
Petr Šabata d9a596
                rmmod dummy
Petr Šabata d9a596
        else
Petr Šabata d9a596
                rmmod dummy
Petr Šabata d9a596
                if [ $no_dummy -eq 1 ] ; then
Petr Šabata d9a596
                        # load dummy module and delete dummy0 with ip link
Petr Šabata d9a596
                        modprobe dummy
Petr Šabata d9a596
                         rlIsRHEL '>=7' && rlRun "ip link del dummy0"
Petr Šabata d9a596
                else
Petr Šabata d9a596
                        modprobe dummy numdummies=$dummies_count
Petr Šabata d9a596
                fi
Petr Šabata d9a596
        fi
Petr Šabata d9a596
        rlRun "service network restart" 0,1 "Restarting network, just for sure"
Petr Šabata d9a596
        rlRun "popd"
Petr Šabata d9a596
        rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
Petr Šabata d9a596
    rlPhaseEnd
Petr Šabata d9a596
rlJournalPrintText
Petr Šabata d9a596
rlJournalEnd