Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contextutil.safe_while does not sleep between tries if needed to loop infinitely #1995

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions teuthology/contextutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion teuthology/lock/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions teuthology/suite/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ 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):
m_query.list_locks.return_value = [{"arch": "arch"}]
result = util.get_arch('magna')
m_query.list_locks.assert_called_with(
machine_type="magna",
count=1
count=1, tries=1
)
assert result == "arch"

Expand Down
2 changes: 1 addition & 1 deletion teuthology/suite/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down