-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make openstack retry more configurable
- Loading branch information
Showing
3 changed files
with
113 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
from staffeln.common import auth | ||
from staffeln.common import openstack as s_openstack | ||
from staffeln import conf | ||
from staffeln.tests import base | ||
|
||
class OpenstackSDKTest(base.TestCase): | ||
|
@@ -23,20 +24,35 @@ def setUp(self): | |
'get_backup_gigabytes_quota' | ||
] | ||
for i in func_list: | ||
getattr(self.openstack, i).retry.sleep = self.m_sleep # pylint: disable=E1101 | ||
getattr(self.openstack, i).retry.stop = tenacity.stop_after_attempt(2) # pylint: disable=E1101 | ||
|
||
self.fake_user = mock.MagicMock(id='foo', email='[email protected]') | ||
self.fake_volume = mock.MagicMock(id='fake_volume') | ||
self.fake_backup = mock.MagicMock(id='fake_backup') | ||
self.fake_role_assignment = mock.MagicMock(user='foo') | ||
self.fake_role_assignment2 = mock.MagicMock(user={'id': 'bar'}) | ||
|
||
def _test_http_error(self, m_func, retry_func, status_code, call_count=1, **kwargs): | ||
m_func.side_effect=openstack_exc.HttpException(http_status=status_code) | ||
exc = self.assertRaises(openstack_exc.HttpException, getattr(self.openstack, retry_func), **kwargs) | ||
getattr(self.openstack, i).retry.sleep = ( # pylint: disable=E1101 | ||
self.m_sleep | ||
) | ||
getattr(self.openstack, i).retry.stop = ( # pylint: disable=E1101 | ||
tenacity.stop_after_attempt(2) | ||
) | ||
|
||
self.fake_user = mock.MagicMock(id="foo", email="[email protected]") | ||
self.fake_volume = mock.MagicMock(id="fake_volume") | ||
self.fake_backup = mock.MagicMock(id="fake_backup") | ||
self.fake_role_assignment = mock.MagicMock(user="foo") | ||
self.fake_role_assignment2 = mock.MagicMock(user={"id": "bar"}) | ||
|
||
def _test_http_error( | ||
self, m_func, retry_func, status_code, call_count=1, | ||
**kwargs | ||
): | ||
m_func.side_effect = openstack_exc.HttpException( | ||
http_status=status_code | ||
) | ||
exc = self.assertRaises( | ||
openstack_exc.HttpException, | ||
getattr(self.openstack, retry_func), | ||
**kwargs, | ||
) | ||
self.assertEqual(status_code, exc.status_code) | ||
if status_code != 404: | ||
skip_retry_codes = conf.CONF.openstack.skip_retry_codes.replace( | ||
' ', '').split(',') | ||
if str(status_code) not in skip_retry_codes: | ||
if call_count == 1: | ||
self.m_sleep.assert_called_once_with(1.0) | ||
else: | ||
|
@@ -57,6 +73,20 @@ def test_get_servers(self): | |
def test_get_servers_non_http_error(self): | ||
self._test_non_http_error(self.m_c.compute.servers, 'get_servers') | ||
|
||
def test_get_servers_conf_skip_http_error(self): | ||
conf.CONF.set_override('skip_retry_codes', '403,', 'openstack') | ||
self._test_http_error( | ||
self.m_c.compute.servers, "get_servers", status_code=403 | ||
) | ||
self.assertEqual('403,', conf.CONF.openstack.skip_retry_codes) | ||
|
||
def test_get_servers_conf_skip_http_error_not_hit(self): | ||
conf.CONF.set_override('skip_retry_codes', '403,', 'openstack') | ||
self._test_http_error( | ||
self.m_c.compute.servers, "get_servers", status_code=404 | ||
) | ||
self.assertEqual('403,', conf.CONF.openstack.skip_retry_codes) | ||
|
||
def test_get_servers_404_http_error(self): | ||
self._test_http_error(self.m_c.compute.servers, 'get_servers', status_code=404) | ||
|
||
|