From 48650b89762fc34d77ca37a26fe81495273abfc3 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Sat, 31 Aug 2024 20:00:52 -0400 Subject: [PATCH 1/2] Make a Merge() call allow not-yet-recognized new fields in P4Info files This is helpful when p4c adds new P4Info fields to the P4Info files it generates, but the consumers have not yet all been updated to recognize them. The most recent example of this in 2024-Aug is the initial_default_action field of Table messages. Signed-off-by: Andy Fingerhut --- p4runtime_sh/p4runtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p4runtime_sh/p4runtime.py b/p4runtime_sh/p4runtime.py index f858f92..85ef344 100644 --- a/p4runtime_sh/p4runtime.py +++ b/p4runtime_sh/p4runtime.py @@ -289,7 +289,7 @@ def set_fwd_pipe_config(self, p4info_path, bin_path): with open(p4info_path, 'r') as f1: with open(bin_path, 'rb') as f2: try: - google.protobuf.text_format.Merge(f1.read(), req.config.p4info) + google.protobuf.text_format.Merge(f1.read(), req.config.p4info, allow_unknown_field=True) except google.protobuf.text_format.ParseError: logging.error("Error when parsing P4Info") raise From e0a803f52cdb4f1d7cfe0aeeef710db3788f259d Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Sat, 31 Aug 2024 20:06:42 -0400 Subject: [PATCH 2/2] Fix Python lint warning Signed-off-by: Andy Fingerhut --- p4runtime_sh/p4runtime.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/p4runtime_sh/p4runtime.py b/p4runtime_sh/p4runtime.py index 85ef344..5bd0302 100644 --- a/p4runtime_sh/p4runtime.py +++ b/p4runtime_sh/p4runtime.py @@ -289,7 +289,8 @@ def set_fwd_pipe_config(self, p4info_path, bin_path): with open(p4info_path, 'r') as f1: with open(bin_path, 'rb') as f2: try: - google.protobuf.text_format.Merge(f1.read(), req.config.p4info, allow_unknown_field=True) + google.protobuf.text_format.Merge(f1.read(), req.config.p4info, + allow_unknown_field=True) except google.protobuf.text_format.ParseError: logging.error("Error when parsing P4Info") raise