diff options
author | Adrian Moreno <amorenoz@redhat.com> | 2022-12-19 17:13:44 +0100 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2022-12-21 18:36:02 +0100 |
commit | fe204743cbc609dc5dfefd1437fc058b7ad3ca52 (patch) | |
tree | 31e75b3a7d0b7ea232d712b1d3fb860215b6433e /python/ovs/flow/kv.py | |
parent | 3648fec08f15b3f2cc37cd4b85eaccb773d1f444 (diff) | |
download | openvswitch-fe204743cbc609dc5dfefd1437fc058b7ad3ca52.tar.gz |
python: Add explicit decoders for all ofp actions.
We were silently relying on some ofp actions to be decoded by the
default decoder which would yield decent string values.
In order to be more safe and robust, add an explicit decoder for all
missing actions.
This patch also reworks the learn action decoding to make it more
explicit and verify all the fields specified in the learn action are
actually valid fields.
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'python/ovs/flow/kv.py')
-rw-r--r-- | python/ovs/flow/kv.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/python/ovs/flow/kv.py b/python/ovs/flow/kv.py index cceb95e43..383d7ee78 100644 --- a/python/ovs/flow/kv.py +++ b/python/ovs/flow/kv.py @@ -87,10 +87,11 @@ class KVDecoders(object): Args: decoders (dict): Optional; A dictionary of decoders indexed by keyword. - default (callable): Optional; A decoder used if a match is not found in - configured decoders. If not provided, the default behavior is to - try to decode the value into an integer and, if that fails, - just return the string as-is. + default (callable): Optional; A function to use if a match is not + found in configured decoders. If not provided, the default behavior + is to try to decode the value into an integer and, if that fails, + just return the string as-is. The function must accept a the key + and the value and return the decoded (key, value) tuple back. default_free (callable): Optional; The decoder used if a match is not found in configured decoders and it's a free value (e.g: a value without a key) Defaults to returning the free value as @@ -100,7 +101,7 @@ class KVDecoders(object): def __init__(self, decoders=None, default=None, default_free=None): self._decoders = decoders or dict() - self._default = default or decode_default + self._default = default or (lambda k, v: (k, decode_default(v))) self._default_free = default_free or self._default_free_decoder def decode(self, keyword, value_str): @@ -126,7 +127,7 @@ class KVDecoders(object): return keyword, value else: if value_str: - return keyword, self._default(value_str) + return self._default(keyword, value_str) else: return self._default_free(keyword) |