From 8d7a25a17fab7f0abb1c43bb729c9d094f307f0f Mon Sep 17 00:00:00 2001 From: Jordan Chen Date: Wed, 8 Jun 2022 09:05:27 +0000 Subject: [PATCH] Fix the conditional requirements on list property Signed-off-by: Jordan Chen --- common/interop.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/common/interop.py b/common/interop.py index aa235e6..5d3eb1e 100644 --- a/common/interop.py +++ b/common/interop.py @@ -342,6 +342,27 @@ def validatePropertyRequirement(propResourceObj, profile_entry, rf_payload_tuple else: my_logger.debug('propRequirement with value: ' + str(rf_payload_item if not isinstance( rf_payload_item, dict) else 'dict')) + + # Check the conditional requirements first or the requirements won't apply correctly against + # a list. + if "ConditionalRequirements" in profile_entry: + innerList = profile_entry["ConditionalRequirements"] + for item in innerList: + try: + if checkConditionalRequirement(propResourceObj, item, rf_payload_tuple): + my_logger.info("\tCondition DOES apply") + conditionalMsgs, conditionalCounts = validatePropertyRequirement( + propResourceObj, item, rf_payload_tuple, itemname, chkCondition = True) + counts.update(conditionalCounts) + for item in conditionalMsgs: + item.name = item.name.replace('.', '.Conditional.', 1) + msgs.extend(conditionalMsgs) + else: + my_logger.info("\tCondition does not apply") + except ValueError as e: + my_logger.info("\tCondition was skipped due to payload error") + counts['errorProfileComparisonError'] += 1 + # If we're working with a list, then consider MinCount, Comparisons, then execute on each item # list based comparisons include AnyOf and AllOf if isinstance(rf_payload_item, list): @@ -384,24 +405,6 @@ def validatePropertyRequirement(propResourceObj, profile_entry, rf_payload_tuple msg.name = itemname + '.' + msg.name if not success: my_logger.error("WriteRequirement failed") - if "ConditionalRequirements" in profile_entry: - innerList = profile_entry["ConditionalRequirements"] - for item in innerList: - try: - if checkConditionalRequirement(propResourceObj, item, rf_payload_tuple): - my_logger.info("\tCondition DOES apply") - conditionalMsgs, conditionalCounts = validatePropertyRequirement( - propResourceObj, item, rf_payload_tuple, itemname, chkCondition = True) - counts.update(conditionalCounts) - for item in conditionalMsgs: - item.name = item.name.replace('.', '.Conditional.', 1) - msgs.extend(conditionalMsgs) - else: - my_logger.info("\tCondition does not apply") - except ValueError as e: - my_logger.info("\tCondition was skipped due to payload error") - counts['errorProfileComparisonError'] += 1 - if "MinSupportValues" in profile_entry: msg, success = validateSupportedValues( profile_entry["MinSupportValues"],