client: change online state before callback

the client in NICOS is referring to the online state within the
callback.

+ better error handling
This commit is contained in:
l_samenv 2021-04-08 10:11:04 +02:00
parent 4d7e5d3cdc
commit 10dad6da47

View File

@ -493,17 +493,12 @@ class SecopClient(ProxyClient):
self.log.warning('unhandled message: %s %s %r' % (action, ident, data))
def _set_state(self, online, state=None):
# treat reconnecting as online!
state = state or self.state
try:
self.callback(None, 'nodeStateChange', online, state)
for mname in self.modules:
self.callback(mname, 'nodeStateChange', online, state)
except Exception as e:
self.log.error('ERROR in nodeStateCallback %s', e)
# set online attribute after callbacks -> callback may check for old state
# remark: reconnecting is treated as online
self.online = online
self.state = state
self.state = state or self.state
self.callback(None, 'nodeStateChange', self.online, self.state)
for mname in self.modules:
self.callback(mname, 'nodeStateChange', self.online, self.state)
def queue_request(self, action, ident=None, data=None):
"""make a request"""
@ -522,8 +517,8 @@ class SecopClient(ProxyClient):
raise ConnectionError('connection closed before reply')
action, _, data = entry[2] # pylint: disable=unpacking-non-sequence
if action.startswith(ERRORPREFIX):
errcls = self.error_map(data[0])
raise errcls('on SEC-Node: ' + data[1])
errcls = self.error_map(data[0] + "Error")
raise errcls(data[1])
return entry[2] # reply
def request(self, action, ident=None, data=None):