Deprecate glance_* configuration settings

Create a new section in the configuration file called 'glance'.
Move all of the glance_* configuration settings to this section.

DocImpact

The table below has the changes:

+---------------------------------+----------------------------+
| 'DEFAULT' Section               | 'glance' Section           |
|---------------------------------|----------------------------|
| glance_host                     | host                       |
| glance_port                     | port                       |
| glance_protocol                 | protocol                   |
| glance_api_servers              | api_servers                |
| glance_api_insecure             | api_insecure               |
| glance_num_retries              | num_retries                |
| allowed_direct_url_schemes      | allowed_direct_url_schemes |
+---------------------------------+----------------------------+

UpgradeImpact
The changes are backward compatible.

Change-Id: I829cf006f7e7c53a36f5e12b40f60f875fe8f331
This commit is contained in:
Gary Kotton 2014-06-17 07:20:18 -07:00
parent d239e93858
commit 4b6e75b5f8
7 changed files with 80 additions and 63 deletions

View File

@ -40,49 +40,62 @@ from nova import utils
glance_opts = [
cfg.StrOpt('glance_host',
cfg.StrOpt('host',
default='$my_ip',
help='Default glance hostname or IP address'),
cfg.IntOpt('glance_port',
help='Default glance hostname or IP address',
deprecated_group='DEFAULT',
deprecated_name='glance_host'),
cfg.IntOpt('port',
default=9292,
help='Default glance port'),
cfg.StrOpt('glance_protocol',
help='Default glance port',
deprecated_group='DEFAULT',
deprecated_name='glance_port'),
cfg.StrOpt('protocol',
default='http',
help='Default protocol to use when connecting to glance. '
'Set to https for SSL.'),
cfg.ListOpt('glance_api_servers',
default=['$glance_host:$glance_port'],
'Set to https for SSL.',
deprecated_group='DEFAULT',
deprecated_name='glance_protocol'),
cfg.ListOpt('api_servers',
help='A list of the glance api servers available to nova. '
'Prefix with https:// for ssl-based glance api servers. '
'([hostname|ip]:port)'),
cfg.BoolOpt('glance_api_insecure',
'([hostname|ip]:port)',
deprecated_group='DEFAULT',
deprecated_name='glance_api_servers'),
cfg.BoolOpt('api_insecure',
default=False,
help='Allow to perform insecure SSL (https) requests to '
'glance'),
cfg.IntOpt('glance_num_retries',
'glance',
deprecated_group='DEFAULT',
deprecated_name='glance_api_insecure'),
cfg.IntOpt('num_retries',
default=0,
help='Number of retries when downloading an image from glance'),
help='Number of retries when downloading an image from glance',
deprecated_group='DEFAULT',
deprecated_name='glance_num_retries'),
cfg.ListOpt('allowed_direct_url_schemes',
default=[],
help='A list of url scheme that can be downloaded directly '
'via the direct_url. Currently supported schemes: '
'[file].'),
'[file].',
deprecated_group='DEFAULT'),
]
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.register_opts(glance_opts)
# glance_opts options in the DEFAULT group were deprecated in Juno
CONF.register_opts(glance_opts, 'glance')
CONF.import_opt('auth_strategy', 'nova.api.auth')
CONF.import_opt('my_ip', 'nova.netconf')
def generate_glance_url():
"""Generate the URL to glance."""
glance_host = CONF.glance_host
glance_host = CONF.glance.host
if utils.is_valid_ipv6(glance_host):
glance_host = '[%s]' % glance_host
return "%s://%s:%d" % (CONF.glance_protocol, glance_host,
CONF.glance_port)
return "%s://%s:%d" % (CONF.glance.protocol, glance_host,
CONF.glance.port)
def generate_image_url(image_ref):
@ -123,7 +136,7 @@ def _create_glance_client(context, host, port, use_ssl, version=1):
if use_ssl:
scheme = 'https'
# https specific params
params['insecure'] = CONF.glance_api_insecure
params['insecure'] = CONF.glance.api_insecure
params['ssl_compression'] = False
else:
scheme = 'http'
@ -142,12 +155,16 @@ def _create_glance_client(context, host, port, use_ssl, version=1):
def get_api_servers():
"""Shuffle a list of CONF.glance_api_servers and return an iterator
"""Shuffle a list of CONF.glance.api_servers and return an iterator
that will cycle through the list, looping around to the beginning
if necessary.
"""
api_servers = []
for api_server in CONF.glance_api_servers:
configured_servers = (['%s:%s' % (CONF.glance.host, CONF.glance.port)]
if CONF.glance.api_servers is None
else CONF.glance.api_servers)
for api_server in configured_servers:
if '//' not in api_server:
api_server = 'http://' + api_server
o = urlparse.urlparse(api_server)
@ -195,12 +212,12 @@ class GlanceClientWrapper(object):
def call(self, context, version, method, *args, **kwargs):
"""Call a glance client method. If we get a connection error,
retry the request according to CONF.glance_num_retries.
retry the request according to CONF.glance.num_retries.
"""
retry_excs = (glanceclient.exc.ServiceUnavailable,
glanceclient.exc.InvalidEndpoint,
glanceclient.exc.CommunicationError)
num_attempts = 1 + CONF.glance_num_retries
num_attempts = 1 + CONF.glance.num_retries
for attempt in xrange(1, num_attempts + 1):
client = self.client or self._create_onetime_client(context,
@ -239,7 +256,7 @@ class GlanceImageService(object):
download_modules = image_xfers.load_transfer_modules()
for scheme, mod in download_modules.iteritems():
if scheme not in CONF.allowed_direct_url_schemes:
if scheme not in CONF.glance.allowed_direct_url_schemes:
continue
try:
@ -289,7 +306,7 @@ class GlanceImageService(object):
def download(self, context, image_id, data=None, dst_path=None):
"""Calls out to Glance for data and writes data."""
if CONF.allowed_direct_url_schemes and dst_path is not None:
if CONF.glance.allowed_direct_url_schemes and dst_path is not None:
locations = _get_locations(self._client, context, image_id)
for entry in locations:
loc_url = entry['url']

View File

@ -79,7 +79,7 @@ class ServerActionsControllerTest(test.TestCase):
def setUp(self):
super(ServerActionsControllerTest, self).setUp()
CONF.set_override('glance_host', 'localhost')
CONF.set_override('host', 'localhost', group='glance')
self.stubs.Set(db, 'instance_get_by_uuid',
fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
host='fake_host'))

View File

@ -193,7 +193,7 @@ class ServersControllerTest(ControllerTest):
def setUp(self):
super(ServersControllerTest, self).setUp()
CONF.set_override('glance_host', 'localhost')
CONF.set_override('host', 'localhost', group='glance')
def test_requested_networks_prefix(self):
uuid = 'br-00000000-0000-0000-0000-000000000000'
@ -2552,7 +2552,7 @@ class ServersViewBuilderTest(test.TestCase):
def setUp(self):
super(ServersViewBuilderTest, self).setUp()
CONF.set_override('glance_host', 'localhost')
CONF.set_override('host', 'localhost', group='glance')
self.flags(use_ipv6=True)
db_inst = fakes.stub_instance(
id=1,

View File

@ -197,17 +197,17 @@ class TestGlanceImageService(test.NoDBTestCase):
writer = NullWriter()
# When retries are disabled, we should get an exception
self.flags(glance_num_retries=0)
self.flags(num_retries=0, group='glance')
self.assertRaises(exception.GlanceConnectionFailed,
service.download, self.context, image_id, data=writer)
# Now lets enable retries. No exception should happen now.
tries = [0]
self.flags(glance_num_retries=1)
self.flags(num_retries=1, group='glance')
service.download(self.context, image_id, data=writer)
def test_download_file_url(self):
self.flags(allowed_direct_url_schemes=['file'])
self.flags(allowed_direct_url_schemes=['file'], group='glance')
class MyGlanceStubClient(glance_stubs.StubGlanceClient):
"""A client that returns a file url."""
@ -264,7 +264,7 @@ class TestGlanceImageService(test.NoDBTestCase):
image_id = 1 # doesn't matter
client = MyGlanceStubClient()
self.flags(allowed_direct_url_schemes=['file'])
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
service = self._create_image_service(client)
#NOTE(Jbresnah) The following options must be added after the module
@ -304,7 +304,7 @@ class TestGlanceImageService(test.NoDBTestCase):
image_id = 1 # doesn't matter
client = MyGlanceStubClient()
self.flags(allowed_direct_url_schemes=['file'])
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
service = self._create_image_service(client)
#NOTE(Jbresnah) The following options must be added after the module
@ -345,7 +345,7 @@ class TestGlanceImageService(test.NoDBTestCase):
self.copy_called = True
self.stubs.Set(lv_utils, 'copy_image', _fake_copyfile)
self.flags(allowed_direct_url_schemes=['file'])
self.flags(allowed_direct_url_schemes=['file'], group='glance')
self.flags(group='image_file_url', filesystems=['gluster'])
image_id = 1 # doesn't matter
client = MyGlanceStubClient()
@ -372,10 +372,10 @@ class TestGlanceImageService(test.NoDBTestCase):
self.data_called = True
return "someData"
self.flags(allowed_direct_url_schemes=['applesauce'])
self.flags(allowed_direct_url_schemes=['applesauce'], group='glance')
self.mox.StubOutWithMock(lv_utils, 'copy_image')
self.flags(allowed_direct_url_schemes=['file'])
self.flags(allowed_direct_url_schemes=['file'], group='glance')
image_id = 1 # doesn't matter
client = MyGlanceStubClient()
service = self._create_image_service(client)
@ -1023,8 +1023,8 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
def setUp(self):
super(TestGlanceClientWrapper, self).setUp()
# host1 has no scheme, which is http by default
self.flags(glance_api_servers=['host1:9292', 'https://host2:9293',
'http://host3:9294'])
self.flags(api_servers=['host1:9292', 'https://host2:9293',
'http://host3:9294'], group='glance')
# Make the test run fast
def _fake_sleep(secs):
@ -1059,7 +1059,7 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
glance._create_glance_client(ctxt, fake_host, fake_port, fake_use_ssl)
def test_static_client_without_retries(self):
self.flags(glance_num_retries=0)
self.flags(num_retries=0, group='glance')
ctxt = context.RequestContext('fake', 'fake')
fake_host = 'host4'
@ -1084,7 +1084,7 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
self.assertEqual(info['num_calls'], 1)
def test_default_client_without_retries(self):
self.flags(glance_num_retries=0)
self.flags(num_retries=0, group='glance')
ctxt = context.RequestContext('fake', 'fake')
@ -1129,7 +1129,7 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
self.assertEqual(info['num_calls'], 1)
def test_static_client_with_retries(self):
self.flags(glance_num_retries=1)
self.flags(num_retries=1, group='glance')
ctxt = context.RequestContext('fake', 'fake')
fake_host = 'host4'
@ -1153,7 +1153,7 @@ class TestGlanceClientWrapper(test.NoDBTestCase):
self.assertEqual(info['num_calls'], 2)
def test_default_client_with_retries(self):
self.flags(glance_num_retries=1)
self.flags(num_retries=1, group='glance')
ctxt = context.RequestContext('fake', 'fake')
@ -1207,30 +1207,30 @@ class TestGlanceUrl(test.NoDBTestCase):
def test_generate_glance_http_url(self):
generated_url = glance.generate_glance_url()
glance_host = CONF.glance_host
glance_host = CONF.glance.host
# ipv6 address, need to wrap it with '[]'
if utils.is_valid_ipv6(glance_host):
glance_host = '[%s]' % glance_host
http_url = "http://%s:%d" % (glance_host, CONF.glance_port)
http_url = "http://%s:%d" % (glance_host, CONF.glance.port)
self.assertEqual(generated_url, http_url)
def test_generate_glance_https_url(self):
self.flags(glance_protocol="https")
self.flags(protocol="https", group='glance')
generated_url = glance.generate_glance_url()
glance_host = CONF.glance_host
glance_host = CONF.glance.host
# ipv6 address, need to wrap it with '[]'
if utils.is_valid_ipv6(glance_host):
glance_host = '[%s]' % glance_host
https_url = "https://%s:%d" % (glance_host, CONF.glance_port)
https_url = "https://%s:%d" % (glance_host, CONF.glance.port)
self.assertEqual(generated_url, https_url)
class TestGlanceApiServers(test.TestCase):
def test_get_ipv4_api_servers(self):
self.flags(glance_api_servers=['10.0.1.1:9292',
'https://10.0.0.1:9293',
'http://10.0.2.2:9294'])
self.flags(api_servers=['10.0.1.1:9292',
'https://10.0.0.1:9293',
'http://10.0.2.2:9294'], group='glance')
glance_host = ['10.0.1.1', '10.0.0.1',
'10.0.2.2']
api_servers = glance.get_api_servers()
@ -1244,9 +1244,10 @@ class TestGlanceApiServers(test.TestCase):
# Python 2.6 can not parse ipv6 address correctly
@testtools.skipIf(sys.version_info < (2, 7), "py27 or greater only")
def test_get_ipv6_api_servers(self):
self.flags(glance_api_servers=['[2001:2012:1:f101::1]:9292',
'https://[2010:2013:1:f122::1]:9293',
'http://[2001:2011:1:f111::1]:9294'])
self.flags(api_servers=['[2001:2012:1:f101::1]:9292',
'https://[2010:2013:1:f122::1]:9293',
'http://[2001:2011:1:f111::1]:9294'],
group='glance')
glance_host = ['2001:2012:1:f101::1', '2010:2013:1:f122::1',
'2001:2011:1:f111::1']
api_servers = glance.get_api_servers()

View File

@ -33,9 +33,9 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
super(TestGlanceStore, self).setUp()
self.store = glance.GlanceStore()
self.flags(glance_host='1.1.1.1',
glance_port=123,
glance_api_insecure=False)
self.flags(host='1.1.1.1',
port=123,
api_insecure=False, group='glance')
self.flags(connection_url='test_url',
connection_password='test_pass',
group='xenserver')
@ -99,7 +99,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
mock_sleep, mock_shuffle,
mock_make_uuid_stack):
params = self._get_download_params()
self.flags(glance_num_retries=2)
self.flags(num_retries=2, group='glance')
params.pop("glance_port")
params.pop("glance_host")
@ -118,7 +118,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
glance_api_servers = ['10.0.1.1:9292',
'http://10.0.0.1:9293']
self.flags(glance_api_servers=glance_api_servers)
self.flags(api_servers=glance_api_servers, group='glance')
with (mock.patch.object(self.session, 'call_plugin_serialized')
) as mock_call_plugin_serialized:
@ -181,7 +181,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
self.mox.VerifyAll()
def test_upload_image_retries_then_raises_exception(self):
self.flags(glance_num_retries=2)
self.flags(num_retries=2, group='glance')
params = self._get_upload_params()
self.mox.StubOutWithMock(self.session, 'call_plugin_serialized')
@ -205,7 +205,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB):
self.mox.VerifyAll()
def test_upload_image_retries_on_signal_exception(self):
self.flags(glance_num_retries=2)
self.flags(num_retries=2, group='glance')
params = self._get_upload_params()
self.mox.StubOutWithMock(self.session, 'call_plugin_serialized')

View File

@ -21,7 +21,7 @@ from nova import utils
from nova.virt.xenapi import vm_utils
CONF = cfg.CONF
CONF.import_opt('glance_num_retries', 'nova.image.glance')
CONF.import_opt('num_retries', 'nova.image.glance', group='glance')
class GlanceStore(object):
@ -36,7 +36,7 @@ class GlanceStore(object):
return g_host
return session.call_plugin_serialized_with_retry(
'glance', fn, CONF.glance_num_retries, pick_glance, **params)
'glance', fn, CONF.glance.num_retries, pick_glance, **params)
def _make_params(self, context, session, image_id):
return {'image_id': image_id,

View File

@ -117,7 +117,6 @@ CONF = cfg.CONF
CONF.register_opts(xenapi_vm_utils_opts, 'xenserver')
CONF.import_opt('default_ephemeral_format', 'nova.virt.driver')
CONF.import_opt('use_cow_images', 'nova.virt.driver')
CONF.import_opt('glance_num_retries', 'nova.image.glance')
CONF.import_opt('use_ipv6', 'nova.netconf')
XENAPI_POWER_STATE = {