Could anyone help to review this?

Thanks
Simon

On 2014/3/28 9:44, Simon Xu wrote:
> The script uses hardcoded 'eth0' which used to work on most systems.
> This fix tries to find a 'working' network interface using the hostname.
>
> Signed-off-by: Simon Xu <xu.si...@oracle.com>
> ---
>   testcases/network/iproute/ip_tests.sh | 50 
> +++++++++++++++++++----------------
>   1 file changed, 27 insertions(+), 23 deletions(-)
>
> diff --git a/testcases/network/iproute/ip_tests.sh 
> b/testcases/network/iproute/ip_tests.sh
> index ed20540..4bba243 100755
> --- a/testcases/network/iproute/ip_tests.sh
> +++ b/testcases/network/iproute/ip_tests.sh
> @@ -38,7 +38,7 @@ set +x
>   # Description:      - Check if command ip is available.
>   #               - Check if command ifconfig is available.
>   #               - check if command awk is available.
> -#               - alias eth0 to eth0:1 with IP 10.1.1.12
> +#               - alias $INF to $INF:1 with IP 10.1.1.12
>   #
>   # Return            - zero on success
>   #               - non zero on failure. return value from commands ($RC)
> @@ -46,7 +46,7 @@ init()
>   {
>   
>       export TST_TOTAL=2                      # total numner of tests in this 
> file.
> -     export TCID="ip_tests  "                # this is the init function.
> +     export TCID="ip_tests"                  # this is the init function.
>       export TST_COUNT=0                      # init identifier,
>   
>       if [ -z $TMP ]
> @@ -107,22 +107,26 @@ init()
>   
>       tst_resm TINFO "INIT: Inititalizing tests."
>   
> -     # Aliasing eth0 to create private network.
> -     /sbin/ifconfig eth0:1 10.1.1.12 >$LTPTMP/tst_ip.err 2>&1
> +     # Get network interface.
> +     IP=$(dig +short $(hostname))
> +     INF=$(ifconfig|grep -B1 $IP|head -1|sed 's/:.*//')
> +
> +     # Aliasing $INF to create private network.
> +     /sbin/ifconfig $INF:1 10.1.1.12 >$LTPTMP/tst_ip.err 2>&1
>       RC=$?
>       if [ $RC -ne 0 ]
>       then
> -             tst_brk TBROK NULL NULL "INIT: failed aliasing eth0:1 with IP 
> 10.1.1.12"
> +             tst_brk TBROK NULL NULL "INIT: failed aliasing $INF:1 with IP 
> 10.1.1.12"
>               return $RC
>       else
> -             /sbin/route add -host 10.1.1.12 dev eth0:1 >$LTPTMP/tst_ip.err 
> 2>&1
> +             /sbin/route add -host 10.1.1.12 dev $INF:1 >$LTPTMP/tst_ip.err 
> 2>&1
>               RC=$?
>               if [ $RC -ne 0 ]
>               then
>                       tst_brk TBROK NULL NULL "INIT: failed adding route to 
> 10.1.1.12"
>                       return $RC
>               else
> -                     tst_resm TINFO "INIT: added alias: `ifconfig eth0:1`"
> +                     tst_resm TINFO "INIT: added alias: `ifconfig $INF:1`"
>               fi
>       fi
>   
> @@ -148,7 +152,7 @@ init()
>   # Function:         cleanup
>   #
>   # Description       - remove temporary files and directories.
> -#               - remove alias to eth0
> +#               - remove alias to $INF
>   #
>   # Return            - zero on success
>   #               - non zero on failure. return value from commands ($RC)
> @@ -157,11 +161,11 @@ cleanup()
>       TCID=dhcpd
>       TST_COUNT=0
>   
> -     /sbin/ifconfig eth0:1 >$LTPTMP/tst_ip.err 2>&1
> +     /sbin/ifconfig $INF:1 >$LTPTMP/tst_ip.err 2>&1
>       RC=$?
>       if [ $RC -eq 0 ]
>       then
> -             /sbin/ifconfig eth0:1 down >$LTPTMP/tst_ip.err 2>&1
> +             /sbin/ifconfig $INF:1 down >$LTPTMP/tst_ip.err 2>&1
>       fi
>   
>       rm -fr $LTPTMP
> @@ -189,11 +193,11 @@ test01()
>       tst_resm TINFO \
>        "Test #1: ip link set DEVICE mtu MTU changes the device mtu size"
>   
> -     tst_resm TINFO "Test #1: changing mtu size of eth0:1 device."
> +     tst_resm TINFO "Test #1: changing mtu size of $INF:1 device."
>   
>       MTUSZ_BAK=`ifconfig eth0:1 | grep -i MTU | sed "s/^.*MTU://" \
>               | awk '{print $1}'`
> -     ip link set eth0:1 mtu 300 >$LTPTMP/tst_ip.err 2>&1
> +     ip link set $INF:1 mtu 300 >$LTPTMP/tst_ip.err 2>&1
>       if [ $RC -ne 0 ]
>       then
>               tst_res TFAIL $LTPTMP/tst_ip.err \
> @@ -204,7 +208,7 @@ test01()
>               if [ $MTUSZ -eq 300 ]
>               then
>                       tst_resm TPASS "Test #1: changing mtu size success"
> -                     ip link set eth0:1 mtu $MTUSZ_BAK \
> +                     ip link set $INF:1 mtu $MTUSZ_BAK \
>                               >$LTPTMP/tst_ip.err 2>&1
>               else
>                       tst_resm FAIL NULL \
> @@ -256,7 +260,7 @@ test02()
>               return $RC
>       else
>               tst_resm TPASS \
> -                     "Test #2: Listed eth0:1 and returned correct attributes"
> +                     "Test #2: Listed $INF:1 and returned correct attributes"
>       fi
>       return $RC
>   }
> @@ -365,7 +369,7 @@ test04()
>               return $RC
>       else
>               tst_resm TINFO \
> -              "Test #4: ip neigh show - shows all neighbour entries in arp 
> tables."
> +                     "Test #4: ip neigh show - shows all neighbour entries 
> in arp tables."
>   
>               cat > $LTPTMP/tst_ip.exp <<-EOF
>               127.0.0.1 dev lo lladdr 00:00:00:00:00:00 REACHABLE
> @@ -443,14 +447,14 @@ test05()
>   
>   
>       tst_resm TINFO \
> -      "Test #5: create an interface with inet 10.6.6.6 alias to eth0"
> +      "Test #5: create an interface with inet 10.6.6.6 alias to $INF"
>   
> -     ifconfig eth0:1 10.6.6.6 netmask 255.255.255.0 >$LTPTMP/tst_ip.err 2>&1
> +     ifconfig $INF:1 10.6.6.6 netmask 255.255.255.0 >$LTPTMP/tst_ip.err 2>&1
>       RC=$?
>       if [ $RC -ne 0 ]
>       then
>               tst_brk TBROK $LTPTMP/tst_ip.err NULL \
> -                     "Test #5: unable to create interface eth0:1 inet 
> 10.6.6.6. Reason:"
> +                     "Test #5: unable to create interface $INF:1 inet 
> 10.6.6.6. Reason:"
>               return $RC
>       fi
>   
> @@ -541,16 +545,16 @@ test06()
>       tst_resm TINFO \
>        "Test #6: ip maddr add - adds a new multicast addr"
>   
> -     ifconfig eth0:1 10.6.6.6 netmask 255.255.255.0 >$LTPTMP/tst_ip.err 2>&1
> +     ifconfig $INF:1 10.6.6.6 netmask 255.255.255.0 >$LTPTMP/tst_ip.err 2>&1
>       RC=$?
>       if [ $RC -ne 0 ]
>       then
>               tst_brk TBROK $LTPTMP/tst_ip.err NULL \
> -                     "Test #6: unable to create interface eth0:1 inet 
> 10.6.6.6. Reason:"
> +                     "Test #6: unable to create interface $INF:1 inet 
> 10.6.6.6. Reason:"
>               return $RC
>       fi
>   
> -     ip maddr add 66:66:00:00:00:66 dev eth0:1 >$LTPTMP/tst_ip.err 2>&1
> +     ip maddr add 66:66:00:00:00:66 dev $INF:1 >$LTPTMP/tst_ip.err 2>&1
>       RC=$?
>       if [ $RC -ne 0 ]
>       then
> @@ -579,7 +583,7 @@ test06()
>                       if [ $RC -ne 0 ]
>                       then
>                               tst_res FAIL $LTPTMP/tst_ip.err \
> -                                     "Test #6: multicast addr not added to 
> eth0:1. Details:"
> +                                     "Test #6: multicast addr not added to 
> $INF:1. Details:"
>                               return $RC
>                       fi
>               fi
> @@ -587,7 +591,7 @@ test06()
>               tst_resm TINFO \
>                "Test #6: ip maddr del - deletes multicast addr."
>   
> -             ip maddr del 66:66:00:00:00:66 dev eth0:1 >$LTPTMP/tst_ip.err 
> 2>&1
> +             ip maddr del 66:66:00:00:00:66 dev $INF:1 >$LTPTMP/tst_ip.err 
> 2>&1
>               RC=$?
>               if [ $RC -ne 0 ]
>               then


------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to