summaryrefslogtreecommitdiff
path: root/heatclient
diff options
context:
space:
mode:
authorSteven Hardy <shardy@redhat.com>2014-03-10 18:21:10 +0000
committerSteven Hardy <shardy@redhat.com>2014-03-10 18:21:10 +0000
commit38098938be46998b651060c81fa92a9ecad562f6 (patch)
tree46a8dc41b6b7e5c3773d5b275ccdd96dff1f29cf /heatclient
parentaa30e4642a5e71b6149dfc29821d4d85da410cc9 (diff)
downloadpython-heatclient-38098938be46998b651060c81fa92a9ecad562f6.tar.gz
Rename --timeout global option and make it work
The --timeout option doesn't work for standalone use-cases when you specify no-client-auth, and it's also confusing since it's easily misinterpreted as an option related to the heat timeouts provided to stack-create and in future stack-update. So take this opportunity to rename the option to --api-timeout, which hopefully more accurately reflects it's purpose, and don't pass a default (just let requests use the global default socket timeout) as it seems relatively unlikely users will wait for 10 minutes before pressing Ctrl-C on interactive shell requests. Change-Id: I52480f0d128735bf5f312fc88f4078f27717baf2 Partial-Bug: #1290456
Diffstat (limited to 'heatclient')
-rw-r--r--heatclient/common/http.py4
-rw-r--r--heatclient/shell.py11
-rw-r--r--heatclient/tests/test_common_http.py21
3 files changed, 32 insertions, 4 deletions
diff --git a/heatclient/common/http.py b/heatclient/common/http.py
index d59bd0c..d744e91 100644
--- a/heatclient/common/http.py
+++ b/heatclient/common/http.py
@@ -65,6 +65,7 @@ class HTTPClient(object):
self.cert_file = kwargs.get('cert_file')
self.key_file = kwargs.get('key_file')
+ self.timeout = kwargs.get('timeout')
self.ssl_connection_params = {
'ca_file': kwargs.get('ca_file'),
@@ -148,6 +149,9 @@ class HTTPClient(object):
if self.verify_cert is not None:
kwargs['verify'] = self.verify_cert
+ if self.timeout is not None:
+ kwargs['timeout'] = float(self.timeout)
+
# Since requests does not follow the RFC when doing redirection to sent
# back the same method on a redirect we are simply bypassing it. For
# example if we do a DELETE/POST/PUT on a URL and we get a 302 RFC says
diff --git a/heatclient/shell.py b/heatclient/shell.py
index b1ee0a9..1ab0073 100644
--- a/heatclient/shell.py
+++ b/heatclient/shell.py
@@ -88,9 +88,10 @@ class HeatShell(object):
' option the client looks'
' for the default system CA certificates.')
- parser.add_argument('--timeout',
- default=600,
- help='Number of seconds to wait for a response.')
+ parser.add_argument('--api-timeout',
+ help='Number of seconds to wait for an '
+ 'API response, '
+ 'defaults to system socket timeout')
parser.add_argument('--os-username',
default=utils.env('OS_USERNAME'),
@@ -364,7 +365,6 @@ class HeatShell(object):
kwargs = {
'token': token,
'insecure': args.insecure,
- 'timeout': args.timeout,
'ca_file': args.ca_file,
'cert_file': args.cert_file,
'key_file': args.key_file,
@@ -380,6 +380,9 @@ class HeatShell(object):
if not endpoint:
endpoint = self._get_endpoint(_ksclient, **kwargs)
+ if args.api_timeout:
+ kwargs['timeout'] = args.api_timeout
+
client = heat_client.Client(api_version, endpoint, **kwargs)
args.func(client, args)
diff --git a/heatclient/tests/test_common_http.py b/heatclient/tests/test_common_http.py
index e15510b..c8fd609 100644
--- a/heatclient/tests/test_common_http.py
+++ b/heatclient/tests/test_common_http.py
@@ -540,6 +540,27 @@ class HttpClientTest(testtools.TestCase):
client._http_request, "/", "GET")
self.m.VerifyAll()
+ def test_http_request_specify_timeout(self):
+ mock_conn = http.requests.request(
+ 'GET', 'http://example.com:8004',
+ allow_redirects=False,
+ headers={'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'User-Agent': 'python-heatclient'},
+ timeout=float(123))
+ mock_conn.AndReturn(
+ fakes.FakeHTTPResponse(
+ 200, 'OK',
+ {'content-type': 'application/json'},
+ '{}'))
+ # Replay, create client, assert
+ self.m.ReplayAll()
+ client = http.HTTPClient('http://example.com:8004', timeout='123')
+ resp, body = client.json_request('GET', '')
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual({}, body)
+ self.m.VerifyAll()
+
def test_get_system_ca_file(self):
chosen = '/etc/ssl/certs/ca-certificates.crt'
self.m.StubOutWithMock(os.path, 'exists')