# 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
'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'),
# 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
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)
import datetime
import glanceclient.exc
+import glanceclient.v2.client
from glanceclient.v2.client import Client as glanceclient_v2
from oslo.config import cfg
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()