[PATCH net-next] tools: ynl-gen: fix parse multi-attr enum attribute

From: Arkadiusz Kubalewski
Date: Tue Jul 11 2023 - 05:56:01 EST


When attribute is enum type and marked as multi-attr, the netlink respond
is not parsed, fails with stack trace:
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 600, in dump
return self._op(method, vals, dump=True)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 586, in _op
rsp_msg = self._decode(gm.raw_attrs, op.attr_set.name)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 453, in _decode
self._decode_enum(rsp, attr_spec)
File "/root/arek/linux-dpll/tools/net/ynl/lib/ynl.py", line 410, in _decode_enum
value = enum.entries_by_val[raw - i].name
TypeError: unsupported operand type(s) for -: 'list' and 'int'
error: 1

Allow succesfull parse of multi-attr enums by decoding and assigning their
names into response in the _decode_enum(..) function.

Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@xxxxxxxxx>
---
tools/net/ynl/lib/ynl.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 3b343d6cbbc0..553d82dd6382 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -407,7 +407,14 @@ class YnlFamily(SpecFamily):
raw >>= 1
i += 1
else:
- value = enum.entries_by_val[raw - i].name
+ if attr_spec.is_multi:
+ for index in range(len(raw)):
+ if (type(raw[index]) == int):
+ enum_name = enum.entries_by_val[raw[index] - i].name
+ rsp[attr_spec['name']][index] = enum_name
+ return
+ else:
+ value = enum.entries_by_val[raw - i].name
rsp[attr_spec['name']] = value

def _decode_binary(self, attr, attr_spec):
--
2.37.3