From 4c366d2f47ff93461d7457009936adc7d70dd553 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 9 May 2017 14:32:51 -0400 Subject: [PATCH] Move raising sync login exception By raising it in the callback, another thread doing wait_for_rsp might get hit by it. Store the message and then raise in __init__ so that it lands in the correct vicinity. Change-Id: Id450a4a3f6194d95bb0eac971e0586525c49e490 --- pyghmi/ipmi/private/session.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pyghmi/ipmi/private/session.py b/pyghmi/ipmi/private/session.py index a9945d08..6997c195 100644 --- a/pyghmi/ipmi/private/session.py +++ b/pyghmi/ipmi/private/session.py @@ -368,8 +368,9 @@ class Session(object): """Handle synchronous callers in liue of a client-provided callback. """ - if 'error' in response: - raise exc.IpmiException(response['error']) + # Be a stub, the __init__ will catch and respond to ensure response + # is given in the same thread as was called + return def __new__(cls, bmc, @@ -415,6 +416,7 @@ class Session(object): else: self.iterwaiters.append(onlogon) return + self.broken = False self.privlevel = 4 self.maxtimeout = 3 # be aggressive about giving up on initial packet self.incommand = False @@ -465,13 +467,16 @@ class Session(object): if not self.async: while self.logging: Session.wait_for_rsp() + if self.broken: + raise exc.IpmiException(self.errormsg) - def _mark_broken(self): + def _mark_broken(self, error=None): # since our connection has failed retries # deregister our keepalive facility Session.keepalive_sessions.pop(self, None) Session.waiting_sessions.pop(self, None) self.logging = False + self.errormsg = error if self.logged: self.logged = 0 # mark session as busted self.logging = False @@ -500,7 +505,7 @@ class Session(object): def onlogon(self, parameter): if 'error' in parameter: - self._mark_broken() + self._mark_broken(parameter['error']) while self.logonwaiters: waiter = self.logonwaiters.pop() waiter(parameter)