[Why] In physical machine, there will be a delay between the start of network card and the availability of the network.
So we add a test ping condition to network_ok.
Signed-off-by: Yu Chuan 13186087857@163.com --- lib/bootstrap.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/bootstrap.sh b/lib/bootstrap.sh index 06aa09bf65b2..38965ff60755 100755 --- a/lib/bootstrap.sh +++ b/lib/bootstrap.sh @@ -85,14 +85,19 @@ net_devices_link() done }
+test_ping() +{ + ping -c 1 -W 1 $LKP_SERVER > /dev/null || return 1 +} + network_ok() { local i for i in /sys/class/net/*/ do [ "${i#*/lo/}" != "$i" ] && continue - [ "$(cat $i/operstate)" = 'up' ] && return 0 - [ "$(cat $i/carrier 2>/dev/null)" = '1' ] && return 0 + [ "$(cat $i/operstate)" = 'up' ] && test_ping && return 0 + [ "$(cat $i/carrier 2>/dev/null)" = '1' ] && test_ping && return 0 done
is_clearlinux && {
On Mon, Feb 08, 2021 at 05:47:50PM +0800, Yu Chuan wrote:
[Why] In physical machine, there will be a delay between the start of network card and the availability of the network.
So we add a test ping condition to network_ok.
Signed-off-by: Yu Chuan 13186087857@163.com
lib/bootstrap.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/bootstrap.sh b/lib/bootstrap.sh index 06aa09bf65b2..38965ff60755 100755 --- a/lib/bootstrap.sh +++ b/lib/bootstrap.sh @@ -85,14 +85,19 @@ net_devices_link() done }
+test_ping() +{
- ping -c 1 -W 1 $LKP_SERVER > /dev/null || return 1
This looks not necessary:
|| return 1
-w seems somehow better than -W, since the man page explicitly discussed it:
If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. => This makes it possible to use the exit code to see if a host is => alive or not.
Thanks, Fengguang
+}
network_ok() { local i for i in /sys/class/net/*/ do [ "${i#*/lo/}" != "$i" ] && continue
[ "$(cat $i/operstate)" = 'up' ] && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && return 0
[ "$(cat $i/operstate)" = 'up' ] && test_ping && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && test_ping && return 0
done
is_clearlinux && {
-- 2.23.0
+test_ping() +{
- ping -c 1 -W 1 $LKP_SERVER > /dev/null || return 1
This looks not necessary:
|| return 1
-w seems somehow better than -W, since the man page explicitly discussed it:
If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0.
=> This makes it possible to use the exit code to see if a host is => alive or not.
1. Nice, i'll delete 'return 1'.
2. about -w and -W. -w <deadline> reply wait <deadline> in seconds -W <timeout> time to wait for response
here is my test result: -w deadline: is the time limit for the ping cmd, not for one ping response. -W timeout: is the timeout for each response.
yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -w 3 baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=50 time=33.7 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=50 time=32.6 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=50 time=32.4 ms
--- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 32.407/32.892/33.652/0.543 ms yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -W 3 baidu.com PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=49 time=30.5 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=49 time=39.4 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=49 time=35.2 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=49 time=29.9 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=8 ttl=49 time=37.3 ms ^C --- baidu.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7010ms rtt min/avg/max/mdev = 29.659/32.678/39.436/3.756 ms
So in the code, we need test whether only one ping is ok, '-w' looks more appropriate?
-------- Thanks Yu Chuan
Thanks, Fengguang
+}
network_ok() { local i for i in /sys/class/net/*/ do [ "${i#*/lo/}" != "$i" ] && continue
[ "$(cat $i/operstate)" = 'up' ] && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && return 0
[ "$(cat $i/operstate)" = 'up' ] && test_ping && return 0
[ "$(cat $i/carrier 2>/dev/null)" = '1' ] && test_ping && return 0
done
is_clearlinux && {
-- 2.23.0
- about -w and -W.
-w <deadline> reply wait <deadline> in seconds -W <timeout> time to wait for response
here is my test result: -w deadline: is the time limit for the ping cmd, not for one ping response. -W timeout: is the timeout for each response.
yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -w 3 baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=50 time=33.7 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=50 time=32.6 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=50 time=32.4 ms
--- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 32.407/32.892/33.652/0.543 ms yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -W 3 baidu.com PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=49 time=30.5 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=49 time=39.4 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=49 time=35.2 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=49 time=29.9 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=8 ttl=49 time=37.3 ms ^C --- baidu.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7010ms rtt min/avg/max/mdev = 29.659/32.678/39.436/3.756 ms
So in the code, we need test whether only one ping is ok, '-w' looks more appropriate?
Yes, looks so.
Thanks, Fengguang
On Fri, Feb 19, 2021 at 09:59:19AM +0800, Wu Fengguang wrote:
- about -w and -W.
-w <deadline> reply wait <deadline> in seconds -W <timeout> time to wait for response
here is my test result: -w deadline: is the time limit for the ping cmd, not for one ping response. -W timeout: is the timeout for each response.
yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -w 3 baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=50 time=33.7 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=50 time=32.6 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=50 time=32.4 ms
--- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 32.407/32.892/33.652/0.543 ms yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -W 3 baidu.com PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=49 time=30.5 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=49 time=39.4 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=49 time=35.2 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=49 time=29.9 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=8 ttl=49 time=37.3 ms ^C --- baidu.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7010ms rtt min/avg/max/mdev = 29.659/32.678/39.436/3.756 ms
So in the code, we need test whether only one ping is ok, '-w' looks more appropriate?
my mistake, i mean '-W(timeout)' is more appropriate?
Yes, looks so.
Thanks, Fengguang
On Fri, Feb 19, 2021 at 10:13:16AM +0800, Yu Chuan wrote:
On Fri, Feb 19, 2021 at 09:59:19AM +0800, Wu Fengguang wrote:
- about -w and -W.
-w <deadline> reply wait <deadline> in seconds -W <timeout> time to wait for response
here is my test result: -w deadline: is the time limit for the ping cmd, not for one ping response. -W timeout: is the timeout for each response.
yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -w 3 baidu.com PING baidu.com (220.181.38.148) 56(84) bytes of data. 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=50 time=33.7 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=50 time=32.6 ms 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=50 time=32.4 ms
--- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 32.407/32.892/33.652/0.543 ms yuchuan@crystal ~/todo/deploy/YuChuan/daily% ping -W 3 baidu.com PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=49 time=30.5 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=49 time=39.4 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=49 time=35.2 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=6 ttl=49 time=29.9 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=49 time=29.7 ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=8 ttl=49 time=37.3 ms ^C --- baidu.com ping statistics --- 8 packets transmitted, 8 received, 0% packet loss, time 7010ms rtt min/avg/max/mdev = 29.659/32.678/39.436/3.756 ms
So in the code, we need test whether only one ping is ok, '-w' looks more appropriate?
my mistake, i mean '-W(timeout)' is more appropriate?
我们代码已经用ping -c1了,主要是为了等待。 不需要那么多ping包。
你有看到关于-W与exit code的关系吗? 反正man page里只描述了-w情况下的exit code.
Thanks, Fengguang
我们代码已经用ping -c1了,主要是为了等待。 不需要那么多ping包。
你有看到关于-W与exit code的关系吗? 反正man page里只描述了-w情况下的exit code.
looks they have the same result.
test -w: [root@d63bac6cf0b3 /]# ping -c 1 -w 1 114.114.114.114 > /dev/null; echo $? 0 [root@d63bac6cf0b3 /]# ping -c 1 -w 1 1.2.3.4 > /dev/null; echo $? 1 [root@d63bac6cf0b3 /]# ping -c 1 -w 1 baidu.com > /dev/null; echo $? ping: baidu.com: Name or service not known 2
test -W [root@d63bac6cf0b3 /]# ping -c 1 -W 1 114.114.114.114 > /dev/null; echo $? 0 [root@d63bac6cf0b3 /]# ping -c 1 -W 1 1.2.3.4 > /dev/null; echo $? 1 [root@d63bac6cf0b3 /]# ping -c 1 -W 1 baidu.com > /dev/null; echo $? ping: baidu.com: Name or service not known 2
我们代码已经用ping -c1了,主要是为了等待。 不需要那么多ping包。
understood it, -w(deadline) is certainly more appropriate than -W(timeout). :)
-------- Thanks Yu Chuan
Thanks, Fengguang
On Fri, Feb 19, 2021 at 02:44:18PM +0800, Yu Chuan wrote:
我们代码已经用ping -c1了,主要是为了等待。 不需要那么多ping包。
你有看到关于-W与exit code的关系吗? 反正man page里只描述了-w情况下的exit code.
looks they have the same result.
是的,这个我也试过。 不过文档上讲过的东西,会比较有保障。其它的程序行为,本质上属于“未定义”,属于"happen to be so"。
test -w: [root@d63bac6cf0b3 /]# ping -c 1 -w 1 114.114.114.114 > /dev/null; echo $? 0 [root@d63bac6cf0b3 /]# ping -c 1 -w 1 1.2.3.4 > /dev/null; echo $? 1 [root@d63bac6cf0b3 /]# ping -c 1 -w 1 baidu.com > /dev/null; echo $? ping: baidu.com: Name or service not known 2
test -W [root@d63bac6cf0b3 /]# ping -c 1 -W 1 114.114.114.114 > /dev/null; echo $? 0 [root@d63bac6cf0b3 /]# ping -c 1 -W 1 1.2.3.4 > /dev/null; echo $? 1 [root@d63bac6cf0b3 /]# ping -c 1 -W 1 baidu.com > /dev/null; echo $? ping: baidu.com: Name or service not known 2
我们代码已经用ping -c1了,主要是为了等待。 不需要那么多ping包。
understood it, -w(deadline) is certainly more appropriate than -W(timeout). :)
Thanks, Fengguang