From: Zack Cerza Date: Tue, 5 Dec 2017 17:53:26 +0000 (-0700) Subject: PhysicalConsole: replace retry mechanism X-Git-Tag: 1.1.0~372^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=baa711fcb38a3d260a5ec3fd257e7363a7c10767;p=teuthology.git PhysicalConsole: replace retry mechanism It was buggy and unreadable. Use safe_while. Signed-off-by: Zack Cerza --- diff --git a/teuthology/orchestra/console.py b/teuthology/orchestra/console.py index e10c08c80..c15e02b0f 100644 --- a/teuthology/orchestra/console.py +++ b/teuthology/orchestra/console.py @@ -9,6 +9,7 @@ import time import teuthology.lock.query import teuthology.lock.util from teuthology.config import config +from teuthology.contextutil import safe_while from ..exceptions import ConsoleError @@ -160,25 +161,18 @@ class PhysicalConsole(): 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):