From: Edward Hope-Morley Date: Wed, 31 Jul 2013 16:26:32 +0000 (+0100) Subject: Added glance_request_timeout config option. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=e5a4c752290fb35572dc5990c1688e5f9d49051f;p=openstack-build%2Fcinder-build.git Added glance_request_timeout config option. The glanceclient supports a timeout for http/https connections but this is not configurable in cinder. This patch adds a glance_request_timeout option to cinder.conf. If unset, None is applied thus allowing glanceclient to use its default value (600). Change-Id: Ic689ecb5d5ee8257964b341b5a7980d5733343dc Fixes: bug #1206992 Co-authored-by: Takahiro Shida --- diff --git a/cinder/common/config.py b/cinder/common/config.py index 32b6092a3..b042b5001 100644 --- a/cinder/common/config.py +++ b/cinder/common/config.py @@ -4,6 +4,7 @@ # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # Copyright 2012 Red Hat, Inc. +# Copyright 2013 NTT corp. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -112,6 +113,11 @@ global_opts = [ 'this may improve data throughput, eg when high network ' 'bandwidth is available and you are using already ' 'compressed image formats such as qcow2 .'), + cfg.IntOpt('glance_request_timeout', + default=None, + help='http/https timeout value for glance operations. If no ' + 'value (None) is supplied here, the glanceclient default ' + 'value is used.'), cfg.StrOpt('scheduler_topic', default='cinder-scheduler', help='the topic scheduler nodes listen on'), diff --git a/cinder/image/glance.py b/cinder/image/glance.py index f9315e6a8..0db8f76a5 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -1,6 +1,7 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2010 OpenStack LLC. +# Copyright 2013 NTT corp. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -72,6 +73,8 @@ def _create_glance_client(context, netloc, use_ssl, scheme = 'http' if CONF.auth_strategy == 'keystone': params['token'] = context.auth_token + if CONF.glance_request_timeout is not None: + params['timeout'] = CONF.glance_request_timeout endpoint = '%s://%s' % (scheme, netloc) return glanceclient.Client(str(version), endpoint, **params) diff --git a/cinder/tests/image/test_glance.py b/cinder/tests/image/test_glance.py index 9248d0f31..206aeaa57 100644 --- a/cinder/tests/image/test_glance.py +++ b/cinder/tests/image/test_glance.py @@ -19,6 +19,7 @@ import datetime import glanceclient.exc +import glanceclient.v2.client from glanceclient.v2.client import Client as glanceclient_v2 from oslo.config import cfg @@ -599,3 +600,63 @@ def _create_failing_glance_client(info): return {} return MyGlanceStubClient() + + +class TestGlanceImageServiceClient(test.TestCase): + + def setUp(self): + super(TestGlanceImageServiceClient, self).setUp() + self.context = context.RequestContext('fake', 'fake', auth_token=True) + self.stubs.Set(glance.time, 'sleep', lambda s: None) + + def test_create_glance_client(self): + self.flags(auth_strategy='keystone') + self.flags(glance_request_timeout=60) + + class MyGlanceStubClient(object): + def __init__(inst, version, *args, **kwargs): + self.assertEqual('1', version) + self.assertEqual("http://fake_host:9292", args[0]) + self.assertEqual(True, kwargs['token']) + self.assertEqual(60, kwargs['timeout']) + + self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient) + client = glance._create_glance_client(self.context, 'fake_host:9292', + False) + self.assertTrue(isinstance(client, MyGlanceStubClient)) + + def test_create_glance_client_auth_strategy_is_not_keystone(self): + self.flags(auth_strategy='noauth') + self.flags(glance_request_timeout=60) + + class MyGlanceStubClient(object): + def __init__(inst, version, *args, **kwargs): + self.assertEqual('1', version) + self.assertEqual('http://fake_host:9292', args[0]) + self.assertFalse('token' in kwargs) + self.assertEqual(60, kwargs['timeout']) + + self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient) + client = glance._create_glance_client(self.context, 'fake_host:9292', + False) + self.assertTrue(isinstance(client, MyGlanceStubClient)) + + def test_create_glance_client_glance_request_default_timeout(self): + self.flags(auth_strategy='keystone') + self.flags(glance_request_timeout=None) + + class MyGlanceStubClient(object): + def __init__(inst, version, *args, **kwargs): + self.assertEqual("1", version) + self.assertEqual("http://fake_host:9292", args[0]) + self.assertEqual(True, kwargs['token']) + self.assertFalse('timeout' in kwargs) + + self.stubs.Set(glance.glanceclient, 'Client', MyGlanceStubClient) + client = glance._create_glance_client(self.context, 'fake_host:9292', + False) + self.assertTrue(isinstance(client, MyGlanceStubClient)) + + def tearDown(self): + self.stubs.UnsetAll() + super(TestGlanceImageServiceClient, self).tearDown() diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index d91d7506b..7e4c44b1b 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -75,6 +75,10 @@ # image formats such as qcow2 . #glance_api_ssl_compression=false +# http/https timeout value for glance operations. If no value (None) is +# supplied, the glanceclient default value is used. +#glance_request_timeout=None + # the topic scheduler nodes listen on (string value) #scheduler_topic=cinder-scheduler