mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-06-13 01:40:26 +00:00
[OpenBMC] The return code on error should be 1 instead of 0 (#4871)
* fix issue 4854, modify return code when has error
This commit is contained in:
@ -92,8 +92,11 @@ class Messager(object):
|
||||
def warn(self, msg):
|
||||
self.logger.warn(msg)
|
||||
|
||||
def error(self, msg):
|
||||
self.logger.error(msg)
|
||||
def error(self, msg, node=''):
|
||||
if node:
|
||||
self.logger.error('%s: Error: %s' % (node, msg))
|
||||
else:
|
||||
self.logger.error('Error: %s' % msg)
|
||||
|
||||
def syslog(self, msg):
|
||||
pass
|
||||
|
@ -27,9 +27,8 @@ class OpenBMCBeaconTask(ParallelNodesCommand):
|
||||
try:
|
||||
obmc.login()
|
||||
obmc.set_beacon_state(state)
|
||||
result = '%s: %s' % (node, state)
|
||||
self.callback.info('%s: %s' % (node, state))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
result = '%s: %s' % (node, e.message)
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
self.callback.info(result)
|
||||
|
@ -59,12 +59,12 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
check_cmd = grep_cmd + ' ' + path_not_found + ' ' + dump_log_file
|
||||
grep_string = os.popen(check_cmd).readlines()
|
||||
if grep_string:
|
||||
result = 'Invalid dump %s was specified. Use -l option to list.' % download_id
|
||||
self.callback.error('Invalid dump %s was specified. Use -l option to list.' % download_id, node)
|
||||
else:
|
||||
result = 'Downloaded dump %s to %s.' % (download_id, dump_log_file)
|
||||
self.callback.info('%s: Downloaded dump %s to %s.' % (node, download_id, dump_log_file))
|
||||
else:
|
||||
result = 'Failed to download dump %s to %s.' % (download_id, dump_log_file)
|
||||
return result
|
||||
self.callback.error('Failed to download dump %s to %s.' % (download_id, dump_log_file), node)
|
||||
return
|
||||
|
||||
def dump_list(self, **kw):
|
||||
|
||||
@ -90,7 +90,7 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
self.callback.info('%s: %s' % (node, info))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return dump_info
|
||||
|
||||
@ -109,7 +109,7 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
else:
|
||||
self.callback.info('%s: [%s] success' % (node, dump_id))
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return dump_id
|
||||
|
||||
@ -123,11 +123,9 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
obmc.login()
|
||||
obmc.clear_dump(clear_arg)
|
||||
|
||||
result = '%s: [%s] clear' % (node, clear_arg)
|
||||
self.callback.info('%s: [%s] clear' % (node, clear_arg))
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
result = '%s: %s' % (node, e.message)
|
||||
|
||||
self.callback.info(result)
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def dump_download(self, download_arg, **kw):
|
||||
|
||||
@ -138,8 +136,7 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
try:
|
||||
obmc.login()
|
||||
if download_arg != 'all':
|
||||
result = self._dump_download(obmc, node, download_arg)
|
||||
self.callback.info('%s: %s' % (node, result))
|
||||
self._dump_download(obmc, node, download_arg)
|
||||
return
|
||||
|
||||
dump_dict = obmc.list_dump_info()
|
||||
@ -147,10 +144,9 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
keys.sort()
|
||||
|
||||
for key in keys:
|
||||
result = self._dump_download(obmc, node, str(key))
|
||||
self.callback.info('%s: %s' % (node, result))
|
||||
self._dump_download(obmc, node, str(key))
|
||||
except SelfServerException as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def dump_process(self, **kw):
|
||||
|
||||
@ -174,14 +170,12 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
sleep( 15 )
|
||||
|
||||
if flag:
|
||||
result = self._dump_download(obmc, node, str(dump_id), flag_dump_process=True)
|
||||
self._dump_download(obmc, node, str(dump_id), flag_dump_process=True)
|
||||
else:
|
||||
result = 'Could not find dump %s after waiting %d seconds.' % (dump_id, 20 * 15)
|
||||
|
||||
self.callback.info('%s: %s' % (node, result))
|
||||
self.callback.error('Could not find dump %s after waiting %d seconds.' % (dump_id, 20 * 15), node)
|
||||
|
||||
except SelfServerException as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def gard_clear(self, **kw):
|
||||
|
||||
@ -195,7 +189,7 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand):
|
||||
self.callback.info('%s: GARD cleared' % node)
|
||||
|
||||
except SelfServerException as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def pre_set_sshcfg(self, *arg, **kw):
|
||||
local_home_dir=os.path.expanduser('~')
|
||||
@ -233,11 +227,11 @@ rmdir \"/tmp/$userid\" \n")
|
||||
ssh_client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
|
||||
ssh_client.connect(nodeinfo['bmcip'], username=nodeinfo['username'], password=nodeinfo['password'])
|
||||
except (NoValidConnectionsError) as e:
|
||||
return self.callback.error("%s: Unable to connect to bmc %s" % (node, nodeinfo['bmcip']))
|
||||
return self.callback.error("Unable to connect to bmc %s" % nodeinfo['bmcip'], node)
|
||||
if not ssh_client.get_transport().is_active():
|
||||
return self.callback.error("%s: SSH session to bmc %s is not active" % (node, nodeinfo['bmcip']))
|
||||
return self.callback.error("SSH session to bmc %s is not active" % nodeinfo['bmcip'], node)
|
||||
if not ssh_client.get_transport().is_authenticated():
|
||||
return self.callback.error("%s: SSH session to bmc %s is not authenticated" % (node, nodeinfo['bmcip']))
|
||||
return self.callback.error("SSH session to bmc %s is not authenticated" % nodeinfo['bmcip'], node)
|
||||
ssh_client.exec_command("/bin/mkdir -p %s\n" % tmp_remote_dir)
|
||||
scp = SCPClient(ssh_client.get_transport())
|
||||
scp.put(self.copy_sh_file, tmp_remote_dir + "copy.sh")
|
||||
@ -255,14 +249,14 @@ rmdir \"/tmp/$userid\" \n")
|
||||
obmc.login()
|
||||
obmc.set_ipdhcp()
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info("%s: %s" % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
return
|
||||
|
||||
self.callback.info("%s: BMC Setting IP to DHCP..." % (node))
|
||||
try:
|
||||
obmc.reboot_bmc()
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info("%s: %s" % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def get_attributes(self, attributes, **kw):
|
||||
netinfo_dict={}
|
||||
@ -273,7 +267,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
elif attr in openbmc.RSPCONFIG_APIS:
|
||||
self._get_apis_values(attr, **kw)
|
||||
else:
|
||||
self.callback.error("get_attributes can not deal with attr %s" % attr)
|
||||
self.callback.error("get_attributes can not deal with attr %s" % attr, kw['node'])
|
||||
if len(netinfo_dict):
|
||||
self._get_netinfo(ip=netinfo_dict.get('ip', False), ipsrc=netinfo_dict.get('ipsrc', False), netmask=netinfo_dict.get('netmask', False),
|
||||
gateway=netinfo_dict.get('gateway', False),vlan= netinfo_dict.get('vlan', False),
|
||||
@ -295,7 +289,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
elif k in openbmc.RSPCONFIG_APIS:
|
||||
self._set_apis_values(k, v, **kw)
|
||||
else:
|
||||
return self.callback.error("set_attributes unsupported attribute:%s" % k)
|
||||
return self.callback.error("set_attributes unsupported attribute:%s" % k, node)
|
||||
if len(netinfo_dict) > 1 and ('ip' not in netinfo_dict or 'netmask' not in netinfo_dict or 'gateway' not in netinfo_dict):
|
||||
self.callback.info("set_attributes miss either ip, netmask or gateway to set network information")
|
||||
elif len(netinfo_dict) <= 1:
|
||||
@ -324,23 +318,23 @@ rmdir \"/tmp/$userid\" \n")
|
||||
obmc.login()
|
||||
netinfo = obmc.get_netinfo()
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
return
|
||||
|
||||
if not netinfo:
|
||||
return self.callback.error("%s: No network information get" % node)
|
||||
return self.callback.error('No network information get', node)
|
||||
|
||||
bmcip = node_info['bmcip']
|
||||
nic = self._get_facing_nic(bmcip, netinfo)
|
||||
if not nic:
|
||||
return self.callback.error('%s: Can not get facing NIC for %s' % (node, bmcip))
|
||||
return self.callback.error('Can not get facing NIC for %s' % bmcip, node)
|
||||
|
||||
try:
|
||||
obmc.set_ntp_servers(nic, servers)
|
||||
self.callback.info('%s: BMC Setting NTPServers...' % node)
|
||||
netinfo = obmc.get_netinfo()
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
return
|
||||
|
||||
ntpservers = None
|
||||
@ -361,7 +355,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
origin_passwd, new_passwd = admin_passwd.split(',')
|
||||
|
||||
if origin_passwd != node_info['password']:
|
||||
self.callback.info('%s: Current BMC password is incorrect, cannot set the new password.' % node)
|
||||
self.callback.error('Current BMC password is incorrect, cannot set the new password.', node)
|
||||
return
|
||||
|
||||
obmc = openbmc.OpenBMCRest(name=node, nodeinfo=node_info, messager=self.callback,
|
||||
@ -371,7 +365,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
obmc.set_admin_passwd(new_passwd)
|
||||
self.callback.info("%s: BMC Setting Password..." % node)
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info("%s: %s" % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
def _set_apis_values(self, key, value, **kw):
|
||||
node = kw['node']
|
||||
@ -381,7 +375,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
obmc.login()
|
||||
obmc.set_apis_values(key, value)
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info("%s: %s" % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
self.callback.info("%s: BMC Setting %s..." % (node, openbmc.RSPCONFIG_APIS[key]['display_name']))
|
||||
|
||||
@ -394,7 +388,7 @@ rmdir \"/tmp/$userid\" \n")
|
||||
value = obmc.get_apis_values(key)
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
str_value = '0.'+str(value)
|
||||
result = '%s: %s: %s' % (node, openbmc.RSPCONFIG_APIS[key]['display_name'], str_value.split('.')[-1])
|
||||
@ -415,10 +409,10 @@ rmdir \"/tmp/$userid\" \n")
|
||||
obmc.login()
|
||||
netinfo = obmc.get_netinfo()
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
return
|
||||
if not netinfo:
|
||||
return self.callback.error("%s: No network information get" % node)
|
||||
return self.callback.error("No network information get", node)
|
||||
defaultgateway = "n/a"
|
||||
bmchostname = ""
|
||||
if 'defaultgateway' in netinfo:
|
||||
|
@ -49,7 +49,7 @@ class OpenBMCEventlogTask(ParallelNodesCommand):
|
||||
eventlog_info += eventlog_info_dict[key]
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return eventlog_info
|
||||
|
||||
|
@ -93,7 +93,7 @@ class OpenBMCInventoryTask(ParallelNodesCommand):
|
||||
self.callback.info( '%s: %s' % (node, info))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return inventory_info
|
||||
|
||||
@ -113,7 +113,7 @@ class OpenBMCInventoryTask(ParallelNodesCommand):
|
||||
self.callback.info( '%s: %s' % (node, info))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return firm_info
|
||||
|
||||
|
@ -88,7 +88,7 @@ class OpenBMCSensorTask(ParallelNodesCommand):
|
||||
self.callback.info( '%s: %s' % (node, info))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return sensor_info
|
||||
|
||||
@ -111,7 +111,7 @@ class OpenBMCSensorTask(ParallelNodesCommand):
|
||||
self.callback.info( '%s: %s' % (node, info))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
self.callback.info('%s: %s' % (node, e.message))
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
return beacon_info
|
||||
|
||||
|
@ -30,12 +30,11 @@ class OpenBMCBootTask(ParallelNodesCommand):
|
||||
obmc.login()
|
||||
state = obmc.get_boot_state()
|
||||
|
||||
result = '%s: %s' % (node, state)
|
||||
self.callback.info('%s: %s' % (node, state))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
result = '%s: %s' % (node, e.message)
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
self.callback.info(result)
|
||||
return state
|
||||
|
||||
def set_state(self, state, persistant, **kw):
|
||||
@ -55,10 +54,9 @@ class OpenBMCBootTask(ParallelNodesCommand):
|
||||
|
||||
state = obmc.get_boot_state()
|
||||
|
||||
result = '%s: %s' % (node, state)
|
||||
self.callback.info('%s: %s' % (node, state))
|
||||
|
||||
except (SelfServerException, SelfClientException) as e:
|
||||
result = '%s: %s' % (node, e.message)
|
||||
self.callback.error(e.message, node)
|
||||
|
||||
self.callback.info(result)
|
||||
|
||||
|
@ -36,8 +36,8 @@ class XCATMessager(utils.Messager):
|
||||
d = {'type': MSG_TYPE, 'msg': {'type': 'warning', 'data': msg}}
|
||||
self._send(d)
|
||||
|
||||
def error(self, msg):
|
||||
d = {'type': MSG_TYPE, 'msg': {'type': 'error', 'data': msg}}
|
||||
def error(self, msg, node=''):
|
||||
d = {'type': MSG_TYPE, 'msg': {'type': 'error', 'node': node, 'data': msg}}
|
||||
self._send(d)
|
||||
|
||||
def syslog(self, msg):
|
||||
|
@ -109,7 +109,7 @@ sub handle_message {
|
||||
} elsif ($msg->{type} eq 'warning') {
|
||||
xCAT::MsgUtils->message("W", { data => [$msg->{data}] }, $callback);
|
||||
} elsif ($msg->{type} eq 'error'){
|
||||
xCAT::MsgUtils->message("E", { data => [$msg->{data}] }, $callback);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $msg->{data} ], $callback, $msg->{node});
|
||||
} elsif ($msg->{type} eq 'syslog'){
|
||||
xCAT::MsgUtils->message("S", $msg->{data});
|
||||
}
|
||||
|
Reference in New Issue
Block a user