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('')
def process_json(self, redfishConfig, url): # Don't attempt to purge if a session is not active sessionId = Label.decode(config.sessionIdVariable) if sessionId is None: Trace.log( TraceLevel.INFO, '-- A valid session ({}) was not found!'.format(sessionId)) return # Purge all StorageGroups ids = super().get_members_list(self, redfishConfig, 'StorageGroups') super().delete_id_list( self, redfishConfig, RedfishSystem.get_uri(redfishConfig, 'StorageGroups'), ids) # Purge all Volumes ids = super().get_members_list(self, redfishConfig, 'Volumes') super().delete_id_list(self, redfishConfig, RedfishSystem.get_uri(redfishConfig, 'Volumes'), ids) # Purge all StoragePools ids = super().get_members_list(self, redfishConfig, 'StoragePools', 'A B') super().delete_id_list( self, redfishConfig, RedfishSystem.get_uri(redfishConfig, 'StoragePools'), ids)
def display_results(self, redfishConfig): if (redfishConfig.sessionValid == True): Trace.log( TraceLevel.INFO, '[] Redfish session established ({}:{})'.format( Label.decode(config.sessionIdVariable), redfishConfig.sessionKey)) else: Trace.log( TraceLevel.ERROR, 'Unable to establish a Redfish session, connection, check ip address, username and password' )
def delete_id_list(self, redfishConfig, startUrl, ids): Trace.log( TraceLevel.DEBUG, ' ++ delete_id_list ids ({}) using start URL ({})'.format( len(ids), startUrl)) successes = 0 if (len(ids) >= 1): Trace.log(TraceLevel.INFO, ' ') for i in range(len(ids)): url = startUrl + Label.decode(ids[i], ids[i], 0) Trace.log(TraceLevel.INFO, '[] DELETE ({0})'.format(url)) link = UrlAccess.process_request(redfishConfig, UrlStatus(url), 'DELETE', True) Trace.log( TraceLevel.INFO, ' -- status={}, reason={}'.format( link.urlStatus, link.urlReason)) if (redfishConfig.get_bool('dumphttpdata') and link.jsonData is not None): Trace.log(TraceLevel.INFO, ' -- httpData {}'.format(link.jsonData)) if (link.urlStatus == 200): successes += 1 else: Trace.log(TraceLevel.DEBUG, ' -- response {}'.format(link.response)) Trace.log(TraceLevel.DEBUG, ' -- urlData {}'.format(link.urlData)) Trace.log(TraceLevel.DEBUG, ' -- jsonData {}'.format(link.jsonData)) if (successes > 1): Trace.log(TraceLevel.INFO, '({}) DELETE commands were successful'.format(successes)) return (successes)
def test_links(self): Trace.log( TraceLevel.VERBOSE, '>> Run {}.{}:{}'.format( type(self).__name__, sys._getframe().f_code.co_name, sys._getframe().f_lineno)) url = self.versionUrl link = UrlAccess.process_request(self.redfishConfig, UrlStatus(url), 'GET', False, None) TestSupport.test_link_status(self, link, url) RedfishCommand.execute(self.redfishConfig, 'create session') odataIds = JsonExtract.get_values(link.jsonData, "@odata.id") for url in odataIds: link = UrlAccess.process_request(self.redfishConfig, UrlStatus(url), 'GET', True, None) self.assertTrue(link.valid, 'Link valid for URL ({})'.format(url)) # Delete any current active session sessionId = Label.decode(config.sessionIdVariable) if sessionId is not None: RedfishCommand.execute(self.redfishConfig, f'delete sessions {sessionId}')
def tearDownClass(cls): # Delete any current active session sessionId = Label.decode(config.sessionIdVariable) if sessionId is not None: RedfishCommand.execute(cls.redfishConfig, f'delete sessions {sessionId}')
def setUpClass(cls): cls.redfishConfig = RedfishConfig(Label.decode(config.sessionConfig)) RedfishCommand.execute(cls.redfishConfig, 'create session') cls.systemInitialized = RedfishSystem.initialize_system( cls.redfishConfig)
help= 'Set the trace level (4, 5, 6, or 7) INFO=4, VERBOSE=5, DEBUG=5, TRACE=6', nargs='?', const=1, type=int) args = parser.parse_args() # Load configuration settings, which can be overwritten at the command line or in a script file redfishConfig = RedfishConfig(config.defaultConfigFile if args.config == None else args.config) if (args.tracelevel != None): redfishConfig.update('trace', args.tracelevel) if (args.scriptfile == None): # Run interactive mode ri = RedfishInteractive() ri.execute(redfishConfig) else: # Run script mode returncode = RedfishScript.execute_script(redfishConfig, args.scriptfile) # Before existing, delete any current active session sessionId = Label.decode(config.sessionIdVariable) if sessionId is not None: RedfishCommand.execute(redfishConfig, f'delete sessions {sessionId}') sys.exit(returncode)
def setUpClass(cls): cls.root = '/redfish' cls.version = 'v1' cls.versionUrl = '/redfish/v1/' cls.redfishConfig = RedfishConfig(Label.decode(config.sessionConfig))
>> 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)