1212The purpose of this program is to validate
1313redfish resources against DMTF json schemas.
1414There are three ways to run this:
15- 1) against a directory of all
15+ 1) against a directory of all
1616 resources created by the mockup creator
17172) selecting individual resources from
18- that same directory
18+ that same directory
1919 ( the -f option )
20- 3) pulling a resource from an actual host
20+ 3) pulling a resource from an actual host
2121 of a redfish service.
2222 ( -r and -i options )
2323
3232#!/usr/bin/env bash
3333cmd="/usr/bin/scl enable rh-python34"
3434args="$@"
35- $cmd "./resourceValidate.py $args "
35+ $cmd "./resourceValidate.py $args "
3636
3737'''
3838
4444import getopt
4545import requests
4646
47+ tool_version = '1.0.0'
4748
4849def usage ():
49- print ('\n resourceValidate .py usage:' )
50- print (' -h display usage and exit' )
51- print (' -v verbose' )
52- print (' -m directory path to a mockup tree to validate against, default ./mockup-sim-pull' )
53- print (' -s path to a local dir containing the json schema files to validate against, default ./DMTFSchemas' )
50+ print ('\n Redfish-JsonSchema-ResponseValidator .py usage:' )
51+ print (' -h display usage and exit' )
52+ print (' -v verbose' )
53+ print (' -m directory path to a mockup tree to validate against, default ./mockup-sim-pull' )
54+ print (' -s path to a local dir containing the json schema files to validate against, default ./DMTFSchemas' )
5455 print (' -S tell resourceValidate to get the schemaFiles from http://redfish.dmtf.org/schemas/v1/' )
55- print (' -u user name, default root' )
56- print (' -p password, default calvin' )
57- print (' -e error output file, default ./validate_errs' )
58- print (' -f comma separated list of files to validate. if no -f, it validates entire mockup' )
56+ print (' -u user name, default root' )
57+ print (' -p password, default calvin' )
58+ print (' -e error output file, default ./validate_errs' )
59+ print (' -f comma separated list of files to validate. if no -f, it validates entire mockup' )
5960 print (' -r hostname or IP address [:portno], default None' )
60- print (' -i url, --used with -r option to specify url for a live system. default /redfish/v1' )
61+ print (' -i url, --used with -r option to specify url for a live system. default /redfish/v1' )
6162 print (' -x comma separated list of patterns to exclude from errors' )
6263 print (' -g validate only resources which failed a previous run' )
6364 print ('\n ' )
@@ -136,7 +137,7 @@ def __init__(self, argv):
136137 elif self .files :
137138 self .traverseFiles ()
138139 else :
139- self .traverseDir ()
140+ self .traverseDir ()
140141
141142 print ('\n {} resources validated.' .format (self .rescount ))
142143 if self .errcount :
@@ -158,7 +159,6 @@ def doErrors(self):
158159 line = line .replace ('/index.json' ,'' )
159160 self .files += line + ','
160161 self .traverseFiles ()
161-
162162
163163 def valFromHost (self ):
164164 ''' GET one resource from a host (rackmanager?)
@@ -189,7 +189,6 @@ def valFromHost(self):
189189 self .rescount += 1
190190 self .validate (data ,schname ,self .url )
191191
192-
193192 def traverseFiles (self ):
194193 ''' read a list of resources specified
195194 with the -f option,
@@ -230,7 +229,7 @@ def traverseFiles(self):
230229 self .validate (data ,schname ,fname )
231230
232231 def traverseDir (self ):
233- ''' walk a directory of resources,i.e a "mockup"
232+ ''' walk a directory of resources,i.e a "mockup"
234233 and validate against a DTMF schema.
235234 '''
236235 for dirn , subdir , filelist in os .walk (self .mockdir ):
@@ -390,7 +389,7 @@ def parseOdataType(self,resource):
390389 return (None ,None ,None )
391390
392391 resourceOdataType = resource ["@odata.type" ]
393-
392+
394393 #the odataType format is: <namespace>.<version>.<type> where version may have periods in it
395394 odataTypeMatch = re .compile ('^#([a-zA-Z0-9]*)\.([a-zA-Z0-9\._]*)\.([a-zA-Z0-9]*)$' )
396395 resourceMatch = re .match (odataTypeMatch , resourceOdataType )
@@ -413,6 +412,5 @@ def parseOdataType(self,resource):
413412 return (namespace , version , resourceType )
414413
415414if __name__ == '__main__' :
415+ print ( "Redfish-JsonSchema-ResponseValidator version {}" .format ( tool_version ) )
416416 rv = ResourceValidate (sys .argv )
417-
418-
0 commit comments