From 7f1968cfbd039af68c899aafe32862633902b251 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Wed, 7 Aug 2024 00:42:32 +0200 Subject: [PATCH 1/3] contextutil: sleep between tries in safe_while again This patch fixes an issue introduced within PR #1816, that when tries are < 0 (e.g. -1) there is no sleep occurred between tries. It also fixes error message, so we repot correct number of tries we've done now. Fixes: ee43f87cfe88a8155566b662750d663c1d8742ff Signed-off-by: Kyr Shatskyy --- teuthology/contextutil.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/teuthology/contextutil.py b/teuthology/contextutil.py index dd6d2d68a..8e53e5439 100644 --- a/teuthology/contextutil.py +++ b/teuthology/contextutil.py @@ -115,20 +115,20 @@ def _make_error_msg(self): msg = msg.format( action=self.action, - tries=self.counter, + tries=self.counter - 1, total=self.total_seconds, ) return msg def __call__(self): - if self.tries < 0: - return True self.counter += 1 if self.counter == 1: return True + def must_stop(): + return self.tries > 0 and self.counter > self.tries if ((self.timeout > 0 and self.total_seconds >= self.timeout) or - (self.timeout == 0 and self.counter > self.tries)): + (self.timeout == 0 and must_stop())): error_msg = self._make_error_msg() if self._raise: raise MaxWhileTries(error_msg) From 5836ffe2db39fa0ae6c6f89387150336fdd1399e Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Wed, 7 Aug 2024 00:54:00 +0200 Subject: [PATCH 2/3] suite/util: list_lock() once for get_arch() We only want to try to list_locks() for getting arch by machine_type when scheduling a suite. Otherwise we've got into an infinite loop and console log flooded with useless error messages. Signed-off-by: Kyr Shatskyy --- teuthology/suite/test/test_util.py | 4 ++-- teuthology/suite/util.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/teuthology/suite/test/test_util.py b/teuthology/suite/test/test_util.py index 20a7dcc88..daa583023 100644 --- a/teuthology/suite/test/test_util.py +++ b/teuthology/suite/test/test_util.py @@ -103,7 +103,7 @@ def test_get_branch_info(self, m_get): def test_get_arch_fail(self, m_query): m_query.list_locks.return_value = False util.get_arch('magna') - m_query.list_locks.assert_called_with(machine_type="magna", count=1) + m_query.list_locks.assert_called_with(machine_type="magna", count=1, tries=1) @patch('teuthology.lock.query') def test_get_arch_success(self, m_query): @@ -111,7 +111,7 @@ def test_get_arch_success(self, m_query): result = util.get_arch('magna') m_query.list_locks.assert_called_with( machine_type="magna", - count=1 + count=1, tries=1 ) assert result == "arch" diff --git a/teuthology/suite/util.py b/teuthology/suite/util.py index 8999f9eaf..db0cf11cb 100644 --- a/teuthology/suite/util.py +++ b/teuthology/suite/util.py @@ -263,7 +263,7 @@ def get_arch(machine_type): :returns: A string or None """ - result = teuthology.lock.query.list_locks(machine_type=machine_type, count=1) + result = teuthology.lock.query.list_locks(machine_type=machine_type, count=1, tries=1) if not result: log.warning("No machines found with machine_type %s!", machine_type) else: From 84652ff038b619876d85aeb5638e53570c10ca6b Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Wed, 7 Aug 2024 00:59:53 +0200 Subject: [PATCH 3/3] lock/query: make use of tries for list_locks() The list_locks has been updated with new argument 'tries' in PR#1816, but by unfortunate mistake hasn't been used yet. Fixes: 55886eac960cfc6f311fb4c9812311c420761793 Signed-off-by: Kyr Shatskyy --- teuthology/lock/query.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teuthology/lock/query.py b/teuthology/lock/query.py index 731f8a1b5..162f38572 100644 --- a/teuthology/lock/query.py +++ b/teuthology/lock/query.py @@ -68,7 +68,7 @@ def list_locks(keyed_by_name=False, tries=10, **kwargs): with safe_while( sleep=1, increment=0.5, - tries=-1, + tries=tries, action='list_locks' ) as proceed: while proceed():