Ask Your Question
0

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

asked 2016-12-22 02:23:19 -0600

kramer gravatar image

updated 2016-12-22 20:30:52 -0600

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()

    # Add Neutron core extensions
    paths[neutron.extensions.__path__[0]] = 1
    if service_plugins:
        # Add Neutron *-aas extensions
        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?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2017-01-28 13:02:26 -0600

benhart gravatar image

The collections isn't called like that. You should maybe look on some tutorials. They give most of the information you need. You can also use some apps to help you code better and detect any errors within your code. A friend once told me about Checkmarx, not sure about their cost but you can check. Good luck. Ben.

edit flag offensive delete link more
0

answered 2016-12-22 02:32:24 -0600

silently gravatar image

you know ,the first of all ,

paths = collections.OrderedDict()

you can assignment some spec values to paths,

look what happened .

edit flag offensive delete link more

Comments

thanks for the answer. but i do not understand. I know paths is a ordered dict but do know what you mean. could you give some more details? also i add something to my question to make it more clear. could you kindly check it again?

kramer gravatar imagekramer ( 2016-12-22 20:27:28 -0600 )edit

using python : print("some variable here");

silently gravatar imagesilently ( 2016-12-25 20:23:24 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-12-22 02:23:19 -0600

Seen: 153 times

Last updated: Jan 28 '17