Fix issue when vinconn raises exception at constructor

Change-Id: If6d69cab26a894c8f5d00f9affc0e214161d65af
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
diff --git a/osm_ro/vim_thread.py b/osm_ro/vim_thread.py
index bbb81a5..1fba7a6 100644
--- a/osm_ro/vim_thread.py
+++ b/osm_ro/vim_thread.py
@@ -82,7 +82,7 @@
     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 @@
             '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 @@
         """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 @@
                 # 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)