Fix issue when vinconn raises exception at constructor 50/5550/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 9 Oct 2017 14:23:55 +0000 (16:23 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 9 Oct 2017 20:18:05 +0000 (22:18 +0200)
Change-Id: If6d69cab26a894c8f5d00f9affc0e214161d65af
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmanod
osm_ro/httpserver.py
osm_ro/nfvo.py
osm_ro/vim_thread.py

index bb27d16..b7f9bd6 100755 (executable)
--- a/openmanod
+++ b/openmanod
@@ -48,7 +48,7 @@ import osm_ro
 
 __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes"
 __date__ = "$26-aug-2014 11:09:29$"
-__version__ = "0.5.31-r541"
+__version__ = "0.5.32-r542"
 version_date = "Oct 2017"
 database_version = 27      # expected database schema version
 
index bb082d5..083bac1 100644 (file)
@@ -348,10 +348,10 @@ def http_get_tenant_id(tenant_id):
         select_, where_, limit_ = filter_query_string(bottle.request.query, None,
                                                       ('uuid', 'name', 'description', 'created_at'))
         where_['uuid'] = tenant_id
-        tenant = mydb.get_rows(FROM=from_, SELECT=select_,WHERE=where_)
+        tenants = mydb.get_rows(FROM=from_, SELECT=select_,WHERE=where_)
         #change_keys_http2db(content, http2db_tenant, reverse=True)
-        convert_datetime2str(tenant)
-        data={'tenant' : tenant}
+        convert_datetime2str(tenants)
+        data = {'tenant' : tenants[0]}
         return format_out(data)
     except db_base_Exception as e:
         logger.error("http_get_tenant_id error {}: {}".format(e.http_code, str(e)))
index 6ce84d4..e16f709 100644 (file)
@@ -182,6 +182,10 @@ def start_service(mydb):
                     user=vim['user'], passwd=vim['passwd'],
                     config=extra, persistent_info=vim_persistent_info[thread_id]
                 )
+            except vimconn.vimconnException as e:
+                myvim = e
+                logger.error("Cannot launch thread for VIM {} '{}': {}".format(vim['datacenter_name'],
+                                                                               vim['datacenter_id'], e))
             except Exception as e:
                 raise NfvoException("Error at VIM  {}; {}: {}".format(vim["type"], type(e).__name__, e),
                                     HTTP_Internal_Server_Error)
@@ -3749,9 +3753,8 @@ def delete_datacenter(mydb, datacenter):
 
 
 def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None, config=None):
-    #get datacenter info
-    datacenter_id, myvim = get_datacenter_by_name_uuid(mydb, None, datacenter, vim_user=vim_username, vim_passwd=vim_password)
-    datacenter_name = myvim["name"]
+    # get datacenter info
+    datacenter_id = get_datacenter_uuid(mydb, None, datacenter)
 
     create_vim_tenant = True if not vim_tenant_id and not vim_tenant_name else False
 
@@ -3785,6 +3788,9 @@ def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=
     else: #if vim_tenant_id==None:
         #create tenant at VIM if not provided
         try:
+            _, myvim = get_datacenter_by_name_uuid(mydb, None, datacenter, vim_user=vim_username,
+                                                               vim_passwd=vim_password)
+            datacenter_name = myvim["name"]
             vim_tenant_id = myvim.new_tenant(vim_tenant_name, "created by openmano for datacenter "+datacenter_name)
         except vimconn.vimconnException as e:
             raise NfvoException("Not possible to create vim_tenant {} at VIM: {}".format(vim_tenant_id, str(e)), HTTP_Internal_Server_Error)
@@ -3809,6 +3815,7 @@ def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=
     mydb.new_row('tenants_datacenters', tenants_datacenter_dict)
     # create thread
     datacenter_id, myvim = get_datacenter_by_name_uuid(mydb, tenant_dict['uuid'], datacenter_id)  # reload data
+    datacenter_name = myvim["name"]
     thread_name = get_non_used_vim_name(datacenter_name, datacenter_id, tenant_dict['name'], tenant_dict['uuid'])
     new_thread = vim_thread.vim_thread(myvim, task_lock, thread_name, datacenter_name, datacenter_tenant_id,
                                        db=db, db_lock=db_lock, ovim=ovim)
index bbb81a5..1fba7a6 100644 (file)
@@ -82,7 +82,7 @@ class vim_thread(threading.Thread):
     REFRESH_BUILD = 5      # 5 seconds
     REFRESH_ACTIVE = 60    # 1 minute
 
-    def __init__(self, vimconn, task_lock, name=None, datacenter_name=None, datacenter_tenant_id=None,
+    def __init__(self, myvimconn, task_lock, name=None, datacenter_name=None, datacenter_tenant_id=None,
                  db=None, db_lock=None, ovim=None):
         """Init a thread.
         Arguments:
@@ -92,7 +92,12 @@ class vim_thread(threading.Thread):
             'db', 'db_lock': database class and lock to use it in exclusion
         """
         threading.Thread.__init__(self)
-        self.vim = vimconn
+        if isinstance(myvimconn, vimconn.vimconnException):
+            self.vim = None
+            self.error_status = "Error accesing to VIM: {}".format(myvimconn)
+        else:
+            self.vim = myvimconn
+            self.error_status = None
         self.datacenter_name = datacenter_name
         self.datacenter_tenant_id = datacenter_tenant_id
         self.ovim = ovim
@@ -365,6 +370,8 @@ class vim_thread(threading.Thread):
         """Insert a task at list of refreshing elements. The refreshing list is ordered by threshold_time (task['modified_at']
         It is assumed that this is called inside this thread
         """
+        if not self.vim:
+            return
         if not threshold_time:
             threshold_time = time.time()
         task["modified_at"] = threshold_time
@@ -407,6 +414,11 @@ class vim_thread(threading.Thread):
                 # not needed to do anything but update database with the new status
                 result = True
                 database_update = None
+            elif not self.vim:
+                task["status"] == "ERROR"
+                task["error_msg"] = self.error_status
+                result = False
+                database_update = {"status": "VIM_ERROR", "error_msg": task["error_msg"]}
             elif task["item"] == 'instance_vms':
                 if task["action"] == "CREATE":
                     result, database_update = self.new_vm(task)