From: Mark McLoughlin Date: Tue, 18 Jun 2013 10:44:06 +0000 (+0100) Subject: Reference default_servicetype group in lowercase X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8a6143e145f3ed46ef3d723e83c9f4f4a5447729;p=openstack-build%2Fneutron-build.git Reference default_servicetype group in lowercase Now that we require oslo-config-1.2.0, we can start referencing group names as lowercase. Let's start with the default_servicetype group. We do this simply by changing the case of the group name passed to register_opt(): -cfg.CONF.register_opts(..., 'DEFAULT_SERVICETYPE') +cfg.CONF.register_opts(..., 'default_servicetype') and this means that all options in the group now need to be referenced using the lowercase group name i.e. -svc_defs = cfg.CONF.DEFAULT_SERVICETYPE.service_definition +svc_defs = cfg.CONF.default_servicetype.service_definition Note however, users can still use the uppercase section name for backwards compatibility. When we last attempted to do this, oslo.config-1.2.0 wasn't actually being installed correctly so add a unit test which verifies that both uppercase and lowercase section names work. Change-Id: I9357397f39d8f7d0d4f445b78aae5665c7ece3d4 --- diff --git a/quantum/db/servicetype_db.py b/quantum/db/servicetype_db.py index 1fa1e5cb0..db9417eb8 100644 --- a/quantum/db/servicetype_db.py +++ b/quantum/db/servicetype_db.py @@ -43,13 +43,13 @@ default_servicetype_opts = [ 'using the format: :[:]')) ] -cfg.CONF.register_opts(default_servicetype_opts, 'DEFAULT_SERVICETYPE') +cfg.CONF.register_opts(default_servicetype_opts, 'default_servicetype') def parse_service_definition_opt(): """Parse service definition opts and returns result.""" results = [] - svc_def_opt = cfg.CONF.DEFAULT_SERVICETYPE.service_definition + svc_def_opt = cfg.CONF.default_servicetype.service_definition try: for svc_def_str in svc_def_opt: split = svc_def_str.split(':') @@ -72,7 +72,7 @@ def parse_service_definition_opt(): class NoDefaultServiceDefinition(q_exc.QuantumException): message = _("No default service definition in configuration file. " "Please add service definitions using the service_definition " - "variable in the [DEFAULT_SERVICETYPE] section") + "variable in the [default_servicetype] section") class ServiceTypeNotFound(q_exc.NotFound): @@ -129,12 +129,12 @@ class ServiceTypeManager(object): self._initialize_db() ctx = context.get_admin_context() # Init default service type from configuration file - svc_defs = cfg.CONF.DEFAULT_SERVICETYPE.service_definition + svc_defs = cfg.CONF.default_servicetype.service_definition if not svc_defs: raise NoDefaultServiceDefinition() def_service_type = {'name': DEFAULT_SVCTYPE_NAME, 'description': - cfg.CONF.DEFAULT_SERVICETYPE.description, + cfg.CONF.default_servicetype.description, 'service_definitions': parse_service_definition_opt(), 'default': True} diff --git a/quantum/tests/unit/test_servicetype.py b/quantum/tests/unit/test_servicetype.py index 670a54475..9fc0adf52 100644 --- a/quantum/tests/unit/test_servicetype.py +++ b/quantum/tests/unit/test_servicetype.py @@ -19,7 +19,10 @@ import contextlib import logging +import os +import tempfile +import fixtures import mock from oslo.config import cfg import webob.exc as webexc @@ -33,6 +36,7 @@ from quantum.db import servicetype_db from quantum.extensions import servicetype from quantum import manager from quantum.plugins.common import constants +from quantum.tests import base from quantum.tests.unit import dummy_plugin as dp from quantum.tests.unit import test_api_v2 from quantum.tests.unit import test_db_plugin @@ -252,7 +256,7 @@ class ServiceTypeManagerTestCase(ServiceTypeTestCaseBase): servicetype_db.ServiceTypeManager._instance = None plugin_name = "%s.%s" % (dp.__name__, dp.DummyServicePlugin.__name__) cfg.CONF.set_override('service_definition', ['dummy:%s' % plugin_name], - group='DEFAULT_SERVICETYPE') + group='default_servicetype') self.addCleanup(db_api.clear_db) super(ServiceTypeManagerTestCase, self).setUp() @@ -467,3 +471,41 @@ class ServiceTypeManagerTestCase(ServiceTypeTestCaseBase): class ServiceTypeManagerTestCaseXML(ServiceTypeManagerTestCase): fmt = 'xml' + + +class CompatServiceTypeConfigTestCase(base.BaseTestCase): + + def setUp(self): + super(CompatServiceTypeConfigTestCase, self).setUp() + self.useFixture(fixtures.NestedTempfile()) + self.conf = cfg.ConfigOpts() + self.conf.register_opts(servicetype_db.default_servicetype_opts, + 'default_servicetype') + + def _write_quantum_conf(self, contents): + (fd, path) = tempfile.mkstemp(prefix='quantum-', suffix='.conf') + try: + os.write(fd, contents) + finally: + os.close(fd) + return path + + def _test_default_servicetype_section(self, section_name): + path = self._write_quantum_conf( + '[%(section_name)s]\n' + 'description = test service type\n' + 'service_definition=test:testing.QuantumTestPlugin\n' % + {'section_name': section_name}) + + self.conf(['--config-file', path]) + + self.assertEqual(self.conf.default_servicetype.description, + 'test service type') + self.assertEqual(self.conf.default_servicetype.service_definition, + ['test:testing.QuantumTestPlugin']) + + def test_default_servicetype_lowercase(self): + self._test_default_servicetype_section('default_servicetype') + + def test_default_servicetype_uppercase(self): + self._test_default_servicetype_section('DEFAULT_SERVICETYPE')