Skip to content

Commit

Permalink
Fixed retry functions with tenacity 8.5.0
Browse files Browse the repository at this point in the history
Tenacity 8.5.0 move the statistics object from func.retry.statistics to
func.statistics [0]

[0] jd/tenacity#484

Closes-Bug: #2081200
Change-Id: Ie9384effe7c306d09fcce80710236ea1770bfd5f
  • Loading branch information
gthiemonge authored and kajinamit committed Sep 19, 2024
1 parent 7974e75 commit c2807ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 9 additions & 5 deletions octavia/controller/worker/v2/tasks/compute_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,30 @@ def execute(self, amphora, passive_failure=False):
amphora_id = amphora.get(constants.ID)
compute_id = amphora[constants.COMPUTE_ID]

if self.execute.retry.statistics.get(constants.ATTEMPT_NUMBER, 1) == 1:
# tenacity 8.5.0 moves statistics from the retry object to the function
try:
retry_statistics = self.execute.statistics
except AttributeError:
retry_statistics = self.execute.retry.statistics
if retry_statistics.get(constants.ATTEMPT_NUMBER, 1) == 1:
LOG.debug('Compute delete execute for amphora with ID %s and '
'compute ID: %s', amphora_id, compute_id)
else:
LOG.warning('Retrying compute delete of %s attempt %s of %s.',
compute_id,
self.execute.retry.statistics[
constants.ATTEMPT_NUMBER],
retry_statistics[constants.ATTEMPT_NUMBER],
self.execute.retry.stop.max_attempt_number)
# Let the Taskflow engine know we are working and alive
# Don't use get with a default for 'attempt_number', we need to fail
# if that number is missing.
self.update_progress(
self.execute.retry.statistics[constants.ATTEMPT_NUMBER] /
retry_statistics[constants.ATTEMPT_NUMBER] /
self.execute.retry.stop.max_attempt_number)

try:
self.compute.delete(compute_id)
except Exception:
if (self.execute.retry.statistics[constants.ATTEMPT_NUMBER] !=
if (retry_statistics[constants.ATTEMPT_NUMBER] !=
self.execute.retry.stop.max_attempt_number):
LOG.warning('Compute delete for amphora id: %s failed. '
'Retrying.', amphora_id)
Expand Down
15 changes: 10 additions & 5 deletions octavia/controller/worker/v2/tasks/network_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,24 +906,29 @@ def execute(self, port_id, passive_failure=False):
"""Delete the network port."""
if port_id is None:
return
if self.execute.retry.statistics.get(constants.ATTEMPT_NUMBER, 1) == 1:
# tenacity 8.5.0 moves statistics from the retry object to the function
try:
retry_statistics = self.execute.statistics
except AttributeError:
retry_statistics = self.execute.retry.statistics

if retry_statistics.get(constants.ATTEMPT_NUMBER, 1) == 1:
LOG.debug("Deleting network port %s", port_id)
else:
LOG.warning('Retrying network port %s delete attempt %s of %s.',
port_id,
self.execute.retry.statistics[
constants.ATTEMPT_NUMBER],
retry_statistics[constants.ATTEMPT_NUMBER],
self.execute.retry.stop.max_attempt_number)
# Let the Taskflow engine know we are working and alive
# Don't use get with a default for 'attempt_number', we need to fail
# if that number is missing.
self.update_progress(
self.execute.retry.statistics[constants.ATTEMPT_NUMBER] /
retry_statistics[constants.ATTEMPT_NUMBER] /
self.execute.retry.stop.max_attempt_number)
try:
self.network_driver.delete_port(port_id)
except Exception:
if (self.execute.retry.statistics[constants.ATTEMPT_NUMBER] !=
if (retry_statistics[constants.ATTEMPT_NUMBER] !=
self.execute.retry.stop.max_attempt_number):
LOG.warning('Network port delete for port id: %s failed. '
'Retrying.', port_id)
Expand Down

0 comments on commit c2807ad

Please sign in to comment.