diff mbox series

[ovs-dev,v3,3/8] python: ovs: flow: Add sample to nested actions.

Message ID 20240105114702.443465-4-amorenoz@redhat.com
State Changes Requested
Delegated to: Simon Horman
Headers show
Series python: Miscelaneous flow parsing fixes. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Adrian Moreno Jan. 5, 2024, 11:46 a.m. UTC
Add the sample action to those that can be called in nested actions
(such as clone).

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 python/ovs/flow/odp.py       | 29 +++++++++++++++--------------
 python/ovs/tests/test_ofp.py | 14 ++++++++++++++
 2 files changed, 29 insertions(+), 14 deletions(-)

Comments

Simon Horman Jan. 5, 2024, 3:19 p.m. UTC | #1
On Fri, Jan 05, 2024 at 12:46:55PM +0100, Adrian Moreno wrote:
> Add the sample action to those that can be called in nested actions
> (such as clone).
> 
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>

Acked-by: Simon Horman <horms@ovn.org>
diff mbox series

Patch

diff --git a/python/ovs/flow/odp.py b/python/ovs/flow/odp.py
index 88aee17fb..ef7e5d6b8 100644
--- a/python/ovs/flow/odp.py
+++ b/python/ovs/flow/odp.py
@@ -336,6 +336,21 @@  class ODPFlow(Flow):
             **ODPFlow._tnl_action_decoder_args(),
         }
 
+        _decoders["sample"] = nested_kv_decoder(
+            KVDecoders(
+                {
+                    "sample": (lambda x: float(x.strip("%"))),
+                    "actions": nested_kv_decoder(
+                        KVDecoders(
+                            decoders=_decoders,
+                            default_free=decode_free_output,
+                        ),
+                        is_list=True,
+                    ),
+                }
+            )
+        )
+
         _decoders["clone"] = nested_kv_decoder(
             KVDecoders(decoders=_decoders, default_free=decode_free_output),
             is_list=True,
@@ -343,20 +358,6 @@  class ODPFlow(Flow):
 
         return {
             **_decoders,
-            "sample": nested_kv_decoder(
-                KVDecoders(
-                    {
-                        "sample": (lambda x: float(x.strip("%"))),
-                        "actions": nested_kv_decoder(
-                            KVDecoders(
-                                decoders=_decoders,
-                                default_free=decode_free_output,
-                            ),
-                            is_list=True,
-                        ),
-                    }
-                )
-            ),
             "check_pkt_len": nested_kv_decoder(
                 KVDecoders(
                     {
diff --git a/python/ovs/tests/test_ofp.py b/python/ovs/tests/test_ofp.py
index 5d2736ab4..9e2721acf 100644
--- a/python/ovs/tests/test_ofp.py
+++ b/python/ovs/tests/test_ofp.py
@@ -569,6 +569,20 @@  def do_test_section(input_string, section, expected):
                 ),
             ],
         ),
+        (
+            "actions=LOCAL,clone(sample(probability=123))",
+            [
+                KeyValue("output", {"port": "LOCAL"}),
+                KeyValue(
+                    "clone",
+                    [
+                        {"sample": {
+                            "probability": 123,
+                        }},
+                    ]
+                ),
+            ],
+        ),
         (
             "actions=doesnotexist(1234)",
             ParseError,