Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgr/dashboard: Set timeout in RestClient calls
Set a default timeout of 45 seconds to all REST client calls. This can be customized via 'ceph dashboard set-rest-requests-timeout <seconds>'. Currently the REST client is only used by the RGW controller. Signed-off-by: Volker Theile <vtheile@suse.com> (cherry picked from commit 2312839) Conflicts: doc/mgr/dashboard.rst
- Loading branch information
Showing
4 changed files
with
74 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from mock import patch | ||
from .. import mgr | ||
from ..rest_client import RestClient | ||
|
||
|
||
class RestClientTest(unittest.TestCase): | ||
def setUp(self): | ||
settings = {'REST_REQUESTS_TIMEOUT': 45} | ||
mgr.get_config.side_effect = settings.get | ||
|
||
def test_timeout_auto_set(self): | ||
with patch('requests.Session.request') as mock_request: | ||
rest_client = RestClient('localhost', 8000) | ||
rest_client.session.request('GET', '/test') | ||
mock_request.assert_called_with('GET', '/test', timeout=45) | ||
|
||
def test_timeout_auto_set_arg(self): | ||
with patch('requests.Session.request') as mock_request: | ||
rest_client = RestClient('localhost', 8000) | ||
rest_client.session.request( | ||
'GET', '/test', None, None, None, None, | ||
None, None, None) | ||
mock_request.assert_called_with( | ||
'GET', '/test', None, None, None, None, | ||
None, None, None, timeout=45) | ||
|
||
def test_timeout_no_auto_set_kwarg(self): | ||
with patch('requests.Session.request') as mock_request: | ||
rest_client = RestClient('localhost', 8000) | ||
rest_client.session.request('GET', '/test', timeout=20) | ||
mock_request.assert_called_with('GET', '/test', timeout=20) | ||
|
||
def test_timeout_no_auto_set_arg(self): | ||
with patch('requests.Session.request') as mock_request: | ||
rest_client = RestClient('localhost', 8000) | ||
rest_client.session.request( | ||
'GET', '/test', None, None, None, None, | ||
None, None, 40) | ||
mock_request.assert_called_with( | ||
'GET', '/test', None, None, None, None, | ||
None, None, 40) |