From: armando-migliaccio Date: Thu, 3 Sep 2015 17:29:12 +0000 (-0700) Subject: Make sure service providers can be loaded correctly X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f347939fd6c7b5a9e93af2007a0c01d00f29dc2b;p=openstack-build%2Fneutron-build.git Make sure service providers can be loaded correctly 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 --- diff --git a/neutron/services/provider_configuration.py b/neutron/services/provider_configuration.py index b4c03cbad..9bbf824d6 100644 --- a/neutron/services/provider_configuration.py +++ b/neutron/services/provider_configuration.py @@ -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