From b90f2bb4fcb3f980644a952543770684c8aa3b8c Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Wed, 30 Mar 2016 12:50:38 -0400 Subject: [PATCH] remove glance deprecated config This removes the very old glance config options which were deprecated in I9054bcfb7f5a4a31f0bbfd770c00c767f3d165ba in favor of glance.api_servers config option. This is required to clear out any default glance servers so that we could pull from the service catalog as a default in the future. Change-Id: Ie2d767c4422ef339d6dcb826f3c8ba3c7cf79f85 --- nova/image/glance.py | 42 +++------------ .../api/openstack/compute/test_disk_config.py | 2 + .../api/openstack/compute/test_image_size.py | 1 + .../unit/api/openstack/compute/test_images.py | 1 + .../openstack/compute/test_server_actions.py | 3 +- .../api/openstack/compute/test_serversV21.py | 7 +-- nova/tests/unit/compute/test_compute_mgr.py | 1 + nova/tests/unit/compute/test_compute_utils.py | 1 + nova/tests/unit/image/fake.py | 3 ++ nova/tests/unit/image/test_glance.py | 54 +------------------ nova/tests/unit/test_notifications.py | 2 + .../unit/virt/xenapi/image/test_glance.py | 6 +-- nova/tests/unit/virt/xenapi/test_vm_utils.py | 1 + .../rm_glance_opts-360c94ac27328dc9.yaml | 7 +++ 14 files changed, 32 insertions(+), 99 deletions(-) create mode 100644 releasenotes/notes/rm_glance_opts-360c94ac27328dc9.yaml diff --git a/nova/image/glance.py b/nova/image/glance.py index 6567608fd280..c30fe6edc335 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -33,7 +33,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_service import sslutils from oslo_utils import excutils -from oslo_utils import netutils from oslo_utils import timeutils import six from six.moves import range @@ -47,28 +46,9 @@ from nova import signature_utils glance_opts = [ - cfg.StrOpt('host', - default='$my_ip', - # TODO(sdague): remove in N - deprecated_for_removal=True, - help='DEPRECATED: Glance server hostname or IP address. ' - 'Use the "api_servers" option instead.'), - cfg.IntOpt('port', - default=9292, - min=1, - max=65535, - # TODO(sdague): remove in N - deprecated_for_removal=True, - help='DEPRECATED: Glance server port. Use the "api_servers" ' - 'option instead.'), - cfg.StrOpt('protocol', - default='http', - choices=('http', 'https'), - # TODO(sdague): remove in N - deprecated_for_removal=True, - help='DEPRECATED: Protocol to use when connecting to glance. ' - 'Set to https for SSL. Use the "api_servers" option ' - 'instead.'), + # NOTE(sdague): there is intentionally no default here. This + # requires configuration. Eventually this will come from the + # service catalog, however we don't have a good path there atm. cfg.ListOpt('api_servers', help=''' A list of the glance api servers endpoints available to nova. These @@ -98,18 +78,13 @@ LOG = logging.getLogger(__name__) CONF = cfg.CONF CONF.register_opts(glance_opts, 'glance') CONF.import_opt('auth_strategy', 'nova.api.auth') -CONF.import_opt('my_ip', 'nova.netconf') supported_glance_versions = (1, 2) def generate_glance_url(): - """Generate the URL to glance.""" - glance_host = CONF.glance.host - if netutils.is_valid_ipv6(glance_host): - glance_host = '[%s]' % glance_host - return "%s://%s:%d" % (CONF.glance.protocol, glance_host, - CONF.glance.port) + """Return a random glance url from the api servers we know about.""" + return next(get_api_servers()) def generate_image_url(image_ref): @@ -187,13 +162,10 @@ def get_api_servers(): """ api_servers = [] - configured_servers = ([generate_glance_url()] - if CONF.glance.api_servers is None - else CONF.glance.api_servers) - for api_server in configured_servers: + for api_server in CONF.glance.api_servers: if '//' not in api_server: api_server = 'http://' + api_server - # NOTE(sdague): remove in N. + # NOTE(sdague): remove in O. LOG.warning( _LW("No protocol specified in for api_server '%s', " "please update [glance] api_servers with fully " diff --git a/nova/tests/unit/api/openstack/compute/test_disk_config.py b/nova/tests/unit/api/openstack/compute/test_disk_config.py index 8b49f26b3bce..08f8fb7b1a93 100644 --- a/nova/tests/unit/api/openstack/compute/test_disk_config.py +++ b/nova/tests/unit/api/openstack/compute/test_disk_config.py @@ -185,6 +185,8 @@ class DiskConfigTestCaseV21(test.TestCase): self.assertDiskConfig(server_dict, expected) def test_show_image(self): + self.flags(group='glance', api_servers=['http://localhost:9292']) + req = fakes.HTTPRequest.blank( '/fake/images/a440c04b-79fa-479c-bed1-0b816eaec379') res = req.get_response(self.app) diff --git a/nova/tests/unit/api/openstack/compute/test_image_size.py b/nova/tests/unit/api/openstack/compute/test_image_size.py index 48b92d8d4152..381181adab7d 100644 --- a/nova/tests/unit/api/openstack/compute/test_image_size.py +++ b/nova/tests/unit/api/openstack/compute/test_image_size.py @@ -80,6 +80,7 @@ class ImageSizeTestV21(test.NoDBTestCase): self.stubs.Set(glance.GlanceImageService, 'detail', fake_detail) self.flags(osapi_compute_extension=['nova.api.openstack.compute' '.contrib.image_size.Image_size']) + self.flags(api_servers=['http://localhost:9292'], group='glance') def _make_request(self, url): req = webob.Request.blank(url) diff --git a/nova/tests/unit/api/openstack/compute/test_images.py b/nova/tests/unit/api/openstack/compute/test_images.py index e49cb2f62355..a74e53c3c380 100644 --- a/nova/tests/unit/api/openstack/compute/test_images.py +++ b/nova/tests/unit/api/openstack/compute/test_images.py @@ -51,6 +51,7 @@ class ImagesControllerTestV21(test.NoDBTestCase): def setUp(self): """Run before each test.""" super(ImagesControllerTestV21, self).setUp() + self.flags(api_servers=['http://localhost:9292'], group='glance') fakes.stub_out_networking(self) fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_key_pair_funcs(self.stubs) diff --git a/nova/tests/unit/api/openstack/compute/test_server_actions.py b/nova/tests/unit/api/openstack/compute/test_server_actions.py index d6a7817e5746..29b3f587d1f7 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_server_actions.py @@ -83,8 +83,7 @@ class ServerActionsControllerTestV21(test.TestCase): def setUp(self): super(ServerActionsControllerTestV21, self).setUp() - - CONF.set_override('host', 'localhost', group='glance') + self.flags(group='glance', api_servers=['http://localhost:9292']) self.stub_out('nova.db.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, host='fake_host')) diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index 362f30c6117e..6da4a8512ded 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -207,6 +207,7 @@ class ControllerTest(test.TestCase): lambda api, *a, **k: return_server(*a, **k)) self.stub_out('nova.db.instance_update_and_get_original', instance_update_and_get_original) + self.flags(group='glance', api_servers=['http://localhost:9292']) ext_info = extension_info.LoadedExtensionInfo() self.controller = servers.ServersController(extension_info=ext_info) @@ -219,10 +220,6 @@ class ControllerTest(test.TestCase): class ServersControllerTest(ControllerTest): wsgi_api_version = os_wsgi.DEFAULT_API_VERSION - def setUp(self): - super(ServersControllerTest, self).setUp() - CONF.set_override('host', 'localhost', group='glance') - def req(self, url, use_admin_context=False): return fakes.HTTPRequest.blank(url, use_admin_context=use_admin_context, @@ -3442,8 +3439,8 @@ class ServersViewBuilderTest(test.TestCase): def setUp(self): super(ServersViewBuilderTest, self).setUp() - CONF.set_override('host', 'localhost', group='glance') self.flags(use_ipv6=True) + self.flags(group='glance', api_servers=['http://localhost:9292']) nw_cache_info = self._generate_nw_cache_info() db_inst = fakes.stub_instance( id=1, diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index eac8d8b81d87..7ed7aedfd0e8 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -4800,6 +4800,7 @@ class ComputeManagerInstanceUsageAuditTestCase(test.TestCase): def setUp(self): super(ComputeManagerInstanceUsageAuditTestCase, self).setUp() self.flags(use_local=True, group='conductor') + self.flags(group='glance', api_servers=['http://localhost:9292']) self.flags(instance_usage_audit=True) @mock.patch('nova.objects.TaskLog') diff --git a/nova/tests/unit/compute/test_compute_utils.py b/nova/tests/unit/compute/test_compute_utils.py index 402be955d6a1..29aba3918920 100644 --- a/nova/tests/unit/compute/test_compute_utils.py +++ b/nova/tests/unit/compute/test_compute_utils.py @@ -409,6 +409,7 @@ class UsageInfoTestCase(test.TestCase): def fake_show(meh, context, id, **kwargs): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} + self.flags(group='glance', api_servers=['http://localhost:9292']) self.stubs.Set(nova.tests.unit.image.fake._FakeImageService, 'show', fake_show) fake_network.set_stub_network_methods(self) diff --git a/nova/tests/unit/image/fake.py b/nova/tests/unit/image/fake.py index ebe624ab5415..ab486597645a 100644 --- a/nova/tests/unit/image/fake.py +++ b/nova/tests/unit/image/fake.py @@ -25,6 +25,7 @@ from oslo_log import log as logging from nova.compute import arch import nova.conf from nova import exception +from nova.tests import fixtures as nova_fixtures CONF = nova.conf.CONF LOG = logging.getLogger(__name__) @@ -258,4 +259,6 @@ def stub_out_image_service(test): lambda x, y: (image_service, y)) test.stub_out('nova.image.glance.get_default_image_service', lambda: image_service) + test.useFixture(nova_fixtures.ConfPatcher( + group="glance", api_servers=['http://localhost:9292'])) return image_service diff --git a/nova/tests/unit/image/test_glance.py b/nova/tests/unit/image/test_glance.py index 515b4ebddf89..b0c339803047 100644 --- a/nova/tests/unit/image/test_glance.py +++ b/nova/tests/unit/image/test_glance.py @@ -22,7 +22,6 @@ import glanceclient.exc import mock from oslo_config import cfg from oslo_service import sslutils -from oslo_utils import netutils import six import testtools @@ -189,11 +188,9 @@ class TestGetImageService(test.NoDBTestCase): class TestCreateGlanceClient(test.NoDBTestCase): - @mock.patch('oslo_utils.netutils.is_valid_ipv6') @mock.patch('glanceclient.Client') - def test_headers_passed_glanceclient(self, init_mock, ipv6_mock): + def test_headers_passed_glanceclient(self, init_mock): self.flags(auth_strategy='keystone') - ipv6_mock.return_value = False auth_token = 'token' ctx = context.RequestContext('fake', 'fake', auth_token=auth_token) @@ -212,7 +209,6 @@ class TestCreateGlanceClient(test.NoDBTestCase): **expected_params) # Test the version is properly passed to glanceclient. - ipv6_mock.reset_mock() init_mock.reset_mock() expected_endpoint = 'http://host4:9295' @@ -230,11 +226,8 @@ class TestCreateGlanceClient(test.NoDBTestCase): **expected_params) # Test that the IPv6 bracketization adapts the endpoint properly. - ipv6_mock.reset_mock() init_mock.reset_mock() - ipv6_mock.return_value = True - expected_endpoint = 'http://[host4]:9295' glance._glanceclient_from_endpoint(ctx, expected_endpoint) init_mock.assert_called_once_with('1', expected_endpoint, @@ -1363,28 +1356,6 @@ class TestDelete(test.NoDBTestCase): mock.sentinel.image_id) -class TestGlanceUrl(test.NoDBTestCase): - - def test_generate_glance_http_url(self): - generated_url = glance.generate_glance_url() - glance_host = CONF.glance.host - # ipv6 address, need to wrap it with '[]' - if netutils.is_valid_ipv6(glance_host): - glance_host = '[%s]' % glance_host - 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(protocol="https", group='glance') - generated_url = glance.generate_glance_url() - glance_host = CONF.glance.host - # ipv6 address, need to wrap it with '[]' - if netutils.is_valid_ipv6(glance_host): - glance_host = '[%s]' % glance_host - https_url = "https://%s:%d" % (glance_host, CONF.glance.port) - self.assertEqual(generated_url, https_url) - - class TestGlanceApiServers(test.NoDBTestCase): def test_get_api_servers(self): @@ -1404,29 +1375,6 @@ class TestGlanceApiServers(test.NoDBTestCase): break -class TestGlanceNoApiServers(test.NoDBTestCase): - def test_get_api_server_no_server(self): - self.flags(group='glance', - host="10.0.0.1", - port=9292) - api_servers = glance.get_api_servers() - self.assertEqual("http://10.0.0.1:9292", next(api_servers)) - - self.flags(group='glance', - host="10.0.0.1", - protocol="https", - port=9292) - api_servers = glance.get_api_servers() - self.assertEqual("https://10.0.0.1:9292", next(api_servers)) - - self.flags(group='glance', - host="f000::c0de", - protocol="https", - port=9292) - api_servers = glance.get_api_servers() - self.assertEqual("https://[f000::c0de]:9292", next(api_servers)) - - class TestUpdateGlanceImage(test.NoDBTestCase): @mock.patch('nova.image.glance.GlanceImageService') def test_start(self, mock_glance_image_service): diff --git a/nova/tests/unit/test_notifications.py b/nova/tests/unit/test_notifications.py index 83f2d3cbb46a..3d9552eb1b75 100644 --- a/nova/tests/unit/test_notifications.py +++ b/nova/tests/unit/test_notifications.py @@ -59,6 +59,8 @@ class NotificationsTestCase(test.TestCase): notify_on_state_change="vm_and_task_state", host='testhost') + self.flags(api_servers=['http://localhost:9292'], group='glance') + self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) diff --git a/nova/tests/unit/virt/xenapi/image/test_glance.py b/nova/tests/unit/virt/xenapi/image/test_glance.py index ae78d70b9542..69c0197eb90a 100644 --- a/nova/tests/unit/virt/xenapi/image/test_glance.py +++ b/nova/tests/unit/virt/xenapi/image/test_glance.py @@ -35,9 +35,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB): super(TestGlanceStore, self).setUp() self.store = glance.GlanceStore() - self.flags(host='1.1.1.1', - port=123, - api_insecure=False, group='glance') + self.flags(api_servers=['http://localhost:9292'], group='glance') self.flags(connection_url='test_url', connection_password='test_pass', group='xenserver') @@ -61,7 +59,7 @@ class TestGlanceStore(stubs.XenAPITestBaseNoDB): def _get_params(self): return {'image_id': 'fake_image_uuid', - 'endpoint': 'http://1.1.1.1:123', + 'endpoint': 'http://localhost:9292', 'sr_path': '/fake/sr/path', 'extra_headers': {'X-Auth-Token': 'foobar', 'X-Roles': '', diff --git a/nova/tests/unit/virt/xenapi/test_vm_utils.py b/nova/tests/unit/virt/xenapi/test_vm_utils.py index 1305d05cc45d..002cb5fd7f5f 100644 --- a/nova/tests/unit/virt/xenapi/test_vm_utils.py +++ b/nova/tests/unit/virt/xenapi/test_vm_utils.py @@ -273,6 +273,7 @@ class FetchVhdImageTestCase(VMUtilsTestBase): self.context.auth_token = 'auth_token' self.session = FakeSession() self.instance = {"uuid": "uuid"} + self.flags(group='glance', api_servers=['http://localhost:9292']) self.mox.StubOutWithMock(vm_utils, '_make_uuid_stack') vm_utils._make_uuid_stack().AndReturn(["uuid_stack"]) diff --git a/releasenotes/notes/rm_glance_opts-360c94ac27328dc9.yaml b/releasenotes/notes/rm_glance_opts-360c94ac27328dc9.yaml new file mode 100644 index 000000000000..a2813152a0b7 --- /dev/null +++ b/releasenotes/notes/rm_glance_opts-360c94ac27328dc9.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + + - Delete the deprecated ``glance.host``, ``glance.port``, + ``glance.protocol`` configuration options. ``glance.api_servers`` + must be set to have a working config. There is currently no + default for this config option, so a value must be set.