]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make sure service providers can be loaded correctly
authorarmando-migliaccio <armamig@gmail.com>
Thu, 3 Sep 2015 17:29:12 +0000 (10:29 -0700)
committerarmando-migliaccio <armamig@gmail.com>
Thu, 3 Sep 2015 17:42:50 +0000 (10:42 -0700)
This patch fixes a regression where, if neutron was loaded using
--config-dir, the service_providers option was no longer available.

We bring the logic back (removed by 61121c5f2af), alongside the ability
to load the option auto-magically. This is especially required for DevStack
deployments as of today, because neutron-server is only loaded by passing
--config-file (...)neutron.conf and --config-file (...)ml2_conf.ini

Change-Id: I9bfaed9e19a5506e27795a0b7ad47f4c31fefa40
Closes-bug: #1490990

neutron/services/provider_configuration.py

index b4c03cbada645bc64bfc56d5f8936fdeb5a87428..9bbf824d6a97579eb2e1846b5ba430ad212b5b2e 100644 (file)
@@ -61,10 +61,7 @@ class NeutronModule(object):
     def module(self):
         return self.repo['mod']
 
-    # Return an INI parser for the child module. oslo.config is a bit too
-    # magical in its INI loading, and in one notable case, we need to merge
-    # together the [service_providers] section across at least four
-    # repositories.
+    # Return an INI parser for the child module
     def ini(self):
         if self.repo['ini'] is None:
             neutron_dir = None
@@ -86,17 +83,34 @@ class NeutronModule(object):
         return self.repo['ini']
 
     def service_providers(self):
-        ini = self.ini()
-
-        sp = []
+        """Return the service providers for the extension module."""
+        providers = []
+        # Attempt to read the config from cfg.CONF; this is possible
+        # when passing --config-dir. Since the multiStr config option
+        # gets merged, extract only the providers pertinent to this
+        # service module.
         try:
-            for name, value in ini.items('service_providers'):
-                if name == 'service_provider':
-                    sp.append(value)
-        except ConfigParser.NoSectionError:
+            providers = [
+                sp for sp in cfg.CONF.service_providers.service_provider
+                if self.module_name in sp
+            ]
+        except cfg.NoSuchOptError:
             pass
 
-        return sp
+        # Alternatively, if the option is not avaialable, load the
+        # config option using the module's built-in ini parser.
+        # this may be necessary, if modules are loaded on the fly
+        # (DevStack may be an example)
+        if not providers:
+            ini = self.ini()
+            try:
+                for name, value in ini.items('service_providers'):
+                    if name == 'service_provider':
+                        providers.append(value)
+            except ConfigParser.NoSectionError:
+                pass
+
+        return providers
 
 
 #global scope function that should be used in service APIs