Skip to content

Commit

Permalink
Added glance_request_timeout config option.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dosaboy and shida2022 committed Aug 7, 2013
1 parent f2c91c9 commit e5a4c75
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cinder/common/config.py
Expand Up @@ -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
Expand Down Expand Up @@ -112,6 +113,11 @@ def _get_my_ip():
'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'),
Expand Down
3 changes: 3 additions & 0 deletions 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
Expand Down Expand Up @@ -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)

Expand Down
61 changes: 61 additions & 0 deletions cinder/tests/image/test_glance.py
Expand Up @@ -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

Expand Down Expand Up @@ -599,3 +600,63 @@ def get(self, image_id):
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()
4 changes: 4 additions & 0 deletions etc/cinder/cinder.conf.sample
Expand Up @@ -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

Expand Down

0 comments on commit e5a4c75

Please sign in to comment.