fix bug 937. NSs are not deleted from database upon NSI deletion
[osm/NBI.git] / osm_nbi / engine.py
index f9fb1e7..3f83557 100644 (file)
@@ -68,7 +68,7 @@ class Engine(object):
         # Add new versions here
     }
 
         # Add new versions here
     }
 
-    def __init__(self):
+    def __init__(self, token_cache):
         self.db = None
         self.fs = None
         self.msg = None
         self.db = None
         self.fs = None
         self.msg = None
@@ -78,6 +78,7 @@ class Engine(object):
         self.logger = logging.getLogger("nbi.engine")
         self.map_topic = {}
         self.write_lock = None
         self.logger = logging.getLogger("nbi.engine")
         self.map_topic = {}
         self.write_lock = None
+        self.token_cache = token_cache
 
     def start(self, config):
         """
 
     def start(self, config):
         """
@@ -126,7 +127,7 @@ class Engine(object):
                 if config["authentication"]["backend"] == "keystone":
                     self.auth = AuthconnKeystone(config["authentication"], self.db, None)
                 else:
                 if config["authentication"]["backend"] == "keystone":
                     self.auth = AuthconnKeystone(config["authentication"], self.db, None)
                 else:
-                    self.auth = AuthconnInternal(config["authentication"], self.db, dict())
+                    self.auth = AuthconnInternal(config["authentication"], self.db, self.token_cache)
             if not self.operations:
                 if "resources_to_operations" in config["rbac"]:
                     resources_to_operations_file = config["rbac"]["resources_to_operations"]
             if not self.operations:
                 if "resources_to_operations" in config["rbac"]:
                     resources_to_operations_file = config["rbac"]["resources_to_operations"]
@@ -263,18 +264,21 @@ class Engine(object):
         with self.write_lock:
             return self.map_topic[topic].delete_list(session, _filter)
 
         with self.write_lock:
             return self.map_topic[topic].delete_list(session, _filter)
 
-    def del_item(self, session, topic, _id):
+    def del_item(self, session, topic, _id, not_send_msg=None):
         """
         Delete item by its internal id
         :param session: contains the used login username and working project
         :param topic: it can be: users, projects, vnfds, nsds, ...
         :param _id: server id of the item
         """
         Delete item by its internal id
         :param session: contains the used login username and working project
         :param topic: it can be: users, projects, vnfds, nsds, ...
         :param _id: server id of the item
+        :param not_send_msg: If False, message will not be sent to kafka.
+            If a list, message is not sent, but content is stored in this variable so that the caller can send this
+            message using its own loop. If None, message is sent
         :return: dictionary with deleted item _id. It raises exception if not found.
         """
         if topic not in self.map_topic:
             raise EngineException("Unknown topic {}!!!".format(topic), HTTPStatus.INTERNAL_SERVER_ERROR)
         with self.write_lock:
         :return: dictionary with deleted item _id. It raises exception if not found.
         """
         if topic not in self.map_topic:
             raise EngineException("Unknown topic {}!!!".format(topic), HTTPStatus.INTERNAL_SERVER_ERROR)
         with self.write_lock:
-            return self.map_topic[topic].delete(session, _id)
+            return self.map_topic[topic].delete(session, _id, not_send_msg=not_send_msg)
 
     def edit_item(self, session, topic, _id, indata=None, kwargs=None):
         """
 
     def edit_item(self, session, topic, _id, indata=None, kwargs=None):
         """