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
This commit is contained in:
Steven Hardy 2014-03-10 18:21:10 +00:00
parent aa30e4642a
commit 38098938be
3 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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')