9
9
import traverseInterop
10
10
import common .interop as interop
11
11
from common .redfish import getType , getNamespace
12
+ from common .interop import REDFISH_ABSENT
12
13
13
14
my_logger = logging .getLogger ()
14
15
my_logger .setLevel (logging .DEBUG )
@@ -245,6 +246,7 @@ def validateURITree(URI, profile, uriName, expectedType=None, expectedSchema=Non
245
246
"Writeable" : False ,
246
247
"URIsFound" : [URI .rstrip ('/' )],
247
248
"SubordinateTo" : set (),
249
+ "UseCasesFound" : set ()
248
250
}
249
251
250
252
# parent first, then child execution
@@ -299,25 +301,33 @@ def validateURITree(URI, profile, uriName, expectedType=None, expectedSchema=Non
299
301
subordinate_tree .append (parentType )
300
302
current_parent = current_parent .parent
301
303
304
+ # Search for UseCase.USECASENAME
305
+ usecases_found = [msg .name .split ('.' )[- 1 ] for msg in linkResults [linkName ]['messages' ] if 'UseCase' == msg .name .split ('.' )[0 ]]
306
+
302
307
if resource_stats .get (SchemaType ) is None :
303
308
resource_stats [SchemaType ] = {
304
309
"Exists" : True ,
305
310
"Writeable" : False ,
306
311
"URIsFound" : [link .rstrip ('/' )],
307
312
"SubordinateTo" : set ([tuple (reversed (subordinate_tree ))]),
313
+ "UseCasesFound" : set (usecases_found ),
308
314
}
309
315
else :
310
316
resource_stats [SchemaType ]['Exists' ] = True
311
317
resource_stats [SchemaType ]['URIsFound' ].append (link .rstrip ('/' ))
312
318
resource_stats [SchemaType ]['SubordinateTo' ].add (tuple (reversed (subordinate_tree )))
313
-
319
+ resource_stats [ SchemaType ][ 'UseCasesFound' ]. union ( usecases_found )
314
320
315
321
if refLinks is not currentLinks and len (newLinks ) == 0 and len (refLinks ) > 0 :
316
322
currentLinks = refLinks
317
323
else :
318
324
currentLinks = newLinks
325
+
326
+ my_logger .info ('Service Level Checks' )
327
+ # NOTE: readrequirements will likely be errors when using --payload outside of root
319
328
320
329
# For every resource check ReadRequirement
330
+ # TODO: verify if IfImplemented should report a fail if any fails exist. Also verify the same for Recommended
321
331
resources_in_profile = profile .get ('Resources' , [])
322
332
for resource_type in resources_in_profile :
323
333
profile_entry = resources_in_profile [resource_type ]
@@ -326,68 +336,90 @@ def validateURITree(URI, profile, uriName, expectedType=None, expectedSchema=Non
326
336
msgs = interop .validateComparisonAnyOfAllOf (profile_entry ['PropertyRequirements' ], resource_type )
327
337
message_list .extend (msgs )
328
338
329
- apply_requirement , expected_requirement = False , None
339
+ does_resource_exist , expected_requirement = False , None
340
+
341
+ resource_exists , uris_found , subs_found = False , [], []
330
342
331
343
# If exist and for what URIs...
332
344
if resource_type in resource_stats :
333
345
resource_exists = resource_stats [resource_type ]['Exists' ]
334
346
uris_found = resource_stats [resource_type ]['URIsFound' ]
335
347
subs_found = resource_stats [resource_type ]['SubordinateTo' ]
336
- else :
337
- resource_exists = False
338
- uris_found = []
339
- subs_found = []
348
+ usecases_found = resource_stats [resource_type ]['UseCasesFound' ]
349
+
350
+ # Before all else, UseCases takes priority
351
+ if 'UseCases' in profile_entry :
352
+ # For each use case, apply the Requirement
353
+ for use_case in profile_entry ['UseCases' ]:
354
+ entry_title = use_case .get ("UseCaseTitle" , "NoName" ).replace (' ' , '_' )
355
+ expected_requirement = use_case .get ("ReadRequirement" , "Mandatory" )
356
+ uris_applied = use_case .get ("URIs" )
357
+
358
+ if uris_applied :
359
+ does_resource_exist = any ([interop .compareRedfishURI (uris_applied , uri ) for uri in uris_found ])
360
+ else :
361
+ does_resource_exist = resource_exists
362
+
363
+ does_resource_exist = does_resource_exist and entry_title in usecases_found
364
+
365
+ my_logger .info ('Validating UseCase {} of {} ReadRequirement' .format (entry_title , resource_type ))
366
+
367
+ my_msg , _ = interop .validateRequirement (expected_requirement , 'Exists' if does_resource_exist else REDFISH_ABSENT )
368
+ my_msg .name = 'UseCase.{}.{}' .format (entry_title , my_msg .name )
369
+ if uris_applied :
370
+ my_msg .expected = "{} at {}" .format (my_msg .expected , ", " .join (uris_applied ))
371
+ message_list .append (my_msg )
372
+ continue
340
373
341
374
# Check conditionals, if it applies, get its requirement
342
- if "ConditionalRequirements" in profile_entry :
375
+ elif "ConditionalRequirements" in profile_entry :
343
376
for condition in profile_entry ['ConditionalRequirements' ]:
344
377
uris_applied = condition .get ("URIs" )
345
378
subordinate_condition = condition .get ("SubordinateToResource" )
379
+ # Check if we have valid URIs for this conditional
346
380
if uris_applied :
347
- apply_requirement = any ([interop .compareRedfishURI (uris_applied , uri ) for uri in uris_found ])
348
- my_logger .info ('Checking if any {} in {}: {}' .format (uris_found , uris_applied , apply_requirement ))
381
+ does_resource_exist = any ([interop .compareRedfishURI (uris_applied , uri ) for uri in uris_found ])
382
+ my_logger .info ('Checking if any {} in {}: {}' .format (uris_found , uris_applied , does_resource_exist ))
383
+ # Or check if we are underneath the correct resource chain
349
384
elif subordinate_condition :
350
- apply_requirement = any ([(tuple ((subordinate_condition ))) == chain [- len (subordinate_condition ):] for chain in subs_found ])
351
- my_logger .info ('Checking if any {} matches {}: {}' .format ([x for x in subs_found ], subordinate_condition , apply_requirement ))
385
+ does_resource_exist = any ([(tuple ((subordinate_condition ))) == chain [- len (subordinate_condition ):] for chain in subs_found ])
386
+ my_logger .info ('Checking if any {} matches {}: {}' .format ([x for x in subs_found ], subordinate_condition , does_resource_exist ))
387
+ # warn user if Conditional has no appropriate conditions to use
352
388
else :
353
- apply_requirement = resource_exists
389
+ does_resource_exist = resource_exists
354
390
my_logger .warn ('This resource {} has no valid Conditional in ConditionalRequirements' .format (resource_type ))
355
391
392
+ # if we have a ReadRequirement...
356
393
expected_requirement = condition .get ("ReadRequirement" )
357
394
if expected_requirement :
358
395
my_logger .info ('Validating {} Conditional ReadRequirement' .format (resource_type ))
359
- my_msg , _ = interop .validateRequirement (expected_requirement , 'Exists' if apply_requirement else 'DNE' )
396
+ my_msg , _ = interop .validateRequirement (expected_requirement , 'Exists' if does_resource_exist else REDFISH_ABSENT )
360
397
my_msg .name = '{}.Conditional.{}' .format (resource_type , my_msg .name )
361
398
if uris_applied :
362
399
my_msg .expected = "{} at {}" .format (my_msg .expected , ", " .join (uris_applied ))
363
400
if subordinate_condition :
364
401
my_msg .expected = "{} under {}" .format (my_msg .expected , ", " .join (subordinate_condition ))
365
402
message_list .append (my_msg )
366
403
404
+ # Outside of ConditionalRequirements, check just for URIs
405
+ # TODO: Verify if this should run if ConditionalRequirements exists
367
406
expected_requirement = profile_entry .get ("ReadRequirement" , "Mandatory" )
368
407
uris_applied = profile_entry .get ("URIs" )
369
408
370
409
if uris_applied :
371
- apply_requirement = any ([interop .compareRedfishURI (uris_applied , uri ) for uri in uris_found ])
410
+ does_resource_exist = any ([interop .compareRedfishURI (uris_applied , uri ) for uri in uris_found ])
372
411
else :
373
- apply_requirement = resource_exists
412
+ does_resource_exist = resource_exists
374
413
375
414
my_logger .info ('Validating {} ReadRequirement' .format (resource_type ))
376
- my_msg , _ = interop .validateRequirement (expected_requirement , 'Exists' if apply_requirement else 'DNE' )
415
+ my_msg , _ = interop .validateRequirement (expected_requirement , 'Exists' if does_resource_exist else REDFISH_ABSENT )
377
416
my_msg .name = '{}.{}' .format (resource_type , my_msg .name )
378
417
if uris_applied :
379
418
my_msg .expected = "{} at {}" .format (my_msg .expected , ", " .join (uris_applied ))
380
419
message_list .append (my_msg )
381
-
382
-
420
+
383
421
# interop service level checks
384
422
finalResults = {}
385
- my_logger .info ('Service Level Checks' )
386
- if URI not in ["/redfish/v1" , "/redfish/v1/" ]:
387
- resultEnum = interop .sEnum .WARN
388
- my_logger .info ("We are not validating root, warn only" )
389
- else :
390
- resultEnum = interop .sEnum .FAIL
391
423
392
424
for item in message_list :
393
425
if item .success == interop .sEnum .WARN :
0 commit comments