Allow ovim parameters at config file. Fix an issue at network deletion 07/1507/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 5 Apr 2017 17:55:36 +0000 (19:55 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Thu, 6 Apr 2017 07:55:14 +0000 (08:55 +0100)
Change-Id: I1b3d5e0e024e776aa763cb50db3189e584120434
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
nfvo.py
openmano_schemas.py
openmanod.cfg
openmanod.py
vim_thread.py

diff --git a/nfvo.py b/nfvo.py
index 724766b..3ea5107 100644 (file)
--- a/nfvo.py
+++ b/nfvo.py
@@ -43,7 +43,7 @@ from db_base import db_base_Exception
 import nfvo_db
 from threading import Lock
 from time import time
-import openvim.ovim as Ovim
+import ovim as ovim_module
 
 global global_config
 global vimconn_imported
@@ -115,23 +115,20 @@ def start_service(mydb):
     # TODO: Avoid static configuration by adding new parameters to openmanod.cfg
     # TODO: review ovim.py to delete not needed configuration
     ovim_configuration = {
-        'logger_name': 'openvim',
+        'logger_name': 'openmano.ovim',
         'network_vlan_range_start': 1000,
         'network_vlan_range_end': 4096,
-        'log_level_db': 'DEBUG',
-        'db_name': 'mano_vim_db',
-        'db_host': 'localhost',
-        'db_user': 'vim',
-        'db_passwd': 'vimpw',
-        'database_version': '0.15',
+        'db_name': global_config["db_ovim_name"],
+        'db_host': global_config["db_ovim_host"],
+        'db_user': global_config["db_ovim_user"],
+        'db_passwd': global_config["db_ovim_passwd"],
         'bridge_ifaces': {},
         'mode': 'normal',
-        'of_controller_nets_with_same_vlan': True,
         'network_type': 'bridge',
         #TODO: log_level_of should not be needed. To be modified in ovim
         'log_level_of': 'DEBUG'
     }
-    ovim = Ovim.ovim(ovim_configuration)
+    ovim = ovim_module.ovim(ovim_configuration)
     ovim.start_service()
 
     from_= 'tenants_datacenters as td join datacenters as d on td.datacenter_id=d.uuid join datacenter_tenants as dt on td.datacenter_tenant_id=dt.uuid'
@@ -3260,4 +3257,4 @@ def datacenter_sdn_port_mapping_list(mydb, tenant_id, datacenter_id):
     return result
 
 def datacenter_sdn_port_mapping_delete(mydb, tenant_id, datacenter_id):
-    return ovim.clear_of_port_mapping(db_filter={"region":datacenter_id})
\ No newline at end of file
+    return ovim.clear_of_port_mapping(db_filter={"region":datacenter_id})
index 5b1b942..1dfcffe 100644 (file)
@@ -86,6 +86,10 @@ config_schema = {
         "db_user": nameshort_schema,
         "db_passwd": {"type":"string"},
         "db_name": nameshort_schema,
+        "db_ovim_host": nameshort_schema,
+        "db_ovim_user": nameshort_schema,
+        "db_ovim_passwd": {"type":"string"},
+        "db_ovim_name": nameshort_schema,
         # Next fields will disappear once the MANO API includes appropriate primitives
         "vim_url": http_schema,
         "vim_url_admin": http_schema,
@@ -109,16 +113,18 @@ config_schema = {
         "log_level_nfvo": log_level_schema,
         "log_level_http": log_level_schema,
         "log_level_console": log_level_schema,
+        "log_level_ovim": log_level_schema,
         "log_file_db": path_schema,
         "log_file_vim": path_schema,
         "log_file_nfvo": path_schema,
         "log_file_http": path_schema,
         "log_file_console": path_schema,
+        "log_file_ovim": path_schema,
         "log_socket_host": nameshort_schema,
         "log_socket_port": port_schema,
         "log_file": path_schema,
     },
-    "required": ['db_host', 'db_user', 'db_passwd', 'db_name'],
+    "required": ['db_user', 'db_passwd', 'db_name'],
     "additionalProperties": False
 }
 
index ebcee2b..adc5b62 100644 (file)
@@ -44,6 +44,12 @@ db_host:   localhost          # by default localhost
 db_user:   mano               # DB user
 db_passwd: manopw             # DB password
 db_name:   mano_db            # Name of the MANO DB
+# Database ovim parameters
+db_ovim_host:   localhost          # by default localhost
+db_ovim_user:   mano               # DB user
+db_ovim_passwd: manopw             # DB password
+db_ovim_name:   mano_vim_db        # Name of the OVIM MANO DB
+
 
 #other MANO parameters
 #  Folder where the VNF descriptors will be stored
@@ -71,6 +77,8 @@ log_level:         DEBUG  #general log levels for internal logging
 #log_file_http:     /opt/openmano/logs/openmano_http.log
 #log_level_console: DEBUG  #proxy console log levels
 #log_file_console:  /opt/openmano/logs/openmano_console.log
+#log_level_ovim:    DEBUG  #ovim library log levels
+#log_file_ovim:     /opt/openmano/logs/openmano_ovim.log
 
 #Uncomment to send logs via IP to an external host
 #log_socket_host:   localhost
index ee9b862..55c7e8c 100755 (executable)
@@ -58,14 +58,16 @@ class LoadConfigurationException(Exception):
     pass
 
 def load_configuration(configuration_file):
-    default_tokens ={'http_port':9090,
-                     'http_host':'localhost',
-                     'http_console_proxy': True,
-                     'http_console_host': None,
-                     'log_level': 'DEBUG',
-                     'log_socket_port': 9022,
-                     'auto_push_VNF_to_VIMs': True
-                    }
+    default_tokens = {'http_port':9090,
+                      'http_host':'localhost',
+                      'http_console_proxy': True,
+                      'http_console_host': None,
+                      'log_level': 'DEBUG',
+                      'log_socket_port': 9022,
+                      'auto_push_VNF_to_VIMs': True,
+                      'db_host': 'localhost',
+                      'db_ovim_host': 'localhost'
+    }
     try:
         #Check config file exists
         with open(configuration_file, 'r') as f:
@@ -242,7 +244,7 @@ if __name__=="__main__":
         logger.critical("Starting openmano server version: '%s %s' command: '%s'",  
                          __version__, version_date, " ".join(sys.argv))
         
-        for log_module in ("nfvo", "http", "vim", "db", "console"):
+        for log_module in ("nfvo", "http", "vim", "db", "console", "ovim"):
             log_level_module = "log_level_" + log_module
             log_file_module = "log_file_" + log_module
             logger_module = logging.getLogger('openmano.' + log_module)
index 3510c4f..1b518d3 100644 (file)
@@ -34,7 +34,7 @@ import Queue
 import logging
 import vimconn
 from db_base import db_base_Exception
-from openvim.ovim import ovimException
+from ovim import ovimException
 
 
 # from logging import Logger
@@ -163,11 +163,12 @@ class vim_thread(threading.Thread):
                                     SELECT=("ii.uuid as iface_id", "ine.uuid as net_id", "iv.uuid as vm_id", "sdn_net_id"),
                                     WHERE=where_)
                             if len(db_ifaces)>1:
-                                self.logger.error("Refresing interfaces. "
+                                self.logger.critical("Refresing interfaces. "
                                                   "Found more than one interface at database for '{}'".format(where_))
                             elif len(db_ifaces)==0:
-                                self.logger.error("Refresing interfaces. "
+                                self.logger.critical("Refresing interfaces. "
                                                   "Not found any interface at database for '{}'".format(where_))
+                                continue
                             else:
                                 db_iface = db_ifaces[0]
                                 if db_iface.get("sdn_net_id") and interface.get("compute_node") and interface.get("pci"):
@@ -224,11 +225,12 @@ class vim_thread(threading.Thread):
                             SELECT=("uuid as net_id", "sdn_net_id"),
                             WHERE=where_)
                     if len(db_nets) > 1:
-                        self.logger.error("Refresing networks. "
+                        self.logger.critical("Refresing networks. "
                                           "Found more than one instance-networks at database for '{}'".format(where_))
                     elif len(db_nets) == 0:
-                        self.logger.error("Refresing networks. "
+                        self.logger.critical("Refresing networks. "
                                           "Not found any instance-network at database for '{}'".format(where_))
+                        continue
                     else:
                         db_net = db_nets[0]
                         if db_net.get("sdn_net_id"):
@@ -330,56 +332,59 @@ class vim_thread(threading.Thread):
         while True:
             #TODO reload service
             while True:
-                if not self.task_queue.empty():
-                    task = self.task_queue.get()
-                    self.task_lock.acquire()
-                    if task["status"] == "deleted":
+                try:
+                    if not self.task_queue.empty():
+                        task = self.task_queue.get()
+                        self.task_lock.acquire()
+                        if task["status"] == "deleted":
+                            self.task_lock.release()
+                            continue
+                        task["status"] = "processing"
                         self.task_lock.release()
+                    else:
+                        self._refres_elements()
                         continue
-                    task["status"] = "processing"
-                    self.task_lock.release()
-                else:
-                    self._refres_elements()
-                    continue
-                self.logger.debug("processing task id={} name={} params={}".format(task["id"], task["name"],
-                                                                                   str(task["params"])))
-                if task["name"] == 'exit' or task["name"] == 'reload':
-                    result, content = self.terminate(task)
-                elif task["name"] == 'new-vm':
-                    result, content = self.new_vm(task)
-                elif task["name"] == 'del-vm':
-                    result, content = self.del_vm(task)
-                elif task["name"] == 'new-net':
-                    result, content = self.new_net(task)
-                elif task["name"] == 'del-net':
-                    result, content = self.del_net(task)
-                else:
-                    error_text = "unknown task {}".format(task["name"])
-                    self.logger.error(error_text)
-                    result = False
-                    content = error_text
-                self.logger.debug("task id={} name={} result={}:{} params={}".format(task["id"], task["name"],
-                                                                                    result, content,
-                                                                                    str(task["params"])))
-
-                with self.task_lock:
-                    task["status"] = "done" if result else "error"
-                    task["result"] = content
-                self.task_queue.task_done()
-
-                if task["name"] == 'exit':
-                    return 0
-                elif task["name"] == 'reload':
-                    break
+                    self.logger.debug("processing task id={} name={} params={}".format(task["id"], task["name"],
+                                                                                       str(task["params"])))
+                    if task["name"] == 'exit' or task["name"] == 'reload':
+                        result, content = self.terminate(task)
+                    elif task["name"] == 'new-vm':
+                        result, content = self.new_vm(task)
+                    elif task["name"] == 'del-vm':
+                        result, content = self.del_vm(task)
+                    elif task["name"] == 'new-net':
+                        result, content = self.new_net(task)
+                    elif task["name"] == 'del-net':
+                        result, content = self.del_net(task)
+                    else:
+                        error_text = "unknown task {}".format(task["name"])
+                        self.logger.error(error_text)
+                        result = False
+                        content = error_text
+                    self.logger.debug("task id={} name={} result={}:{} params={}".format(task["id"], task["name"],
+                                                                                        result, content,
+                                                                                        str(task["params"])))
+
+                    with self.task_lock:
+                        task["status"] = "done" if result else "error"
+                        task["result"] = content
+                    self.task_queue.task_done()
+
+                    if task["name"] == 'exit':
+                        return 0
+                    elif task["name"] == 'reload':
+                        break
+                except Exception as e:
+                    self.logger.critical("Unexpected exception at run: " + str(e), exc_info=True)
 
         self.logger.debug("Finishing")
 
     def terminate(self, task):
         return True, None
 
-    def _format_vim_error_msg(self, error_text, len=1024):
-        if error_text and len(error_text) >= len:
-            return error_text[:len//2-3] + " ... " + error_text[-len//2+3:]
+    def _format_vim_error_msg(self, error_text, max_length=1024):
+        if error_text and len(error_text) >= max_length:
+            return error_text[:max_length//2-3] + " ... " + error_text[-max_length//2+3:]
         return error_text
 
     def new_net(self, task):
@@ -539,7 +544,7 @@ class vim_thread(threading.Thread):
             except Exception as e:
                 return False, "Error trying to get task_id='{}':".format(net_id, str(e))
         try:
-            self._remove_refresh("get-vm", net_id)
+            self._remove_refresh("get-net", net_id)
             result = self.vim.delete_network(net_id)
             if sdn_net_id:
                 with self.db_lock: