Skip to content

Commit

Permalink
PhysicalConsole: replace retry mechanism
Browse files Browse the repository at this point in the history
It was buggy and unreadable. Use safe_while.

Signed-off-by: Zack Cerza <[email protected]>
  • Loading branch information
zmc committed Dec 5, 2017
1 parent 57b0cf6 commit baa711f
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions teuthology/orchestra/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import teuthology.lock.query
import teuthology.lock.util
from teuthology.config import config
from teuthology.contextutil import safe_while

from ..exceptions import ConsoleError

Expand Down Expand Up @@ -160,25 +161,18 @@ def check_power(self, state, timeout=None):
Check power. Retry if EOF encountered on power check read.
"""
timeout = timeout or self.timeout
t = 1
total = t
ta = time.time()
while total < timeout:
c = self._pexpect_spawn_ipmi('power status')
r = c.expect(['Chassis Power is {s}'.format(
s=state), pexpect.EOF, pexpect.TIMEOUT], timeout=t)
tb = time.time()
if r == 0:
return True
elif r == 1:
# keep trying if EOF is reached, first sleep for remaining
# timeout interval
if tb - ta < t:
time.sleep(t - (tb - ta))
# go around again if EOF or TIMEOUT
ta = tb
t *= 2
total += t
sleep_time = 4.0
with safe_while(
sleep=sleep_time,
tries=int(timeout / sleep_time),
_raise=False,
action='wait for power %s' % state) as proceed:
while proceed():
c = self._pexpect_spawn_ipmi('power status')
r = c.expect(['Chassis Power is {s}'.format(
s=state), pexpect.EOF, pexpect.TIMEOUT], timeout=1)
if r == 0:
return True
return False

def check_status(self, timeout=None):
Expand Down

0 comments on commit baa711f

Please sign in to comment.