Skip to content

Commit

Permalink
Merge pull request #60 from DMTF/check-fixes
Browse files Browse the repository at this point in the history
Fixes to write check and single entry comparisons
  • Loading branch information
mraineri authored Oct 18, 2018
2 parents 74af590 + 20a35e1 commit cf7e019
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
6 changes: 5 additions & 1 deletion RedfishInteropValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def validateURITree(URI, uriName, profile, expectedType=None, expectedSchema=Non
#############################################################


validatorconfig = {'payloadmode': 'Default', 'payloadfilepath': None, 'logpath': './logs'}
validatorconfig = {'payloadmode': 'Default', 'payloadfilepath': None, 'logpath': './logs', 'writecheck': False}

def main(arglist=None, direct_parser=None):
"""
Expand Down Expand Up @@ -399,6 +399,8 @@ def main(arglist=None, direct_parser=None):
argget.add_argument('profile', type=str, default='sample.json', help='interop profile with which to validate service against')
argget.add_argument('--schema', type=str, default=None, help='schema with which to validate interop profile against')
argget.add_argument('--warnrecommended', action='store_true', help='warn on recommended instead of pass')
# todo: write patches
argget.add_argument('--writecheck', action='store_true', help='(unimplemented) specify to allow WriteRequirement checks')

args = argget.parse_args(arglist)

Expand Down Expand Up @@ -427,6 +429,8 @@ def main(arglist=None, direct_parser=None):
# Set interop config items
config['WarnRecommended'] = rst.config.get('warnrecommended', args.warnrecommended)
commonInterop.config['WarnRecommended'] = config['WarnRecommended']
config['WriteCheck'] = rst.config.get('writecheck', args.writecheck)
commonInterop.config['WriteCheck'] = config['WriteCheck']
config['profile'] = args.profile
config['schema'] = args.schema

Expand Down
38 changes: 25 additions & 13 deletions commonInterop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

rsvLogger = rst.getLogger()

config = {'WarnRecommended': False}
config = {'WarnRecommended': False, 'WriteCheck': False}


class sEnum(Enum):
Expand Down Expand Up @@ -113,6 +113,10 @@ def validateWriteRequirement(propObj, entry, itemname):
rsvLogger.info('writeable \n\t' + str(entry))
permission = 'Read'
expected = "OData.Permission/ReadWrite" if entry else "Any"
if not config['WriteCheck']:
paramPass = True
return msgInterop('WriteRequirement', entry, expected, permission, paramPass),\
paramPass
if entry:
targetProp = findPropItemforString(propObj, itemname.replace('#', ''))
propAttr = None
Expand Down Expand Up @@ -175,22 +179,30 @@ def checkComparison(val, compareType, target):
else:
paramPass = False

if compareType == "Equal":
paramPass = val == target
if compareType == "NotEqual":
paramPass = val != target
if compareType == "GreaterThan":
paramPass = val > target
if compareType == "GreaterThanOrEqual":
paramPass = val >= target
if compareType == "LessThan":
paramPass = val < target
if compareType == "LessThanOrEqual":
paramPass = val <= target
if compareType == "Absent":
paramPass = val == 'DNE'
if compareType == "Present":
paramPass = val != 'DNE'

if isinstance(target, list):
if len(target) >= 1:
target = target[0]
else:
target = 'DNE'

if target != 'DNE':
if compareType == "Equal":
paramPass = val == target
if compareType == "NotEqual":
paramPass = val != target
if compareType == "GreaterThan":
paramPass = val > target
if compareType == "GreaterThanOrEqual":
paramPass = val >= target
if compareType == "LessThan":
paramPass = val < target
if compareType == "LessThanOrEqual":
paramPass = val <= target
rsvLogger.info('\tpass ' + str(paramPass))
if not paramPass:
rsvLogger.error('\tNoPass')
Expand Down

0 comments on commit cf7e019

Please sign in to comment.