Changes to import dynamically modules in ovim.py 03/1703/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 26 Apr 2017 15:55:43 +0000 (17:55 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 8 May 2017 15:51:06 +0000 (17:51 +0200)
Change-Id: Iccea5d9ab6c87423d37fa0cb345d8f97cd0f30c9
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
Makefile
osm_openvim/ovim.py

index 3214870..bae4fe1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@ prepare_lite:
        sed -i "s/from osm_openvim/from lib_osm_openvim/g" build/openflow-lib
        sed -i "s/import osm_openvim/import lib_osm_openvim/g" build/openflow-lib
        sed -i "s/import osm_openvim; print osm_openvim\.__path__\[0\]/import lib_osm_openvim; print lib_osm_openvim\.__path__\[0\]/g" build/lib_osm_openvim/database_utils/migrate_vim_db.sh
+       sed -i "s/__import__(\"osm_openvim\.\"/__import__(\"lib_osm_openvim\.\"/g" build/lib_osm_openvim/ovim.py
 
 prepare:
        pip install --user --upgrade setuptools
@@ -91,15 +92,11 @@ snap:
        echo "Nothing to be done yet"
 
 install: clean build
+       #cd build/dist; pip install --user osm_openvim*
        cd build/dist; pip install osm_openvim*
 
 install_lite: clean build_lite
+       #cd build/dist; pip install --user lib_osm_openvim-*
        cd build/dist; pip install lib_osm_openvim-*
 
 
-
-
-
-
-
-
index c999049..fb34552 100755 (executable)
@@ -378,19 +378,12 @@ class ovim():
                 module = temp_dict['of_controller']
 
             if module not in ovim.of_module:
-                for base in ("", "osm_openvim.", "lib_osm_openvim."):
-                    try:
-                        pkg = __import__(base + module)
-                        if base:
-                            of_conn_module = getattr(pkg, module)
-                        else:
-                            of_conn_module = pkg
-                        ovim.of_module[module] = of_conn_module
-                        self.logger.debug("Module load from {}".format(base + module))
-                        break
-                    except Exception as e:
-                        self.logger.warning("Module {} not found {}".format(base + module, e))
-                else:
+                try:
+                    pkg = __import__("osm_openvim." + module)
+                    of_conn_module = getattr(pkg, module)
+                    ovim.of_module[module] = of_conn_module
+                    self.logger.debug("Module load from {}".format("osm_openvim." + module))
+                except Exception as e:
                     self.logger.error("Cannot open openflow controller module of type '%s'", module)
                     raise ovimException("Cannot open openflow controller of type module '{}'"
                                         "Revise it is installed".format(module),