diff mbox series

[ovs-dev,v4,12/17] tests: verify flows in odp.at are parseable

Message ID 20220616063247.517147-13-amorenoz@redhat.com
State Changes Requested
Headers show
Series python: add flow parsing library | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed

Commit Message

Adrian Moreno June 16, 2022, 6:32 a.m. UTC
Create a small helper script and check that flows tested in odp.at are
parseable.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 tests/automake.mk         |  2 ++
 tests/odp.at              | 11 ++++++++++
 tests/ovs-test-dpparse.py | 42 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100755 tests/ovs-test-dpparse.py

Comments

Eelco Chaudron June 27, 2022, 9:53 a.m. UTC | #1
On 16 Jun 2022, at 8:32, Adrian Moreno wrote:

> Create a small helper script and check that flows tested in odp.at are
> parseable.
>
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>

Changes look good.

Acked-by: Eelco Chaudron <echaudro@redhat.com>
diff mbox series

Patch

diff --git a/tests/automake.mk b/tests/automake.mk
index ab23f04ca..fcb1857b7 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -19,6 +19,7 @@  EXTRA_DIST += \
 	$(OVSDB_CLUSTER_TESTSUITE) \
 	tests/atlocal.in \
 	$(srcdir)/package.m4 \
+	$(srcdir)/tests/ovs-test-dpparse.py \
 	$(srcdir)/tests/ovs-test-ofparse.py \
 	$(srcdir)/tests/testsuite \
 	$(srcdir)/tests/testsuite.patch
@@ -526,6 +527,7 @@  CHECK_PYFILES = \
 	tests/flowgen.py \
 	tests/mfex_fuzzy.py \
 	tests/ovsdb-monitor-sort.py \
+	tests/ovs-test-dpparse.py \
 	tests/ovs-test-ofparse.py \
 	tests/test-daemon.py \
 	tests/test-json.py \
diff --git a/tests/odp.at b/tests/odp.at
index 4d08c59ca..abd22e04a 100644
--- a/tests/odp.at
+++ b/tests/odp.at
@@ -107,6 +107,7 @@  sed -i'back' 's/\(in_port(1)\),\(eth\)/\1,packet_type(ns=0,id=0),\2/' odp-out.tx
 
 AT_CHECK_UNQUOTED([ovstest test-odp parse-keys < odp-in.txt], [0], [`cat odp-out.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-out.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CLEANUP
 
 AT_SETUP([OVS datapath wildcarded key parsing and formatting - valid forms])
@@ -194,6 +195,7 @@  sed -n 's/,frag=no),.*/,frag=later)/p' odp-base.txt
 AT_CAPTURE_FILE([odp.txt])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-wc-keys < odp.txt], [0], [`cat odp.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CLEANUP
 
 AT_SETUP([OVS datapath wildcarded key filtering.])
@@ -241,24 +243,31 @@  in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv
 ])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='dl_type=0x1235' < odp-base.txt], [0], [`cat odp-eth-type.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-eth-type.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='dl_vlan=99' < odp-vlan-base.txt], [0], [`cat odp-vlan.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-vlan.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='dl_vlan=99,ip' < odp-vlan-base.txt], [0], [`cat odp-vlan.txt`
 ])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='ip,nw_src=35.8.2.199' < odp-base.txt], [0], [`cat odp-ipv4.txt`
 ])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='ip,nw_dst=172.16.0.199' < odp-base.txt], [0], [`cat odp-ipv4.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-ipv4.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='dl_type=0x0800,nw_src=35.8.2.199,nw_dst=172.16.0.199' < odp-base.txt], [0], [`cat odp-ipv4.txt`
 ])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='icmp,nw_src=35.8.2.199' < odp-base.txt], [0], [`cat odp-icmp.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-icmp.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='arp,arp_spa=1.2.3.5' < odp-base.txt], [0], [`cat odp-arp.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-arp.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='tcp,tp_src=90' < odp-base.txt], [0], [`cat odp-tcp.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-tcp.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CHECK_UNQUOTED([ovstest test-odp parse-filter filter='tcp6,tp_src=90' < odp-base.txt], [0], [`cat odp-tcp6.txt`
 ])
+AT_CHECK_UNQUOTED([cat odp-tcp6.txt | sed 's/^#.*//' | sed 's/$/ actions:drop/' | ovs-test-dpparse.py])
 AT_CLEANUP
 
 AT_SETUP([OVS datapath actions parsing and formatting - valid forms])
@@ -389,6 +398,7 @@  add_mpls(label=200,tc=7,ttl=64,bos=1,eth_type=0x8847)
 AT_CHECK_UNQUOTED([ovstest test-odp parse-actions < actions.txt], [0],
   [`cat actions.txt`
 ])
+AT_CHECK_UNQUOTED([cat actions.txt | sed 's/^/actions:/' | ovs-test-dpparse.py])
 AT_CLEANUP
 
 AT_SETUP([OVS datapath actions parsing and formatting - invalid forms])
@@ -434,6 +444,7 @@  odp_actions_from_string: error
 `cat actions.txt | head -3 | tail -1`
 odp_actions_from_string: error
 ])
+AT_CHECK_UNQUOTED([cat actions.txt | sed 's/^/actions:/' | ovs-test-dpparse.py])
 AT_CLEANUP
 
 AT_SETUP([OVS datapath actions parsing and formatting - actions too long])
diff --git a/tests/ovs-test-dpparse.py b/tests/ovs-test-dpparse.py
new file mode 100755
index 000000000..e9489a3c6
--- /dev/null
+++ b/tests/ovs-test-dpparse.py
@@ -0,0 +1,42 @@ 
+#!/usr/bin/env python3
+# Copyright (c) 2021 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""ovs-test-dpparse reads flows from stdin and tries to parse them using
+the python flow parsing library.
+"""
+
+import fileinput
+import sys
+
+from ovs.flow.odp import ODPFlow
+
+
+def main():
+    for flow in fileinput.input():
+        try:
+            result_flow = ODPFlow(flow)
+            if flow != str(result_flow):
+                print("in: {}".format(flow))
+                print("out: {}".format(str(result_flow)))
+                raise ValueError("Flow conversion back to string failed")
+        except Exception as e:
+            print(e)
+            return 1
+
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())