Merge ~rodsmith/plainbox-provider-certification-server:fix-precheck-script-multiple-subnets into plainbox-provider-certification-server:master

Proposed by Rod Smith
Status: Merged
Approved by: Rod Smith
Approved revision: e300544bbd326e1e1c4beedc71a27f113cf67cac
Merged at revision: 4d7d5bf72ef54522ac9efee76e49fc6a2fc99ee2
Proposed branch: ~rodsmith/plainbox-provider-certification-server:fix-precheck-script-multiple-subnets
Merge into: plainbox-provider-certification-server:master
Diff against target: 139 lines (+73/-17)
2 files modified
tools/canonical-certification-precheck (+68/-17)
units/packaging.pxu (+5/-0)
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Review via email: mp+381318@code.launchpad.net

Commit message

Improve precheck script handling of multi-network configurations

Description of the change

This MR holds two interrelated changes to the canonical-certification-precheck script:

* A failure of the Network_Subnets check is demoted from a failure
  to a warning.
* The Iperf check is expanded to verify that there's an iperf3 server
  accessible on every subnet to which the SUT connects.

The second is, by far, the biggest change. In principle, the Network_Subnets check is no longer needed; however, I've left it because I thought it might be useful to warn users about this should the Iperf check fail -- if a user has accidentally misconfigured a NIC, it would likely fail the Iperf test, and the warning about the Network_Subnets problem issued in the summary would then help the user track down the cause of the Iperf failure. I'm not wedded to this, though; if desired, the Network_Subnets check could instead be completely eliminated.

To post a comment you must log in.
Revision history for this message
Rod Smith (rodsmith) wrote :

Oh, BTW, I've tested this on three SUTs, one connected to a single network and two connected to two networks each. In both cases, I tried with iperf3 servers accessible on all networks and with one network missing an iperf3 server. It worked as expected in all cases.

Revision history for this message
Jeff Lane  (bladernr) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tools/canonical-certification-precheck b/tools/canonical-certification-precheck
2index 3f7c223..c333cc9 100755
3--- a/tools/canonical-certification-precheck
4+++ b/tools/canonical-certification-precheck
5@@ -528,16 +528,17 @@ Ubuntu_Version(){
6 fi
7 }
8
9+ALL_NICS=$(cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|egrep -v "lo|br.|tun.|usb.")
10
11 # All NICs are on the same network segment, to flag cabling, switch, or configuration errors (??)
12 Network_Subnets(){
13 name="Network Subnets"
14 echoname
15-check_bcast=$(for nic in `cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|egrep -v "lo|br.|tun.|usb."`
16+check_bcast=$(for nic in $ALL_NICS
17 do
18 ip addr show dev $nic | grep "inet "|awk '{print $4}'
19 done|uniq|wc -l)
20-for nic in `cat /proc/net/dev|grep ":"|awk -F: '{print $1}'|egrep -v "lo|br.|tun.|usb."`
21+for nic in $ALL_NICS
22 do
23 echo " $nic - $(ip addr show dev $nic | grep "inet "|awk '{print $2, $4}')"
24 done
25@@ -547,11 +548,27 @@ if [ $check_bcast = 1 ]; then
26 echo " All interfaces seem to be on the same subnet"
27 else
28 echo " One or more interfaces are on separate subnets"
29- fail
30+ eval info${i}=\"Multiple subnets detected\"
31+ warn
32 fi
33
34 }
35
36+# Find the network associated with the specified IP address.
37+# Returns network (in network/width form, as in 10.1.10.0/23)
38+# in the "network" variable, or empty variable if address
39+# requires routing.
40+find_network() {
41+# $1 = IP address
42+network=""
43+# routable = 'via' if routed, 'dev' if local
44+local routable=$(ip route get $1 | awk '{print $2}')
45+if [ $routable == 'dev' ]; then
46+ local nic=$(ip route get $1 | awk '{print $3}')
47+ network=$(ipcalc $(ip addr show dev $nic | grep "inet " | awk '{print $2}') -nb | grep "Network" | awk '{print $2}')
48+fi
49+}
50+
51 # Check if iperf3 is available on server specified in /etc/xdg/canonical-certification.conf
52 IPERF(){
53 name="Iperf"
54@@ -570,24 +587,58 @@ elif [ $(grep ^TEST_TARGET_IPERF /etc/xdg/canonical-certification.conf|wc -l) =
55 fail
56 fi
57 fi
58-local iperf3found=0
59+
60+# Create a list of all local networks (identified by address/width, as in 10.1.10.0/23)
61+for nic in $ALL_NICS; do
62+ local nic_addr=$(ip addr show dev $nic | grep "inet " | awk '{print $2}')
63+ if [[ $nic_addr != "" ]]; then
64+ this_network=$(ipcalc $nic_addr -nb | grep "Network" | awk '{print $2}')
65+ found=0
66+ for net in ${all_networks[@]}; do
67+ if [ $net == $this_network ]; then
68+ found=1;
69+ fi
70+ done
71+ if [ $found == 0 ]; then
72+ all_networks+=( $this_network )
73+ fi
74+ fi
75+done
76+
77+# Report on presence of individual configured iperf3 servers....
78 for iperfserver in $(grep ^TEST_TARGET_IPERF /etc/xdg/canonical-certification.conf | cut -d = -f 2 | sed s/,/\\n/g)
79- do
80- timeout 5 iperf3 -c $iperfserver -n 1 >/dev/null 2>&1
81- if [ $? = 0 ]; then
82- echo " Iperf3 server found on port 5201 on $iperfserver"
83- iperf3found=1
84- else
85- echo " No Iperf3 server found on $iperfserver"
86- fi
87+ do
88+ timeout 5 iperf3 -c $iperfserver -n 1 >/dev/null 2>&1
89+ if [ $? = 0 ]; then
90+ echo " Iperf3 server found on port 5201 on $iperfserver"
91+ find_network $iperfserver
92+ all_networks=( "${all_networks[@]/$network}" )
93+ else
94+ echo " No Iperf3 server found on $iperfserver"
95+ fi
96 done
97-if [[ $iperf3found == 0 ]]; then
98- echo " No iperf3 server found"
99- fail
100+
101+# Count number of networks without an iperf3 server.
102+# Note: ${#all_networks[@]} SHOULD have this, but seems to be thrown
103+# off by removing elements earlier.
104+local num_nets_left=0
105+for net in ${all_networks[@]}; do
106+ let num_nets_left=num_nets_left+1
107+done
108+
109+if [[ $num_nets_left -gt 0 ]]; then
110+ echo ""
111+ echo " Networks without iperf3 servers:"
112+ for net in ${all_networks[@]}; do
113+ echo " $net"
114+ done
115+ fail
116 else
117- pass
118+ echo ""
119+ echo " iperf3 server(s) found on all network(s)."
120+ pass
121 fi
122-}
123+} # IPERF()
124
125 # Check that jumbo frames are enabled on all >10Gbps NICs
126 Jumbo_Frames(){
127diff --git a/units/packaging.pxu b/units/packaging.pxu
128index 67eb35f..347b964 100644
129--- a/units/packaging.pxu
130+++ b/units/packaging.pxu
131@@ -12,3 +12,8 @@ Depends: numactl
132 unit: packaging meta-data
133 os-id: debian
134 Depends: bc
135+
136+# The canonical-certification-precheck tool requires ipcalc
137+unit: packaging meta-data
138+os-id: debian
139+Depends: ipcalc

Subscribers

People subscribed via source and target branches

to all changes: