Added coverage tests in tox
[osm/NBI.git] / osm_nbi / nbi.py
index 3172846..6c63ad8 100644 (file)
@@ -307,9 +307,9 @@ valid_url_methods = {
                                         "nsd": {"METHODS": ("GET",),  # descriptor inside package
                                                 "ROLE_PERMISSION": "nsds:id:content:"
                                                 },
-                                        "artifacts": {"*": {"METHODS": ("GET",),
-                                                            "ROLE_PERMISSION": "nsds:id:nsd_artifact:"
-                                                            }
+                                        "artifacts": {"METHODS": ("GET",),
+                                                      "ROLE_PERMISSION": "nsds:id:nsd_artifact:",
+                                                      "*": None,
                                                       }
                                         }
                                },
@@ -344,9 +344,9 @@ valid_url_methods = {
                                       "vnfd": {"METHODS": ("GET", ),  # descriptor inside package
                                                "ROLE_PERMISSION": "vnfds:id:content:"
                                                },
-                                      "artifacts": {"*": {"METHODS": ("GET", ),
-                                                          "ROLE_PERMISSION": "vnfds:id:vnfd_artifact:"
-                                                          }
+                                      "artifacts": {"METHODS": ("GET", ),
+                                                    "ROLE_PERMISSION": "vnfds:id:vnfd_artifact:",
+                                                    "*": None,
                                                     },
                                       "action": {"METHODS": ("POST", ),
                                                  "ROLE_PERMISSION": "vnfds:id:action:"
@@ -408,6 +408,12 @@ valid_url_methods = {
                                        "ROLE_PERMISSION": "vnf_instances:id:"
                                        }
                               },
+            "subscriptions": {"METHODS": ("GET", "POST"),
+                              "ROLE_PERMISSION": "ns_subscriptions:",
+                              "<ID>": {"METHODS": ("GET", "DELETE"),
+                                       "ROLE_PERMISSION": "ns_subscriptions:id:"
+                                       }
+                              },
         }
     },
     "nst": {
@@ -428,9 +434,9 @@ valid_url_methods = {
                                             "nst": {"METHODS": ("GET",),  # descriptor inside package
                                                     "ROLE_PERMISSION": "slice_templates:id:content:"
                                                     },
-                                            "artifacts": {"*": {"METHODS": ("GET",),
-                                                                "ROLE_PERMISSION": "slice_templates:id:content:"
-                                                                }
+                                            "artifacts": {"METHODS": ("GET",),
+                                                          "ROLE_PERMISSION": "slice_templates:id:content:",
+                                                          "*": None
                                                           }
                                             }
                                    },
@@ -861,7 +867,9 @@ class Server(object):
             elif "<ID>" in reference:
                 reference = reference["<ID>"]
             elif "*" in reference:
-                reference = reference["*"]
+                # if there is content
+                if reference["*"]:
+                    reference = reference["*"]
                 break
             else:
                 raise NbiException("Unexpected URL item {}".format(arg), HTTPStatus.METHOD_NOT_ALLOWED)
@@ -1006,8 +1014,7 @@ class Server(object):
             engine_session = self._manage_admin_query(token_info, kwargs, method, _id)
             indata = self._format_in(kwargs)
             engine_topic = topic
-            if topic == "subscriptions":
-                engine_topic = main_topic + "_" + topic
+
             if item and topic != "pm_jobs":
                 engine_topic = item
 
@@ -1036,6 +1043,9 @@ class Server(object):
             if engine_topic == "vims":   # TODO this is for backward compatibility, it will be removed in the future
                 engine_topic = "vim_accounts"
 
+            if topic == "subscriptions":
+                engine_topic = main_topic + "_" + topic
+
             if method == "GET":
                 if item in ("nsd_content", "package_content", "artifacts", "vnfd", "nsd", "nst", "nst_content"):
                     if item in ("vnfd", "nsd", "nst"):
@@ -1109,6 +1119,14 @@ class Server(object):
                     self._set_location_header(main_topic, version, "vnfpkg_op_occs", _id)
                     outdata = {"id": _id}
                     cherrypy.response.status = HTTPStatus.ACCEPTED.value
+                elif topic == "subscriptions":
+                    _id, _ = self.engine.new_item(rollback, engine_session, engine_topic, indata, kwargs)
+                    self._set_location_header(main_topic, version, topic, _id)
+                    link = {}
+                    link["self"] = cherrypy.response.headers["Location"]
+                    outdata = {"id": _id, "filter": indata["filter"], "callbackUri": indata["CallbackUri"],
+                               "_links": link}
+                    cherrypy.response.status = HTTPStatus.CREATED.value
                 else:
                     _id, op_id = self.engine.new_item(rollback, engine_session, engine_topic, indata, kwargs,
                                                       cherrypy.request.headers)
@@ -1201,6 +1219,9 @@ class Server(object):
                     if rollback_item.get("operation") == "set":
                         self.engine.db.set_one(rollback_item["topic"], {"_id": rollback_item["_id"]},
                                                rollback_item["content"], fail_on_empty=False)
+                    elif rollback_item.get("operation") == "del_list":
+                        self.engine.db.del_list(rollback_item["topic"], rollback_item["filter"], 
+                                                fail_on_empty=False)
                     else:
                         self.engine.db.del_one(rollback_item["topic"], {"_id": rollback_item["_id"]},
                                                fail_on_empty=False)