shinken-monitoring / mod-webui

Shinken Web User Interface
GNU Affero General Public License v3.0
79 stars 71 forks source link

WebUI submodules import #281

Closed mohierf closed 9 years ago

mohierf commented 9 years ago

The new submodules in the WebUI make the broker log a Warning:

[1438156709] WARNING: [broker-master] Cannot import webui..module : No module named submodules.metamodule
[1438156709] WARNING: [broker-master] Trying to load '/var/lib/shinken/modules/webui' as an (very-)old-style shinken "module" : by adding its path to sys.path. This can be (very) bad in case of name conflicts within the files part of /var/lib/shinken/modules/webui and others top-level python modules; I'll try to limit that.
[1438156709] INFO: [broker-master] Correctly loaded webui as a very old-style shinken module :s

Note: this log is a simple alert on WebUI module importation by the broker ... at the end, the WebUI is started and runs correctly!

mohierf commented 9 years ago

Source of the WARNING log is in Shinken modulesmanager.py, function _try_bestload.

This function is called twice :

    def try_best_load(cls, name, package=None):
        try:
            mod = importlib.import_module(name, package)
        except Exception as err:
            logger.warning("Cannot import %s : %s",
                           '%s.%s' % (package, name) if package else name,
                           err)
            return
maethor commented 9 years ago

Don't assign this to me. For me, all this module management is pure magic :D

Stupid question: did you find a documentation somewhere that explain how to make a "new style" module ?

mohierf commented 9 years ago

You are right ... I assigned this issue to you if you had an idea about it. But, no, I did not found any info about what are old style, new-old style, old-new style ... modules :-)

Simage commented 9 years ago

Issue appears to be due to the submodules python module not being found in the python path, as such it falls back to an older import mechanism that adds the shinken modules path (too many different definitions of module) to sys.path allowing it to resolve submodules.metamodule. I suspect that the issue is easiest resolved by simply changing the sub modules to use relative imports to pull the parent class into the module