Admin util should work from any dir

It wasn't working because of two reasons:
1. The packages filed in setup.cfg takes a directory name.
so specifying tools.python_nsxadmin.admin didn't put the py files
in /usr/local/lib/python2.7/dist-packages when we pip installed
vmware-nsx package. (sudo pip install .). So changing it to tools
installs all the code in tools including python_nsxadmin there. Read
2 to know why we need this.

2. To enable admin utility to dynamically pick up any hooks that users
might add we use the importlib module. The bug was here, as the path was
absolute tools/python_nsxadmin/.... So when we executed it from other
diretory those modules were not imported. So I changed that to relative
path. Though, over here there could be a case where the hooks location
directory path contains a '-' / dash, which will cause it to fail.

>>> import
>>> home.gangil.t1-review.e_nsx.tools.python_nsxadmin.admin.plugins.nsxv.resources.edges

  File "<stdin>", line 1

    import
home.gangil.t1-review.vmware_nsx.tools.python_nsxadmin.admin.plugins.nsxv.resources.edges

                         ^

SyntaxError: invalid syntax

So we install the tools code using setup.cfg and then just import
resources from there.

Now it works from any directory.

Change-Id: Idc414fabc769d0503974e8f77b84d32008b3c08a
This commit is contained in:
Akash Gangil 2015-12-02 04:02:20 -08:00
parent 8af4b6462b
commit 72d72623a9
2 changed files with 5 additions and 2 deletions

View File

@ -21,12 +21,14 @@ classifier =
[files]
packages =
vmware_nsx
tools/python_nsxadmin.admin
data_files =
etc/neutron/plugins/vmware = etc/nsx.ini
[entry_points]
console_scripts =
neutron-check-nsx-config = vmware_nsx.check_nsx_config:main
nsxadmin = tools.python_nsxadmin.admin.shell:main
neutron.db.alembic_migrations =
vmware-nsx = vmware_nsx.db.migration:alembic_migrations
neutron.core_plugins =

View File

@ -104,7 +104,7 @@ def _get_plugin():
def _get_plugin_dir():
plugin_dir = 'tools/python_nsxadmin/admin/plugins'
plugin_dir = os.path.dirname(os.path.realpath(__file__)) + "/plugins"
return '{}/{}/resources'.format(plugin_dir, _get_plugin())
@ -151,7 +151,8 @@ def _init_resource_plugin():
for resource in resources:
if resource != '__init__':
importlib.import_module("." + resource,
_get_plugin_dir().replace("/", "."))
"tools.python_nsxadmin.admin.plugins."
"{}.resources".format(_get_plugin()))
def _init_cfg():