def process_json(self, redfishConfig, url): redfishConfig.sessionValid = False Trace.log(TraceLevel.INFO, '') Trace.log(TraceLevel.VERBOSE, '++ Establish Redfish session: ({})...'.format(url)) JsonBuilder.startNew() JsonBuilder.newElement('main', JsonType.DICT) JsonBuilder.addElement('main', JsonType.STRING, 'UserName', redfishConfig.get_value('username')) JsonBuilder.addElement('main', JsonType.STRING, 'Password', redfishConfig.get_value('password')) link = UrlAccess.process_request( redfishConfig, UrlStatus(url), 'POST', False, json.dumps(JsonBuilder.getElement('main'), indent=4)) Trace.log( TraceLevel.TRACE, ' -- urlStatus={} urlReason={}'.format(link.urlStatus, link.urlReason)) # HTTP 201 Created if (link.urlStatus == 201): if (link.jsonData != None): Label.encode(config.sessionIdVariable, link.jsonData['Id']) Trace.log( TraceLevel.TRACE, ' -- {0: <12}: {1}'.format('Id', link.jsonData['Id'])) Trace.log( TraceLevel.TRACE, ' -- {0: <12}: {1}'.format('Name', link.jsonData['Name'])) Trace.log( TraceLevel.TRACE, ' -- {0: <12}: {1}'.format('Description', link.jsonData['Description'])) Trace.log( TraceLevel.TRACE, ' -- {0: <12}: {1}'.format('UserName', link.jsonData['UserName'])) else: Trace.log(TraceLevel.TRACE, ' -- JSON data was (None)') link.sessionKey = link.response.getheader('x-auth-token', '') redfishConfig.sessionKey = link.sessionKey if (redfishConfig.sessionKey != ''): redfishConfig.sessionValid = True else: print('') print('[] URL : {}'.format(link.url)) print('[] Status : {}'.format(link.urlStatus)) print('[] Reason : {}'.format(link.urlReason)) print('')
>> Run Redfish unit tests and generate an XML report. python redfishUnittest.py --xml ''' parser = argparse.ArgumentParser( description='Run Seagate Systems Redfish unit tests and generate a report.', epilog=redfishUnittestEpilog, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('-c', '--config', help='Specify the Redfish API JSON configuration file.') parser.add_argument('--html', help='Generate an HTML unit test report', action='store_true', required=False) parser.add_argument('--xml', help='Generate an XML unit test report', action='store_true') args = parser.parse_args() Label.encode(config.sessionConfig, config.defaultConfigFile if args.config == None else args.config) extension = '' testFiles = 'test*.py' if (args.xml): Trace.log(TraceLevel.INFO, '++ Generate XML Report') extension = 'xml' tests = unittest.TestLoader().discover(config.testFolder, pattern=testFiles) testRunner = xmlrunner.XMLTestRunner(output=config.reportFolder) testRunner.run(tests) else: Trace.log(TraceLevel.INFO, '++ Generate HTML Report') extension = 'html' tests = unittest.TestLoader().discover(config.testFolder, pattern=testFiles) testRunner = HtmlTestRunner.HTMLTestRunner(combine_reports=True, open_in_browser=True, add_timestamp=True)