[LTP] [RFC PATCH v8 07/11] lib/test_net.sh: Add function reset_ltp_netspace()

Alexey Kodanev alexey.kodanev@oracle.com
Wed Aug 23 11:39:33 CEST 2017


On 22.08.2017 23:13, Petr Vorel wrote:
> Hi Alexey,
>
>>> +# Force to reset netns.
>>> +reset_ltp_netspace()
>>> +{
>>> +	[ -n "$TST_USE_NETNS" ] || return
>>> +
>>> +	tst_resm TINFO "reset netns"
>>> +	ip link delete ltp_ns_veth2 2> /dev/null
>>> +	rm -f /var/run/netns/ltp_ns
>>> +	pkill ns_create
>> Hmm, if there was custom netns you would break it anyway with this
>> function and change to LTP one.
>> I guess we should leave it unsupported for route rmmod test unless we
>> figure out the right solution.
>> Also, what if we reset only ltp veth pair, i.e.:
>> reset_ltp_netspace()
>> {
>>     ...
>>     [ "$(tst_iface)" != "ltp_ns_veth2" ] || return
> Why this? I suppose it detects whether custom netns is used, but then I'd swap the
> condition to:
> 	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return

Right

>
>>     ip li del ltp_ns_veth2 2>/dev/null
>> }
>> init_ltp_netspace()
>> {
>>     ...
>>     pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>>     export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
>>     if ! ip li sh $LHOST_IFACES > /dev/null 2>&1; then
>>         ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
> Code duplicity :-(.

Why? it is moved here from the upper if block.

>>         ROD ns_ifmove ltp_ns_veth1 $pid
>>     fi
>>     ...
>> }
> It's working for me with this patch (turn over the condition in reset_ltp_netspace(), assuming
> that custom netns would have different LHOST_IFACES, is that correct?):

I'm not sure how to handle it correctly for rmmod test right now,
may be we should TCONF on the check inside the test:

$TST_USE_NETNS -a "$(tst_iface)" != "ltp_ns_veth2"


Thanks,
Alexey

>
> +++ b/testcases/lib/test_net.sh
> @@ -44,12 +44,26 @@ init_ltp_netspace()
>  	pid="$(echo $(readlink /var/run/netns/ltp_ns) | cut -f3 -d'/')"
>  	export LTP_NETNS="${LTP_NETNS:-ns_exec $pid net,mnt}"
>  
> +	if ! ip li show $LHOST_IFACES > /dev/null 2>&1; then
> +		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
> +		ROD ns_ifmove ltp_ns_veth1 $pid
> +	fi
> +
>  	tst_restore_ipaddr
>  	tst_restore_ipaddr rhost
>  
>  	tst_wait_ipv6_dad
>  }
>  
> +# Force to reset netns.
> +reset_ltp_netspace()
> +{
> +	[ "$(tst_iface)" = "ltp_ns_veth2" ] || return
> +	tst_resm TINFO "reset netns"
> +	ip link delete ltp_ns_veth2 2> /dev/null
> +	init_ltp_netspace
> +}
> +




More information about the ltp mailing list