# Revision history [back]

### Does this code is wrong? neutron.api.extensions.get_extensions_path

I am reading the code of liberty version neutron and I find a place very confusing. Sorry if this is not the right place to talk code. In that case please kindly tell me where should I go.

OK, this is my question. The code location is at

neutron/aip/extensions.py


The function is

# Returns the extension paths from a config entry and the __path__
# of neutron.extensions
def get_extensions_path(service_plugins=None):
paths = collections.OrderedDict()

paths[neutron.extensions.__path__[0]] = 1
if service_plugins:
for plugin in service_plugins.values():
neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1
except AttributeError:
# Occurs normally if module has no extensions sub-module
pass


The problem is this line

plugin.__module__.split('.')[0]


No matter what does the plugin is, the plugin.__module__ must be some string start with

neutron.


Because they all belong to the package neutron. So split['.'][0] will return only the string "neutron".

So the line

paths[neutron_mod.module().extensions.__path__[0]] = 1


Will be doing the exactly same thing with the line

paths[neutron.extensions.__path__[0]] = 1


Because the neutron_mod.module() will be just "neutron" module..

So... what is the point of doing it again here?

### Does this code is wrong? neutron.api.extensions.get_extensions_path

I am reading the code of liberty version neutron and I find a place very confusing. Sorry if this is not the right place to talk about code. In that case please kindly tell me where should I go.

OK, this is my question. The code location is at

neutron/aip/extensions.py


The function is

# Returns the extension paths from a config entry and the __path__
# of neutron.extensions
def get_extensions_path(service_plugins=None):
paths = collections.OrderedDict()

paths[neutron.extensions.__path__[0]] = 1
if service_plugins:
for plugin in service_plugins.values():
neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1
except AttributeError:
# Occurs normally if module has no extensions sub-module
pass


The problem is this line

plugin.__module__.split('.')[0]


No matter what does the plugin is, the plugin.__module__ must be some string start with

neutron.


Because they all belong to the package neutron. So split['.'][0] will return only the string "neutron".

So the line

paths[neutron_mod.module().extensions.__path__[0]] = 1


Will be doing the exactly same thing with the line

paths[neutron.extensions.__path__[0]] = 1


Because the neutron_mod.module() will be just "neutron" module..

So... what is the point of doing it again here?

### Does this code is wrong? neutron.api.extensions.get_extensions_path

I am reading the code of liberty version neutron and I find a place very confusing. Sorry if this is not the right place to talk about code. In that case please kindly tell me where should I go.

OK, this is my question. The code location is at

neutron/aip/extensions.py


The function is

# Returns the extension paths from a config entry and the __path__
# of neutron.extensions
def get_extensions_path(service_plugins=None):
paths = collections.OrderedDict()

paths[neutron.extensions.__path__[0]] = 1
if service_plugins:
for plugin in service_plugins.values():
neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1
except AttributeError:
# Occurs normally if module has no extensions sub-module
pass


The problem is this line

plugin.__module__.split('.')[0]


No matter what does the plugin is, the plugin.__module__ must be some string start with

neutron.


Because they all belong to the package neutron. So split['.'][0] will return only the string "neutron".

So the line

paths[neutron_mod.module().extensions.__path__[0]] = 1


Will be doing the exactly same thing with the line

paths[neutron.extensions.__path__[0]] = 1


Because the neutron_mod.module() will be just "neutron" module..

So... what is the point of doing it again here?

Add some thing to make my question more clear From the comment we know that it said this functions return a collection of paths. The paths should include

1. neutron.extensions.__path__ (which is /usr/lib/python/site/packages/neutron/extensions)
2. service plugin extension paths (for example : extension sub directory of L3_ROUTER_Plugin which is a service plugin )

The first one like neutron.extensions.__path__ will be get by the line

paths[neutron.extensions.__path__[0]] = 1


But the part of getting service plugin extension paths which is the below lines:

            neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1


These lines seems have some problem. Because the plugin.__module__.split('.')[0] will always return string "neutron". So neutron_mod is nothing but the neutron module. So paths[neutron_mod.module().extensions.__path__] is exactly the neutron.extensions.__path__ which we already get before.

It is not the extension path of service plugin. So I am confused here. Is there anything wrong with my understanding or it is wrong？

### Does this code is wrong? neutron.api.extensions.get_extensions_path

I am reading the code of liberty version neutron and I find a place very confusing. Sorry if this is not the right place to talk about code. In that case please kindly tell me where should I go.

OK, this is my question. The code location is at

neutron/aip/extensions.py


The function is

# Returns the extension paths from a config entry and the __path__
# of neutron.extensions
def get_extensions_path(service_plugins=None):
paths = collections.OrderedDict()

paths[neutron.extensions.__path__[0]] = 1
if service_plugins:
for plugin in service_plugins.values():
neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1
except AttributeError:
# Occurs normally if module has no extensions sub-module
pass


The problem is this line

plugin.__module__.split('.')[0]


No matter what does the plugin is, the plugin.__module__ must be some string start with

neutron.


Because they all belong to the package neutron. So split['.'][0] will return only the string "neutron".

So the line

paths[neutron_mod.module().extensions.__path__[0]] = 1


Will be doing the exactly same thing with the line

paths[neutron.extensions.__path__[0]] = 1


Because the neutron_mod.module() will be just "neutron" module..

So... what is the point of doing it again here?

Add some thing to make my question more clear

From the comment we know that it said this functions return a collection of paths. The paths should include

1. neutron.extensions.__path__ (which is /usr/lib/python/site/packages/neutron/extensions)
2. service plugin extension paths (for example : extension sub directory of L3_ROUTER_Plugin which is a service plugin )

The first one like neutron.extensions.__path__ will be get by the line

paths[neutron.extensions.__path__[0]] = 1


But the part of getting service plugin extension paths which is the below lines:

            neutron_mod = provider_configuration.NeutronModule(
plugin.__module__.split('.')[0])
try:
paths[neutron_mod.module().extensions.__path__[0]] = 1


These lines seems have some problem. Because the plugin.__module__.split('.')[0] will always return string "neutron". So neutron_mod is nothing but the neutron module. So paths[neutron_mod.module().extensions.__path__] is exactly the neutron.extensions.__path__ which we already get before.

It is not the extension path of service plugin. So I am confused here. Is there anything wrong with my understanding or it is wrong？