Add a new timeout option to set the HTTP Timeout

Adds a new --timeout option and check to the env
var OS_NETWORK_TIMEOUT to set the HTTP timeout used
for the request to the Neutron backend.

DocImpact

Closes-Bug: #1338932
Change-Id: I0d9687e671f68c4845af2439abfe581c6dcf020c
This commit is contained in:
Kevin Benton 2014-07-08 01:13:43 -07:00
parent d7c5104e99
commit 5db54ed301
4 changed files with 37 additions and 2 deletions

@ -64,6 +64,7 @@ class ClientManager(object):
ca_cert=None,
log_credentials=False,
service_type=None,
timeout=None
):
self._token = token
self._url = url
@ -82,6 +83,7 @@ class ClientManager(object):
self._insecure = insecure
self._ca_cert = ca_cert
self._log_credentials = log_credentials
self._timeout = timeout
return
def initialize(self):
@ -98,7 +100,8 @@ class ClientManager(object):
endpoint_type=self._endpoint_type,
insecure=self._insecure,
ca_cert=self._ca_cert,
log_credentials=self._log_credentials)
log_credentials=self._log_credentials,
timeout=self._timeout)
httpclient.authenticate()
# Populate other password flow attributes
self._token = httpclient.auth_token

@ -445,6 +445,12 @@ class NeutronShell(app.App):
default=env('OS_NETWORK_SERVICE_TYPE', default='network'),
help=_('Defaults to env[OS_NETWORK_SERVICE_TYPE] or network.'))
parser.add_argument(
'--timeout', metavar='<seconds>',
default=env('OS_NETWORK_TIMEOUT', default=None), type=float,
help=_('Timeout in seconds to wait for an HTTP response. Defaults '
'to env[OS_NETWORK_TIMEOUT] or None if not specified.'))
parser.add_argument(
'--endpoint-type', metavar='<endpoint-type>',
default=env('OS_ENDPOINT_TYPE', default='publicURL'),
@ -643,6 +649,7 @@ class NeutronShell(app.App):
endpoint_type=self.options.endpoint_type,
insecure=self.options.insecure,
ca_cert=self.options.os_cacert,
timeout=self.options.timeout,
log_credentials=True)
return

@ -129,7 +129,7 @@ class ShellTest(testtools.TestCase):
password='test', region_name='', api_version={'network': '2.0'},
auth_strategy='keystone', service_type='network',
endpoint_type='publicURL', insecure=False, ca_cert=None,
log_credentials=True)
log_credentials=True, timeout=None)
neutron_shell.run_subcommand(['quota-list'])
self.mox.ReplayAll()
cmdline = ('--os-username test '
@ -185,3 +185,26 @@ class ShellTest(testtools.TestCase):
# --endpoint-type and $OS_ENDPOINT_TYPE
namespace = parser.parse_args(['--endpoint-type=admin'])
self.assertEqual('admin', namespace.endpoint_type)
def test_timeout_option(self):
shell = openstack_shell.NeutronShell('2.0')
parser = shell.build_option_parser('descr', '2.0')
# Neither $OS_ENDPOINT_TYPE nor --endpoint-type
namespace = parser.parse_args([])
self.assertIsNone(namespace.timeout)
# --endpoint-type but not $OS_ENDPOINT_TYPE
namespace = parser.parse_args(['--timeout=50'])
self.assertEqual(50, namespace.timeout)
def test_timeout_environment_variable(self):
fixture = fixtures.EnvironmentVariable("OS_NETWORK_TIMEOUT",
"50")
self.useFixture(fixture)
shell = openstack_shell.NeutronShell('2.0')
parser = shell.build_option_parser('descr', '2.0')
namespace = parser.parse_args([])
self.assertEqual(50, namespace.timeout)

@ -63,6 +63,7 @@ class TestSSL(testtools.TestCase):
username=mox.IgnoreArg(),
user_id=mox.IgnoreArg(),
log_credentials=mox.IgnoreArg(),
timeout=mox.IgnoreArg(),
)
openstack_shell.NeutronShell.interact().AndReturn(0)
self.mox.ReplayAll()
@ -94,6 +95,7 @@ class TestSSL(testtools.TestCase):
username=mox.IgnoreArg(),
user_id=mox.IgnoreArg(),
log_credentials=mox.IgnoreArg(),
timeout=mox.IgnoreArg(),
)
openstack_shell.NeutronShell.interact().AndReturn(0)
self.mox.ReplayAll()