Skip to content

Commit

Permalink
Merge pull request #549 from DMTF/action-log-entry
Browse files Browse the repository at this point in the history
Fix to Action validation overriding variable name, added log entry
  • Loading branch information
mraineri authored Mar 17, 2023
2 parents 2e16b6a + af57edb commit fe34add
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion redfish_service_validator/tohtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from types import SimpleNamespace
from collections import Counter
import json
import re

# hack in tagnames into module namespace
tag = SimpleNamespace(**{tagName: lambda string, attr=None, tag=tagName: wrapTag(string, tag=tag, attr=attr)\
Expand All @@ -29,7 +30,7 @@ def count_errors(results):
for countType in sorted(innerCounts.keys()):
if innerCounts.get(countType) == 0:
continue
if any(x in countType for x in ['problem', 'fail', 'bad', 'exception', 'err.']):
if re.search(r"^error|problem|fail|bad|exception|err[.]", countType):
counters_all_pass = False
error_lines.append('{} {} errors in {}'.format(innerCounts[countType], countType, results[item]['uri']))
innerCounts[countType] += 0
Expand Down
25 changes: 16 additions & 9 deletions redfish_service_validator/validateRedfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,39 @@ def validateExcerpt(prop, val):
return True


def validateAction(act_name, actionDecoded, all_actions):
def validateAction(act_fulltype, actionDecoded, all_actions):
actionMessages, actionCounts = OrderedDict(), Counter()
act_name, act_type = getNamespace(act_name.strip('#')), getType(act_name)
act_namespace, act_type = getNamespace(act_fulltype.strip('#')), getType(act_fulltype)
actPass = False
if act_type not in all_actions:
my_logger.error('Action {} does not exist in Namespace {}'.format(act_type, act_namespace))
actionCounts['errorActionBadName'] += 1
actionMessages[act_fulltype] = (
'Action', '-',
'Yes' if actionDecoded != REDFISH_ABSENT else 'No',
'FAIL')
else:
my_act = all_actions[act_type]
actOptional = my_act.find('annotation', {'term': 'Redfish.Required'}) is not None
if actionDecoded == REDFISH_ABSENT:
if actOptional:
actPass = True
else:
my_logger.error('{}: Mandatory action missing'.format(act_name))
my_logger.error('{}: Mandatory action missing'.format(act_namespace))
actionCounts['failMandatoryAction'] += 1
if actionDecoded != REDFISH_ABSENT:
# validate target
target = actionDecoded.get('target')
if target is None:
my_logger.error('{}: target for action is missing'.format(act_name))
my_logger.error('{}: target for action is missing'.format(act_namespace))
elif not isinstance(target, str):
my_logger.error('{}: target for action is malformed'.format(act_name))
my_logger.error('{}: target for action is malformed'.format(act_namespace))
# check for unexpected properties
for ap_name in actionDecoded:
expected = ['target', 'title', '@Redfish.ActionInfo', '@Redfish.OperationApplyTimeSupport']
if ap_name not in expected and '@Redfish.AllowableValues' not in ap_name:
my_logger.error('{}: Property "{}" is not allowed in actions property. \
Allowed properties are "{}", "{}", "{}", "{}" and "{}"'.format(act_name, ap_name, *expected, '*@Redfish.AllowableValues'))
Allowed properties are "{}", "{}", "{}", "{}" and "{}"'.format(act_namespace, ap_name, *expected, '*@Redfish.AllowableValues'))
actPass = True
if actOptional and actPass:
actionCounts['optionalAction'] += 1
Expand All @@ -78,9 +83,9 @@ def validateAction(act_name, actionDecoded, all_actions):
else:
actionCounts['failAction'] += 1

actionMessages[act_name] = (
actionMessages[act_fulltype] = (
'Action', '-',
'Yes' if actionDecoded != 'n/a' else 'No',
'Yes' if actionDecoded != REDFISH_ABSENT else 'No',
'Optional' if actOptional else 'PASS' if actPass else 'FAIL')
return actionMessages, actionCounts

Expand Down Expand Up @@ -218,15 +223,17 @@ def validateComplex(service, sub_obj, prop_name, oem_check=True):
subCounts.update(new_counts)
subCounts['invalidNamedProperty.complex'] += 1


successPayload, odataMessages = checkPayloadConformance(sub_obj.Value, '')

if not successPayload:
odataMessages['failPayloadError.complex'] += 1
my_logger.error('{}: complex payload error, @odata property non-conformant'.format(str(sub_obj.Name)))

if prop_name == 'Actions':
actionMessages, actionCounts = OrderedDict(), Counter()

# Get our actions from the object itself to test
# Action Namespace.Type, Action Object
my_actions = [(x.strip('#'), y) for x, y in sub_obj.Value.items() if x != 'Oem']
if 'Oem' in sub_obj.Value.items():
if oem_check:
Expand Down

0 comments on commit fe34add

Please sign in to comment.