From bf29bd2612f11a9ac4414e078e1a9423be957c2b Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Fri, 6 Oct 2023 11:01:00 -0400 Subject: [PATCH] Added exception handling when traversing links if the schema definition for the link is invalid Signed-off-by: Mike Raineri --- README.md | 5 ++++- redfish_service_validator/catalog.py | 19 +++++++++++-------- redfish_service_validator/validateResource.py | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5e85791..52ab827 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ When validating a resource, the following types of tests may occur for each prop * For object properties, check the properties inside the object againt the object's schema definition. * For links, check that the URI referenced matches the expected resource type. +CSDL syntax errors will cause testing to halt and move on to other resources. +The OData CSDL Validator (https://github.com/DMTF/Redfish-Tools/tree/main/odata-csdl-validator) can be used to identify schema errors prior to testing. + ## Conformance Logs - Summary and Detailed Conformance Report The Redfish Service Validator generates an HTML report under the 'logs' folder and is named as 'ConformanceHtmlLog_MM_DD_YYYY_HHMMSS.html', along with a text and config file. @@ -144,7 +147,7 @@ The Redfish Service Validator only performs GET operations on the service. Below are certain items that are not in scope for the tool. * Other HTTP methods, such as PATCH, are not covered. -* Wuery parameters, such as $top and $skip, are not covered. +* Query parameters, such as $top and $skip, are not covered. * Multiple services are not tested simultaneously. ## Building a Standalone Windows Executable diff --git a/redfish_service_validator/catalog.py b/redfish_service_validator/catalog.py index 8653baf..c698109 100644 --- a/redfish_service_validator/catalog.py +++ b/redfish_service_validator/catalog.py @@ -1101,14 +1101,17 @@ def getLinks(self): if isinstance(item.Value, list): for num, val in enumerate(item.Value): # TODO: Along with example Excerpt and RedfishObject, replace following code with hypothetical RedfishType.getCollectionType - new_type_obj = item.Type.getCollectionType() - new_link = RedfishObject(new_type_obj, item.Name, item.parent).populate(val) - new_link.Name = new_link.Name + '#{}'.format(num) - if item.Type.AutoExpand: - new_link.IsAutoExpanded = True - if item.Type.Excerpt: - new_link.IsExcerpt = True - links.append(new_link) + try: + new_type_obj = item.Type.getCollectionType() + new_link = RedfishObject(new_type_obj, item.Name, item.parent).populate(val) + new_link.Name = new_link.Name + '#{}'.format(num) + if item.Type.AutoExpand: + new_link.IsAutoExpanded = True + if item.Type.Excerpt: + new_link.IsExcerpt = True + links.append(new_link) + except Exception as e: + my_logger.error('Unable to build definition for URI {}; check its schema definition or the schema making the reference to the URI for schema errors: {}'.format(val, repr(e))) else: links.append(item) elif item.Type.getBaseType() == 'complex': diff --git a/redfish_service_validator/validateResource.py b/redfish_service_validator/validateResource.py index b147a34..16338f5 100644 --- a/redfish_service_validator/validateResource.py +++ b/redfish_service_validator/validateResource.py @@ -116,7 +116,7 @@ def validateSingleURI(service, URI, uriName='', expectedType=None, expectedJson= raise # re-raise exception except Exception as e: my_logger.verbose1('Exception caught while creating ResourceObj', exc_info=1) - my_logger.error('Unable to gather property info for URI {}: {}'.format(URI, repr(e))) + my_logger.error('Unable to gather property info from schema for URI {}; check its schema definition for schema errors: {}'.format(URI, repr(e))) counts['exceptionResource'] += 1 me['warns'], me['errors'] = get_my_capture(my_logger, whandler), get_my_capture(my_logger, ehandler) return False, counts, results, None, None