Switch from retrying to tenacity

The retrying library is no longer maintained and users are encouraged to
migrate to tenacity.

This has a small behavior change in that before we were applying an
exponential backoff to the first time a retry was needed. This no longer
happens, but retries will exponentially back off with subsequent each
retry.

Change-Id: I25ca007386a7b8ca6a7d572742334ba3d7dcbf1e
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis
2018-09-07 11:21:44 -05:00
parent d4eb4a9ba1
commit ec6fb2da52
10 changed files with 85 additions and 80 deletions

View File

@@ -23,7 +23,6 @@ from unittest import mock
import ddt
from oslo_utils import timeutils
import six
from six.moves import range
import webob.exc
import cinder
@@ -939,7 +938,7 @@ class TestRetryDecorator(test.TestCase):
def test_no_retry_required(self):
self.counter = 0
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException,
interval=2,
retries=3,
@@ -956,7 +955,7 @@ class TestRetryDecorator(test.TestCase):
def test_no_retry_required_random(self):
self.counter = 0
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException,
interval=2,
retries=3,
@@ -977,7 +976,7 @@ class TestRetryDecorator(test.TestCase):
backoff_rate = 2
retries = 3
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException,
interval,
retries,
@@ -993,7 +992,7 @@ class TestRetryDecorator(test.TestCase):
self.assertEqual('success', ret)
self.assertEqual(2, self.counter)
self.assertEqual(1, mock_sleep.call_count)
mock_sleep.assert_called_with(interval * backoff_rate)
mock_sleep.assert_called_with(interval)
def test_retries_once_random(self):
self.counter = 0
@@ -1001,7 +1000,7 @@ class TestRetryDecorator(test.TestCase):
backoff_rate = 2
retries = 3
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException,
interval,
retries,
@@ -1026,7 +1025,7 @@ class TestRetryDecorator(test.TestCase):
interval = 2
backoff_rate = 4
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException,
interval,
retries,
@@ -1040,17 +1039,17 @@ class TestRetryDecorator(test.TestCase):
self.assertEqual(retries, self.counter)
expected_sleep_arg = []
for i in range(retries):
if i > 0:
interval *= backoff_rate
interval *= (backoff_rate ** (i - 1))
expected_sleep_arg.append(float(interval))
mock_sleep.assert_has_calls(map(mock.call, expected_sleep_arg))
mock_sleep.assert_has_calls(
list(map(mock.call, expected_sleep_arg)))
def test_wrong_exception_no_retry(self):
with mock.patch.object(time, 'sleep') as mock_sleep:
with mock.patch('cinder.utils._time_sleep') as mock_sleep:
@utils.retry(exception.VolumeBackendAPIException)
def raise_unexpected_error():
raise WrongException("wrong exception")