mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	Changes for review comments
This commit is contained in:
		| @@ -1,9 +1,8 @@ | ||||
| #!/usr/bin/env python | ||||
|  | ||||
| class SelfServerException(Exception) : | ||||
|     def __init__(self, message, code=0, detail_msg= "", host_and_port="") : | ||||
|     def __init__(self, message, detail_msg= "", host_and_port="") : | ||||
|         super(Exception, self).__init__(message) | ||||
|         self.code = code | ||||
|         self.host_and_port = host_and_port | ||||
|         self.detail_msg = detail_msg | ||||
|  | ||||
|   | ||||
| @@ -46,16 +46,16 @@ class RestSession(object): | ||||
|                 causing_error = "timeout" | ||||
|                 host_and_port = self.extract_server_and_port(e.message[0], "STRING") | ||||
|  | ||||
|             message = 'Error: Failed to connect to server.' | ||||
|             message = 'Failed to connect to server.' | ||||
|             # message = '\n\n--> {0} \n\n'.format(e.message[0]) | ||||
|             raise xcat_exception.SelfServerException(message, "500", '({0})'.format(causing_error), host_and_port) | ||||
|             raise xcat_exception.SelfServerException(message, '({0})'.format(causing_error), host_and_port) | ||||
|  | ||||
|         except requests.exceptions.Timeout as e: | ||||
|             causing_error = "timeout" | ||||
|             host_and_port = self.extract_server_and_port(e.message[0], "STRING") | ||||
|  | ||||
|             message = 'Error: Timeout to connect to server' | ||||
|             raise xcat_exception.SelfServerException(message, "500", '({0})'.format(causing_error), host_and_port) | ||||
|             message = 'Timeout to connect to server' | ||||
|             raise xcat_exception.SelfServerException(message, '({0})'.format(causing_error), host_and_port) | ||||
|  | ||||
|         if not self.cookies: | ||||
|             self.cookies = requests.utils.dict_from_cookiejar(self.session.cookies) | ||||
|   | ||||
| @@ -73,6 +73,13 @@ class OpenBMCPowerTask(ParallelNodesCommand): | ||||
|         bmc_not_ready = bmc_state = 'NotReady' | ||||
|         try: | ||||
|             obmc.login() | ||||
|         except SelfServerException as e: | ||||
|             # Special exception handling for login failure | ||||
|             login_message = "Login to BMC failed: Can't connect to {0} {1}.".format(e.host_and_port, e.detail_msg) | ||||
|             self.callback.error(login_message, node) | ||||
|             return bmc_state | ||||
|  | ||||
|         try: | ||||
|             state = obmc.get_bmc_state() | ||||
|             bmc_state = state.get('bmc') | ||||
|  | ||||
| @@ -83,8 +90,7 @@ class OpenBMCPowerTask(ParallelNodesCommand): | ||||
|  | ||||
|         except SelfServerException, SelfClientException: | ||||
|             # There is no response when BMC is not ready | ||||
|             # Do not print bmc_state, instead, error messages from login failure will be displayed | ||||
|             return bmc_state | ||||
|             result = '%s: %s'  % (node, openbmc.RPOWER_STATES[bmc_not_ready]) | ||||
|  | ||||
|         self.callback.info(result) | ||||
|         return bmc_state | ||||
|   | ||||
| @@ -249,15 +249,6 @@ class OpenBMCRest(object): | ||||
|             self.messager.info(localtime + ' ' + log) | ||||
|             logger.debug(log) | ||||
|  | ||||
|     def _print_record (self, msg, cmd, type="I"): | ||||
|  | ||||
|         log = self.name + ': ' + msg | ||||
|         logger.debug(log) | ||||
|         if type == "E": | ||||
|             self.messager.error(log) | ||||
|         else: | ||||
|             self.messager.info(log) | ||||
|  | ||||
|     def _log_request (self, method, url, headers, data=None, files=None, file_path=None, cmd=''): | ||||
|  | ||||
|         header_str = ' '.join([ "%s: %s" % (k, v) for k,v in headers.items() ]) | ||||
| @@ -285,7 +276,7 @@ class OpenBMCRest(object): | ||||
|         if code != requests.codes.ok: | ||||
|             description = ''.join(data['data']['description']) | ||||
|             error = 'Error: [%d] %s' % (code, description) | ||||
|             self._print_record(error, cmd, "E") | ||||
|             self._print_record_log(error, cmd) | ||||
|             raise SelfClientException(error, code) | ||||
|  | ||||
|         self._print_record_log(data['message'], cmd) | ||||
| @@ -307,13 +298,9 @@ class OpenBMCRest(object): | ||||
|             response = self.session.request(method, url, httpheaders, data=data) | ||||
|             return self.handle_response(response, cmd=cmd) | ||||
|         except SelfServerException as e: | ||||
|             message = 'Error: BMC did not respond. ' \ | ||||
|                       'Validate BMC configuration and retry the command.' | ||||
|             if cmd == 'login': | ||||
|                 login_message = "Error: [{0}] Login to BMC failed: {1} Can't connect to {2} {3}.".format(e.code, e.code, e.host_and_port, e.detail_msg) | ||||
|                 self._print_record(login_message, cmd, "I") | ||||
|  | ||||
|             self._print_record(message, cmd, "E") | ||||
|             e.message = 'Error: BMC did not respond. ' \ | ||||
|                         'Validate BMC configuration and retry the command.' | ||||
|             self._print_record_log(e.message, cmd) | ||||
|             raise | ||||
|         except ValueError: | ||||
|             error = 'Error: Received wrong format response: %s' % response | ||||
|   | ||||
		Reference in New Issue
	
	Block a user