Skip to content

Commit

Permalink
Merge pull request #596 from DMTF/limit-entity-fix
Browse files Browse the repository at this point in the history
Changes to collection limit for entities and link allocation
  • Loading branch information
mraineri authored Jul 26, 2024
2 parents 0ad97ae + 1aa6fa8 commit cdff70f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 6 additions & 1 deletion redfish_service_validator/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ def as_json(self):
base.update({'Properties': {a: b.as_json() for a, b in self.properties.items()}})
return base

def getLinks(self):
def getLinks(self, collectionlimit={}):
"""Grab links from our Object
"""
links = []
Expand All @@ -1109,6 +1109,11 @@ 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
if item.Type.TypeName in collectionlimit:
link_limit = collectionlimit[item.Type.TypeName]
if num >= link_limit:
my_logger.verbose1('Removing link via limit: {} {}'.format(item.Type.TypeName, val))
continue
try:
new_type_obj = item.Type.getCollectionType()
new_link = RedfishObject(new_type_obj, item.Name, item.parent).populate(val)
Expand Down
10 changes: 10 additions & 0 deletions redfish_service_validator/validateRedfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,16 @@ def checkPropertyConformance(service, prop_name, prop, parent_name=None, parent_
appendStr = (('[' + str(cnt) + ']') if prop.IsCollection else '')
sub_item = prop_name + appendStr

if propRealType == 'entity' and isinstance(prop.Type, RedfishType):
if prop.Type.TypeName in service.config['collectionlimit']:
link_limit = service.config['collectionlimit'][prop.Type.TypeName]
if cnt >= link_limit:
my_logger.verbose1('Removing link check via limit: {} {}'.format(prop.Type.TypeName, val))
resultList[sub_item] = (
displayValue(val, sub_item if prop.IsAutoExpanded else None), displayType(prop.Type),
'Yes' if prop.Exists else 'No', 'NOT TESTED')
continue

excerptPass = validateExcerpt(prop, val)

if isinstance(val, str):
Expand Down
12 changes: 2 additions & 10 deletions redfish_service_validator/validateResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def validateSingleURI(service, URI, uriName='', expectedType=None, expectedJson=

# Get all links available

my_logger.debug(redfish_obj.getLinks())
collection_limit = service.config['collectionlimit']

# Count of occurrences of fail, warn, invalid and deprecated in result of tests to FAILS / WARNINGS
for value in messages.values():
Expand All @@ -301,7 +301,7 @@ def validateSingleURI(service, URI, uriName='', expectedType=None, expectedJson=
if 'failMandatoryExist' in counts.keys():
counts['fails'] += counts['failMandatoryExist']

return True, counts, results, redfish_obj.getLinks(), redfish_obj
return True, counts, results, redfish_obj.getLinks(collection_limit), redfish_obj


def validateURITree(service, URI, uriName, expectedType=None, expectedJson=None, parent=None, all_links_traversed=None, inAnnotation=False):
Expand Down Expand Up @@ -339,14 +339,6 @@ def validateURITree(service, URI, uriName, expectedType=None, expectedJson=None,
# If successful...
if validateSuccess:
# Bring Registries to Front if possible
for link_type in service.config['collectionlimit']:
link_limit = service.config['collectionlimit'][link_type]
applicable_links = [link for link in gathered_links if link_type in link.Type.TypeName]
trimmed_links = applicable_links[link_limit:]
for link in trimmed_links:
link_destination = link.Value.get('@odata.id', link.Value.get('Uri'))
my_logger.verbose1('Removing link via limit: {} {}'.format(link_type, link_destination))
all_links_traversed.add(link_destination)

for link in sorted(gathered_links, key=lambda link: (link.Type.fulltype != 'Registries.Registries')):
if link is None or link.Value is None:
Expand Down

0 comments on commit cdff70f

Please sign in to comment.