New create-tenant option idempotent useful for docker initialization. Other minor... 01/5901/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 23 Mar 2018 14:44:03 +0000 (15:44 +0100)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 26 Mar 2018 10:13:58 +0000 (12:13 +0200)
Change-Id: I1da8ddfbad06c1a1f0c490f5e606c48aaec4ecd0
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
docker/scripts/start.sh
openmanod
osm_ro/nfvo.py
osm_ro/vim_thread.py
osm_ro/vimconn_openstack.py

index 136bf85..1506e3a 100755 (executable)
@@ -125,4 +125,4 @@ fi
 
 
 echo "4/4 Try to start"
-/usr/bin/openmanod -c /etc/osm/openmanod.cfg --log-file=/var/log/osm/openmano.log
+/usr/bin/openmanod -c /etc/osm/openmanod.cfg --log-file=/var/log/osm/openmano.log --create-tenant=osm
index 18ca8cc..b45187e 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.56-r566"
+__version__ = "0.5.57-r567"
 version_date = "Mar 2018"
 database_version = 28      # expected database schema version
 
@@ -136,6 +136,7 @@ def usage():
     print("      --log-socket-host HOST: send logs to this host")
     print("      --log-socket-port PORT: send logs using this port (default: 9022)")
     print("      --log-file FILE: send logs to this file")
+    print("      --create-tenant NAME: Try to creates this tenant name before starting, ignoring any errors as e.g. conflict")
     return
 
 
@@ -183,8 +184,10 @@ if __name__=="__main__":
     # Read parameters and configuration file
     httpthread = None
     try:
-        #load parameters and configuration
-        opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:", ["config=", "help", "version", "port=", "vnf-repository=", "adminport=", "log-socket-host=", "log-socket-port=", "log-file="])
+        # load parameters and configuration
+        opts, args = getopt.getopt(sys.argv[1:], "hvc:V:p:P:",
+                                   ["config=", "help", "version", "port=", "vnf-repository=", "adminport=",
+                                    "log-socket-host=", "log-socket-port=", "log-file=", "create-tenant="])
         port=None
         port_admin = None
         config_file = 'osm_ro/openmanod.cfg'
@@ -192,6 +195,7 @@ if __name__=="__main__":
         log_file = None
         log_socket_host = None
         log_socket_port = None
+        create_tenant = None
 
         for o, a in opts:
             if o in ("-v", "--version"):
@@ -215,6 +219,8 @@ if __name__=="__main__":
                 log_socket_host = a
             elif o == "--log-file":
                 log_file = a
+            elif o == "--create-tenant":
+                create_tenant = a
             else:
                 assert False, "Unhandled option"
         if log_file:
@@ -320,6 +326,14 @@ if __name__=="__main__":
             exit(-1)
 
         nfvo.global_config=global_config
+        if create_tenant:
+            try:
+                nfvo.new_tenant(mydb, {"name": create_tenant})
+            except Exception as e:
+                if isinstance(e, nfvo.NfvoException) and e.http_code == 409:
+                    pass  # if tenant exist (NfvoException error 409), ignore
+                else:     # otherwise print and error and continue
+                    logger.error("Cannot create tenant '{}': {}".format(create_tenant, e))
         nfvo.start_service(mydb)
 
         httpthread = httpserver.httpserver(mydb, False, global_config['http_host'], global_config['http_port'])
index c2f331b..6bb14f9 100644 (file)
@@ -4243,7 +4243,7 @@ def new_tenant(mydb, tenant_dict):
         tenant_dict['encrypted_RO_priv_key'] = priv_key
         mydb.new_row("nfvo_tenants", tenant_dict, confidential_data=True)
     except db_base_Exception as e:
-        raise NfvoException("Error creating the new tenant: {} ".format(tenant_dict['name']) + str(e), HTTP_Internal_Server_Error)
+        raise NfvoException("Error creating the new tenant: {} ".format(tenant_dict['name']) + str(e), e.http_code)
     return tenant_uuid
 
 def delete_tenant(mydb, tenant):
@@ -4626,7 +4626,7 @@ def get_sdn_net_id(mydb, tenant_id, datacenter, network_id):
         result =  mydb.get_rows(SELECT=('sdn_net_id',), FROM='instance_nets', WHERE=search_dict)
     except db_base_Exception as e:
         raise NfvoException("db_base_Exception obtaining SDN network to associated to vim network {}".format(
-            network_id) + str(e), HTTP_Internal_Server_Error)
+            network_id) + str(e), e.http_code)
 
     sdn_net_counter = 0
     for net in result:
@@ -4683,7 +4683,7 @@ def vim_net_sdn_attach(mydb, tenant_id, datacenter, network_id, descriptor):
             sdn_network_id, network_id) + str(e), HTTP_Internal_Server_Error)
     except db_base_Exception as e:
         raise NfvoException("db_base_Exception attaching SDN network to vim network {}".format(
-            network_id) + str(e), HTTP_Internal_Server_Error)
+            network_id) + str(e), e.http_code)
 
     return 'Port uuid: '+ result
 
@@ -4813,7 +4813,7 @@ def vim_action_delete(mydb, tenant_id, datacenter, item, name):
                     mydb.delete_row(FROM='instance_nets', WHERE={'instance_scenario_id': None, 'sdn_net_id': sdn_network_id, 'vim_net_id': item_id})
                 except db_base_Exception as e:
                     raise NfvoException("Error deleting correspondence for VIM/SDN dataplane networks{}: ".format(correspondence) +
-                                        str(e), HTTP_Internal_Server_Error)
+                                        str(e), e.http_code)
 
                 #Delete the SDN network
                 try:
@@ -4883,7 +4883,7 @@ def vim_action_create(mydb, tenant_id, datacenter, item, descriptor):
                     mydb.new_row('instance_nets', correspondence, add_uuid=True)
                 except db_base_Exception as e:
                     raise NfvoException("Error saving correspondence for VIM/SDN dataplane networks{}: {}".format(
-                        correspondence, e), HTTP_Internal_Server_Error)
+                        correspondence, e), e.http_code)
         elif item=="tenants":
             tenant = descriptor["tenant"]
             content = myvim.new_tenant(tenant["name"], tenant.get("description"))
index d5574b4..cbcd31f 100644 (file)
@@ -484,11 +484,11 @@ class vim_thread(threading.Thread):
                         break
                     elif task_dependency["status"] == "FAILED":
                         raise VimThreadException(
-                            "Cannot {} {}, (task {}.{}) because depends on failed {} {}, (task{}.{})".format(
+                            "Cannot {} {}, (task {}.{}) because depends on failed {}.{}, (task{}.{}): {}".format(
                                 task["action"], task["item"],
                                 task["instance_action_id"], task["task_index"],
                                 task_dependency["instance_action_id"], task_dependency["task_index"],
-                                task_dependency["action"], task_dependency["item"]))
+                                task_dependency["action"], task_dependency["item"], task_dependency.get("error_msg")))
                 if dependency_not_completed:
                     # Move this task to the end.
                     task["extra"]["tries"] = task["extra"].get("tries", 0) + 1
index 499d265..55f910b 100644 (file)
@@ -1612,8 +1612,7 @@ class vimconnector(vimconn.vimconnector):
             error_text= type(e).__name__ + ": "+  (str(e) if len(e.args)==0 else str(e.args[0]))
         #TODO insert exception vimconn.HTTP_Unauthorized
         #if reaching here is because an exception
-        if self.debug:
-            self.logger.debug("new_user " + error_text)
+        self.logger.debug("new_user " + error_text)
         return error_value, error_text
 
     def delete_user(self, user_id):
@@ -1636,8 +1635,7 @@ class vimconnector(vimconn.vimconnector):
             error_text= type(e).__name__ + ": "+  (str(e) if len(e.args)==0 else str(e.args[0]))
         #TODO insert exception vimconn.HTTP_Unauthorized
         #if reaching here is because an exception
-        if self.debug:
-            print("delete_tenant " + error_text)
+            self.logger.debug("delete_tenant " + error_text)
         return error_value, error_text
 
     def get_hosts_info(self):
@@ -1660,8 +1658,7 @@ class vimconnector(vimconn.vimconnector):
             error_text= type(e).__name__ + ": "+  (str(e) if len(e.args)==0 else str(e.args[0]))
         #TODO insert exception vimconn.HTTP_Unauthorized
         #if reaching here is because an exception
-        if self.debug:
-            print("get_hosts_info " + error_text)
+        self.logger.debug("get_hosts_info " + error_text)
         return error_value, error_text
 
     def get_hosts(self, vim_tenant):
@@ -1689,8 +1686,7 @@ class vimconnector(vimconn.vimconnector):
             error_text= type(e).__name__ + ": "+  (str(e) if len(e.args)==0 else str(e.args[0]))
         #TODO insert exception vimconn.HTTP_Unauthorized
         #if reaching here is because an exception
-        if self.debug:
-            print("get_hosts " + error_text)
+        self.logger.debug("get_hosts " + error_text)
         return error_value, error_text
 
     def new_classification(self, name, ctype, definition):
@@ -1846,9 +1842,9 @@ class vimconnector(vimconn.vimconnector):
         try:
             new_sf = None
             self._reload_connection()
-            correlation = None
-            if sfc_encap:
-                correlation = 'nsh'
+            correlation = None
+            if sfc_encap:
+                correlation = 'nsh'
             for instance in sfis:
                 sfi = self.get_sfi(instance)
                 if sfi.get('sfc_encap') != sfc_encap: