Skip to contentSkip to conversation

tst_net.sh: Add more tst_require_cmds check

PATCH In review Wei Gao via ltp 2 participants 7 messages Jan 17, 2023 – Jan 26, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tst_net.sh: Add more tst_require_cmds check

More strict check for ns_xxx etc will help avoid following issue:
https://github.com/linux-test-project/ltp/issues/991

---
 testcases/lib/tst_net.sh | 2 ++
 1 file changed, 2 insertions(+)
testcases/lib/tst_net.sh +2 -0
index ceb45c98d..ec915ad74 100644
@@ -205,6 +205,7 @@ tst_rhost_run()
 	sh_cmd="$pre_cmd $cmd $post_cmd"
 
 	if [ -n "${TST_USE_NETNS:-}" ]; then
+		tst_require_cmds ip ns_create ns_exec ns_ifmove
 		use="NETNS"
 		rcmd="$LTP_NETNS sh -c"
 	else
@@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
 # tst_net_iface_prefix -h
 # tst_net_vars -h
 if [ -z "$_tst_net_parse_variables" ]; then
+	tst_require_cmds tst_net_ip_prefix
 	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
 	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
 
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wei,

Quoted 14 lines

More strict check for ns_xxx etc will help avoid following issue:
https://github.com/linux-test-project/ltp/issues/991

---
 testcases/lib/tst_net.sh | 2 ++
 1 file changed, 2 insertions(+)
testcases/lib/tst_net.sh +0 -0
index ceb45c98d..ec915ad74 100644

testcases/lib/tst_net.sh tst_rhost_run() · line 208

Quoted 4 lines
testcases/lib/tst_net.sh +1 -0
@@ -205,6 +205,7 @@ tst_rhost_run()
 	sh_cmd="$pre_cmd $cmd $post_cmd"
 
 	if [ -n "${TST_USE_NETNS:-}" ]; then
+		tst_require_cmds ip ns_create ns_exec ns_ifmove

Why this? none of these commands is used here.

testcases/lib/tst_net.sh IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}" · line 1010

Quoted 8 lines
testcases/lib/tst_net.sh +1 -0
 		use="NETNS"
 		rcmd="$LTP_NETNS sh -c"
 	else
@@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
 # tst_net_iface_prefix -h
 # tst_net_vars -h
 if [ -z "$_tst_net_parse_variables" ]; then
+	tst_require_cmds tst_net_ip_prefix

This is correct.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 18 lines · Petr Vorel

Hi Wei,

Quoted 15 lines

More strict check for ns_xxx etc will help avoid following issue:
https://github.com/linux-test-project/ltp/issues/991

---
 testcases/lib/tst_net.sh | 2 ++
 1 file changed, 2 insertions(+)
testcases/lib/tst_net.sh +0 -0
index ceb45c98d..ec915ad74 100644
@@ -205,6 +205,7 @@ tst_rhost_run()
 	sh_cmd="$pre_cmd $cmd $post_cmd"
Quoted 3 lines

testcases/lib/tst_net.sh tst_rhost_run() · line 208

Quoted 2 lines
testcases/lib/tst_net.sh +1 -0
 	if [ -n "${TST_USE_NETNS:-}" ]; then
+		tst_require_cmds ip ns_create ns_exec ns_ifmove

Why this? none of these commands is used here.

This line is the key to avoid wrong configuration(such as add ip inteface etc..) continue even ns_xxx not exist, you can check following code, line 222 will execute ns_xxx with error but not exit test immediately, so if we add require_cmds here then we can avoid it. (line 222 $rcmd will contain command ns_xxx)

218 tst_res_ TINFO "tst_rhost_run: cmd: $cmd"
219 tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out 2>&1"
220 fi
221
222 output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
223
224 echo "$output" | grep -q 'RTERR$' && ret=1
225 if [ $ret -eq 1 ]; then

Quoted 13 lines

testcases/lib/tst_net.sh IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}" · line 1010

Quoted 9 lines
testcases/lib/tst_net.sh +1 -0
 		use="NETNS"
 		rcmd="$LTP_NETNS sh -c"
 	else
@@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
 # tst_net_iface_prefix -h
 # tst_net_vars -h
 if [ -z "$_tst_net_parse_variables" ]; then
+	tst_require_cmds tst_net_ip_prefix

This is correct.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 26 lines · Petr Vorel
Quoted 18 lines

Hi Wei,

Quoted 15 lines

More strict check for ns_xxx etc will help avoid following issue:
https://github.com/linux-test-project/ltp/issues/991

---
 testcases/lib/tst_net.sh | 2 ++
 1 file changed, 2 insertions(+)
testcases/lib/tst_net.sh +0 -0
index ceb45c98d..ec915ad74 100644
@@ -205,6 +205,7 @@ tst_rhost_run()
 	sh_cmd="$pre_cmd $cmd $post_cmd"
Quoted 3 lines

testcases/lib/tst_net.sh tst_rhost_run() · line 208

Quoted 2 lines
testcases/lib/tst_net.sh +1 -0
 	if [ -n "${TST_USE_NETNS:-}" ]; then
+		tst_require_cmds ip ns_create ns_exec ns_ifmove

Why this? none of these commands is used here.

This line is the key to avoid wrong configuration(such as add ip inteface etc..) continue even ns_xxx not exist, you can check following code, line 222 will execute ns_xxx with error but not exit test immediately, so if we add require_cmds here then we can avoid it. (line 222 $rcmd will contain command ns_xxx)

Quoted 8 lines

218 tst_res_ TINFO "tst_rhost_run: cmd: $cmd"
219 tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out 2>&1"
220 fi
221
222 output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
223
224 echo "$output" | grep -q 'RTERR$' && ret=1
225 if [ $ret -eq 1 ]; then

Long time ago the first run code for netns was init_ltp_netspace. I added IPv6 check quite recently. (I originally submitted it as run after, but in the end it is run before it.)
I need to have a deeper look how tst_net_detect_ipv6 rhost works, calling tst_rhost_run before init_ltp_netspace should not work (interfaces aren't configured yet).

But even if "ip ns_create ns_exec ns_ifmove" are needed to be checked to fix tst_rhost_run (not yet convinced), why to check them each time tst_rhost_run is called? It should be checked before first tst_rhost_run call to avoid useless repeating.

Kind regards,
Petr

Quoted 12 lines
Quoted 12 lines

testcases/lib/tst_net.sh IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}" · line 1010

Quoted 8 lines
testcases/lib/tst_net.sh +1 -0
 		use="NETNS"
 		rcmd="$LTP_NETNS sh -c"
 	else
@@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
 # tst_net_iface_prefix -h
 # tst_net_vars -h
 if [ -z "$_tst_net_parse_variables" ]; then
+	tst_require_cmds tst_net_ip_prefix

This is correct.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 42 lines · Petr Vorel
Quoted 26 lines · Petr Vorel
Quoted 18 lines

Hi Wei,

Quoted 15 lines

More strict check for ns_xxx etc will help avoid following issue:
https://github.com/linux-test-project/ltp/issues/991

---
 testcases/lib/tst_net.sh | 2 ++
 1 file changed, 2 insertions(+)
testcases/lib/tst_net.sh +0 -0
index ceb45c98d..ec915ad74 100644
@@ -205,6 +205,7 @@ tst_rhost_run()
 	sh_cmd="$pre_cmd $cmd $post_cmd"
Quoted 3 lines

testcases/lib/tst_net.sh tst_rhost_run() · line 208

Quoted 2 lines
testcases/lib/tst_net.sh +1 -0
 	if [ -n "${TST_USE_NETNS:-}" ]; then
+		tst_require_cmds ip ns_create ns_exec ns_ifmove

Why this? none of these commands is used here.

This line is the key to avoid wrong configuration(such as add ip inteface etc..) continue even ns_xxx not exist, you can check following code, line 222 will execute ns_xxx with error but not exit test immediately, so if we add require_cmds here then we can avoid it. (line 222 $rcmd will contain command ns_xxx)

Quoted 8 lines

218 tst_res_ TINFO "tst_rhost_run: cmd: $cmd"
219 tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out 2>&1"
220 fi
221
222 output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
223
224 echo "$output" | grep -q 'RTERR$' && ret=1
225 if [ $ret -eq 1 ]; then

Long time ago the first run code for netns was init_ltp_netspace. I added IPv6 check quite recently. (I originally submitted it as run after, but in the end it is run before it.)
I need to have a deeper look how tst_net_detect_ipv6 rhost works, calling tst_rhost_run before init_ltp_netspace should not work (interfaces aren't configured yet).

Quoted 4 lines

But even if "ip ns_create ns_exec ns_ifmove" are needed to be checked to fix tst_rhost_run (not yet convinced), why to check them each time tst_rhost_run is called? It should be checked before first tst_rhost_run call to avoid useless repeating.

tst_rhost_run already be called everywhere so if you need check before call tst_rhost_run, means lot of place/cases maybe need review and update.

Furthermore, check each time in tst_rhost_run can make this function more robust, the old code also do tst_require_cmds if go ssh logic in line 211 for example.

205 sh_cmd="$pre_cmd $cmd $post_cmd"
206
207 if [ -n "${TST_USE_NETNS:-}" ]; then
208 use="NETNS"
209 rcmd="$LTP_NETNS sh -c"
210 else

 211                 tst_require_cmds ssh
 212                 use="SSH"
 213                 rcmd="ssh -nq $user@$RHOST"

214 fi

Quoted 16 lines

Kind regards,
Petr

Quoted 12 lines
Quoted 12 lines

testcases/lib/tst_net.sh IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}" · line 1010

Quoted 8 lines
testcases/lib/tst_net.sh +1 -0
 		use="NETNS"
 		rcmd="$LTP_NETNS sh -c"
 	else
@@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
 # tst_net_iface_prefix -h
 # tst_net_vars -h
 if [ -z "$_tst_net_parse_variables" ]; then
+	tst_require_cmds tst_net_ip_prefix

This is correct.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi Wei,

...

Quoted 7 lines
Quoted 4 lines

But even if "ip ns_create ns_exec ns_ifmove" are needed to be checked to fix tst_rhost_run (not yet convinced), why to check them each time tst_rhost_run is called? It should be checked before first tst_rhost_run call to avoid useless repeating.

tst_rhost_run already be called everywhere so if you need check before call tst_rhost_run, means lot of place/cases maybe need review and update.

No, the check would be on single place at tst_net.sh.

Quoted 2 lines

Furthermore, check each time in tst_rhost_run can make this function more robust, the old code also do tst_require_cmds if go ssh logic in line 211 for example.

Well, repeated check for ssh is not ideal either (how likely is that ssh will disappear during testing?), but it's a single command which is used here. And it's definitely less awkward than checking "ip ns_create ns_exec ns_ifmove" which aren't used there. tst_net.sh needs cleanup, not more unneeded code.

We could document the reason to make this check more obvious, but the code is wrong, because for netns (the default) running "tst_net_detect_ipv6 rhost" before init_ltp_netspace does not make sense, because interfaces aren't defined (probably error code is not detected, I need to recheck that).

It's actually enough for netns to test IPv6 support only on localhost (it will be the same on rhost), I'll send a patch to fix that.

Kind regards,
Petr

Quoted 10 lines

205 sh_cmd="$pre_cmd $cmd $post_cmd"
206
207 if [ -n "${TST_USE_NETNS:-}" ]; then
208 use="NETNS"
209 rcmd="$LTP_NETNS sh -c"
210 else

 211                 tst_require_cmds ssh
 212                 use="SSH"
 213                 rcmd="ssh -nq $user@$RHOST"

214 fi

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi Wei,

Quoted 19 lines

...

Quoted 7 lines
Quoted 4 lines

But even if "ip ns_create ns_exec ns_ifmove" are needed to be checked to fix tst_rhost_run (not yet convinced), why to check them each time tst_rhost_run is called? It should be checked before first tst_rhost_run call to avoid useless repeating.

tst_rhost_run already be called everywhere so if you need check before call tst_rhost_run, means lot of place/cases maybe need review and update.

No, the check would be on single place at tst_net.sh.

Quoted 2 lines

Furthermore, check each time in tst_rhost_run can make this function more robust, the old code also do tst_require_cmds if go ssh logic in line 211 for example.

Well, repeated check for ssh is not ideal either (how likely is that ssh will disappear during testing?), but it's a single command which is used here. And it's definitely less awkward than checking "ip ns_create ns_exec ns_ifmove" which aren't used there. tst_net.sh needs cleanup, not more unneeded code.

Quoted 7 lines

We could document the reason to make this check more obvious, but the code is wrong, because for netns (the default) running "tst_net_detect_ipv6 rhost" before init_ltp_netspace does not make sense, because interfaces aren't defined (probably error code is not detected, I need to recheck that).

It's actually enough for netns to test IPv6 support only on localhost (it will be the same on rhost), I'll send a patch to fix that.

I'm sorry, I was wrong. tst_net_detect_ipv6() checks [ -f /proc/net/if_inet6 ], which is ok even before interfaces are set. It's a question whether this needs to be run on netns also on rhost (IMHO the result will be always the same). We should investigate that.

FYI I changed your patch to use just check in $_tst_net_parse_variables and put it into larger cleanup. I haven't addressed move tools to testcases/lib/ yet, nor the case when tools are missing. Instead I fixed few real problems with IPv6 disabled and did cleanup.

https://lore.kernel.org/ltp/[email protected]/
https://patchwork.ozlabs.org/project/ltp/list/?series=338700&state=*

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp