Skip to content

Commit 883f0dc

Browse files
committed
Merge branch 'ovs-selftests'
From: Aaron Conole <aconole@redhat.com> To: netdev@vger.kernel.org Cc: dev@openvswitch.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Pravin B Shelar <pshelar@ovn.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Adrian Moreno <amorenoz@redhat.com>, Eelco Chaudron <echaudro@redhat.com>, shuah@kernel.org Subject: [PATCH net v2 0/4] selftests: openvswitch: Minor fixes for some systems Date: Wed, 11 Oct 2023 15:49:35 -0400 [thread overview] Message-ID: <20231011194939.704565-1-aconole@redhat.com> (raw) A number of corner cases were caught when trying to run the selftests on older systems. Missed skip conditions, some error cases, and outdated python setups would all report failures but the issue would actually be related to some other condition rather than the selftest suite. Address these individual cases. ==================== Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents fc8b2a6 + 8eff0e0 commit 883f0dc

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

tools/testing/selftests/net/openvswitch/openvswitch.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44
# OVS kernel module self tests
55

6+
trap ovs_exit_sig EXIT TERM INT ERR
7+
68
# Kselftest framework requirement - SKIP code is 4.
79
ksft_skip=4
810

@@ -142,6 +144,12 @@ ovs_add_flow () {
142144
return 0
143145
}
144146

147+
ovs_del_flows () {
148+
info "Deleting all flows from DP: sbx:$1 br:$2"
149+
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-flows "$2"
150+
return 0
151+
}
152+
145153
ovs_drop_record_and_run () {
146154
local sbx=$1
147155
shift
@@ -198,6 +206,17 @@ test_drop_reason() {
198206
ip netns exec server ip addr add 172.31.110.20/24 dev s1
199207
ip netns exec server ip link set s1 up
200208

209+
# Check if drop reasons can be sent
210+
ovs_add_flow "test_drop_reason" dropreason \
211+
'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(10)' 2>/dev/null
212+
if [ $? == 1 ]; then
213+
info "no support for drop reasons - skipping"
214+
ovs_exit_sig
215+
return $ksft_skip
216+
fi
217+
218+
ovs_del_flows "test_drop_reason" dropreason
219+
201220
# Allow ARP
202221
ovs_add_flow "test_drop_reason" dropreason \
203222
'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
@@ -525,7 +544,7 @@ run_test() {
525544
fi
526545

527546
if python3 ovs-dpctl.py -h 2>&1 | \
528-
grep "Need to install the python" >/dev/null 2>&1; then
547+
grep -E "Need to (install|upgrade) the python" >/dev/null 2>&1; then
529548
stdbuf -o0 printf "TEST: %-60s [PYLIB]\n" "${tdesc}"
530549
return $ksft_skip
531550
fi

tools/testing/selftests/net/openvswitch/ovs-dpctl.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
from pyroute2.netlink import nlmsg_atoms
2929
from pyroute2.netlink.exceptions import NetlinkError
3030
from pyroute2.netlink.generic import GenericNetlinkSocket
31+
import pyroute2
32+
3133
except ModuleNotFoundError:
32-
print("Need to install the python pyroute2 package.")
34+
print("Need to install the python pyroute2 package >= 0.6.")
3335
sys.exit(0)
3436

3537

@@ -1117,12 +1119,14 @@ class ovs_key_ct_tuple_ipv4(ovs_key_proto):
11171119
"src",
11181120
lambda x: str(ipaddress.IPv4Address(x)),
11191121
int,
1122+
convert_ipv4,
11201123
),
11211124
(
11221125
"dst",
11231126
"dst",
1124-
lambda x: str(ipaddress.IPv6Address(x)),
1127+
lambda x: str(ipaddress.IPv4Address(x)),
11251128
int,
1129+
convert_ipv4,
11261130
),
11271131
("tp_src", "tp_src", "%d", int),
11281132
("tp_dst", "tp_dst", "%d", int),
@@ -1904,6 +1908,32 @@ def add_flow(self, dpifindex, flowmsg):
19041908
raise ne
19051909
return reply
19061910

1911+
def del_flows(self, dpifindex):
1912+
"""
1913+
Send a del message to the kernel that will drop all flows.
1914+
1915+
dpifindex should be a valid datapath obtained by calling
1916+
into the OvsDatapath lookup
1917+
"""
1918+
1919+
flowmsg = OvsFlow.ovs_flow_msg()
1920+
flowmsg["cmd"] = OVS_FLOW_CMD_DEL
1921+
flowmsg["version"] = OVS_DATAPATH_VERSION
1922+
flowmsg["reserved"] = 0
1923+
flowmsg["dpifindex"] = dpifindex
1924+
1925+
try:
1926+
reply = self.nlm_request(
1927+
flowmsg,
1928+
msg_type=self.prid,
1929+
msg_flags=NLM_F_REQUEST | NLM_F_ACK,
1930+
)
1931+
reply = reply[0]
1932+
except NetlinkError as ne:
1933+
print(flowmsg)
1934+
raise ne
1935+
return reply
1936+
19071937
def dump(self, dpifindex, flowspec=None):
19081938
"""
19091939
Returns a list of messages containing flows.
@@ -1998,6 +2028,12 @@ def main(argv):
19982028
nlmsg_atoms.ovskey = ovskey
19992029
nlmsg_atoms.ovsactions = ovsactions
20002030

2031+
# version check for pyroute2
2032+
prverscheck = pyroute2.__version__.split(".")
2033+
if int(prverscheck[0]) == 0 and int(prverscheck[1]) < 6:
2034+
print("Need to upgrade the python pyroute2 package to >= 0.6.")
2035+
sys.exit(0)
2036+
20012037
parser = argparse.ArgumentParser()
20022038
parser.add_argument(
20032039
"-v",
@@ -2060,6 +2096,9 @@ def main(argv):
20602096
addflcmd.add_argument("flow", help="Flow specification")
20612097
addflcmd.add_argument("acts", help="Flow actions")
20622098

2099+
delfscmd = subparsers.add_parser("del-flows")
2100+
delfscmd.add_argument("flsbr", help="Datapath name")
2101+
20632102
args = parser.parse_args()
20642103

20652104
if args.verbose > 0:
@@ -2143,6 +2182,11 @@ def main(argv):
21432182
flow = OvsFlow.ovs_flow_msg()
21442183
flow.parse(args.flow, args.acts, rep["dpifindex"])
21452184
ovsflow.add_flow(rep["dpifindex"], flow)
2185+
elif hasattr(args, "flsbr"):
2186+
rep = ovsdp.info(args.flsbr, 0)
2187+
if rep is None:
2188+
print("DP '%s' not found." % args.flsbr)
2189+
ovsflow.del_flows(rep["dpifindex"])
21462190

21472191
return 0
21482192

0 commit comments

Comments
 (0)