From df41ce807f430a29a08607a2f4434a4505182f4f Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Mon, 11 Jul 2022 22:36:36 +0800 Subject: [PATCH] config_tools: resolve incompatibility with elementpath 2.5.3 This patch adds to the customized function `number-of-clos-id-needed` more robust checks, which ensures that a given node is a concrete element, before that function passes the node to `get_policy_list`. This resolves the incompatibility issue with elementpath 2.5.3 which is reported in v3.0. Tracked-On: #7893 Signed-off-by: Junjie Mao --- .../scenario_config/elementpath_overlay.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/misc/config_tools/scenario_config/elementpath_overlay.py b/misc/config_tools/scenario_config/elementpath_overlay.py index 3e7081896..3454d8146 100644 --- a/misc/config_tools/scenario_config/elementpath_overlay.py +++ b/misc/config_tools/scenario_config/elementpath_overlay.py @@ -96,10 +96,17 @@ def select_duplicate_values_function(self, context=None): @method(function('number-of-clos-id-needed', nargs=1)) def evaluate_number_of_clos_id_needed(self, context=None): op = self.get_argument(context, index=0) - try: - return len(rdt.get_policy_list(op.elem)) if op else 0 - except AttributeError as err: - raise self.error('XPTY0004', err) + if op is not None: + if isinstance(op, elementpath.TypedElement): + op = op.elem + + # This function may be invoked when the xmlschema library parses the data check schemas, in which case `op` will + # be an object of class Xsd11Element. Only attempt to calculate the needed CLOS IDs when a real acrn-config node + # is given. + if hasattr(op, "xpath"): + return len(rdt.get_policy_list(op)) + + return 0 ### # Collection of counter examples