]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Added glance_request_timeout config option.
authorEdward Hope-Morley <edward.hope-morley@canonical.com>
Wed, 31 Jul 2013 16:26:32 +0000 (17:26 +0100)
committerEdward Hope-Morley <edward.hope-morley@canonical.com>
Wed, 7 Aug 2013 16:00:48 +0000 (17:00 +0100)
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 <shida@intellilink.co.jp>
cinder/common/config.py
cinder/image/glance.py
cinder/tests/image/test_glance.py
etc/cinder/cinder.conf.sample

index 32b6092a37f3b38a53aea012474fe8ce976e3008..b042b50019f0053e5ff1d0dd0b4269918342463e 100644 (file)
@@ -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'),
index f9315e6a88c6bb1f9341868959e872d78f4a5b28..0db8f76a5dae7326ba6de1c8617a21a02f28a251 100644 (file)
@@ -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)
 
index 9248d0f312326dd978a2320f7117dc37f25d157f..206aeaa570d36dd4d96797c1c0998d6941c7ccc0 100644 (file)
@@ -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()
index d91d7506b6c594dfce152f06556c213f9b64c834..7e4c44b1bd62b28580104e7e5c64f43fa9af1a05 100644 (file)
 # 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