From eafdef413c1e05d3a9b8249bb2214341b48d1b30 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sun, 15 Sep 2013 10:45:38 -0400 Subject: [PATCH] Fix problem where wait for next data would only work every other time Also fix busy wait behavior --- plugins/ipmi.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/ipmi.py b/plugins/ipmi.py index 2a3ca87b..0db5ec78 100644 --- a/plugins/ipmi.py +++ b/plugins/ipmi.py @@ -1,5 +1,6 @@ import collections import eventlet +import eventlet.event import os import pyghmi.ipmi.console as console console.session.select = eventlet.green.select @@ -9,6 +10,7 @@ _ipmithread = None pullchain = None tmptimeout = None ipmiq = collections.deque([]) +ipmiwaiters = collections.deque([]) def _ipmi_evtloop(): @@ -22,13 +24,16 @@ def _ipmi_evtloop(): tmptimeout = None else: console.session.Session.wait_for_rsp(timeout=600) + while ipmiwaiters: + waiter = ipmiwaiters.popleft() + waiter.send() def _process_chgs(intline): - print "yoink" os.read(intline,1) # answer the bell while ipmiq: cval = ipmiq.popleft() - cval[0](*cval[1]) + if hasattr(cval[0], '__call__'): + cval[0](*cval[1]) @@ -88,15 +93,14 @@ class Console(object): userid=self.username, password=self.password, kg=self.kg, + force=True, iohandler=callback) if _ipmithread is None: pullchain = os.pipe() _ipmithread = eventlet.spawn(_ipmi_evtloop) def write(self, data): - global pullchain ipmiq.append((self.solconnection.send_data, (data,))) - print "yank" os.write(pullchain[1],'1') #self.solconnection.send_data(data) @@ -114,9 +118,14 @@ class Console(object): # taller than it has to be global tmptimeout tmptimeout = timeout + os.write(pullchain[1],'1') + eventlet.sleep(0.001) + waitevt = eventlet.event.Event() + ipmiwaiters.append(waitevt) + waitevt.wait() #TODO: a channel for the ipmithread to tug back instead of busy wait - while tmptimeout is not None: - eventlet.sleep(0) + #while tmptimeout is not None: + # eventlet.sleep(0) #console.session.Session.wait_for_rsp(timeout=timeout)