From: tierno Date: Thu, 3 May 2018 15:51:43 +0000 (+0200) Subject: Fixed vnfpkg nspkg not inserted when conflict. X-Git-Tag: v4.0.0~8 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=refs%2Fchanges%2F61%2F6061%2F3 Fixed vnfpkg nspkg not inserted when conflict. Return nslcm-opp-id at DELETE /ns_instances_content Change-Id: I94047091168d89eeaf5b2246decc5a08bd443e04 Signed-off-by: tierno --- diff --git a/osm_nbi/engine.py b/osm_nbi/engine.py index 38bbe77..102d5a4 100644 --- a/osm_nbi/engine.py +++ b/osm_nbi/engine.py @@ -251,15 +251,15 @@ class Engine(object): raise EngineException("missing 'password'", HTTPStatus.UNPROCESSABLE_ENTITY) if not indata.get("projects"): raise EngineException("missing 'projects'", HTTPStatus.UNPROCESSABLE_ENTITY) - # check username not exist + # check username not exists if self.db.get_one(item, {"username": indata.get("username")}, fail_on_empty=False, fail_on_more=False): - raise EngineException("username '{}' exist".format(indata["username"]), HTTPStatus.CONFLICT) + raise EngineException("username '{}' exists".format(indata["username"]), HTTPStatus.CONFLICT) elif item == "projects": if not indata.get("name"): raise EngineException("missing 'name'") - # check name not exist + # check name not exists if self.db.get_one(item, {"name": indata.get("name")}, fail_on_empty=False, fail_on_more=False): - raise EngineException("name '{}' exist".format(indata["name"]), HTTPStatus.CONFLICT) + raise EngineException("name '{}' exists".format(indata["name"]), HTTPStatus.CONFLICT) elif item in ("vnfds", "nsds"): filter = {"id": indata["id"]} if id: @@ -267,7 +267,7 @@ class Engine(object): # TODO add admin to filter, validate rights self._add_read_filter(session, item, filter) if self.db.get_one(item, filter, fail_on_empty=False): - raise EngineException("{} with id '{}' already exist for this tenant".format(item[:-1], indata["id"]), + raise EngineException("{} with id '{}' already exists for this tenant".format(item[:-1], indata["id"]), HTTPStatus.CONFLICT) # TODO validate with pyangbind @@ -279,7 +279,7 @@ class Engine(object): pass elif item == "vim_accounts" or item == "sdns": if self.db.get_one(item, {"name": indata.get("name")}, fail_on_empty=False, fail_on_more=False): - raise EngineException("name '{}' already exist for {}".format(indata["name"], item), + raise EngineException("name '{}' already exists for {}".format(indata["name"], item), HTTPStatus.CONFLICT) def _format_new_data(self, session, item, indata): @@ -324,7 +324,7 @@ class Engine(object): :return: True package has is completely uploaded or False if partial content has been uplodaed. Raise exception on error """ - # Check that _id exist and it is valid + # Check that _id exists and it is valid current_desc = self.get_item(session, item, _id) content_range_text = headers.get("Content-Range") diff --git a/osm_nbi/html_public/version b/osm_nbi/html_public/version index 10340c4..b7021d1 100644 --- a/osm_nbi/html_public/version +++ b/osm_nbi/html_public/version @@ -1,3 +1,3 @@ -0.1.3 -Apr 2018 +0.1.4 +May 2018 diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index a72fa58..dda9946 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -603,6 +603,7 @@ class Server(object): _format = None method = "DONE" engine_item = None + rollback = None try: if not topic or not version or not item: raise NbiException("URL must contain at least 'topic/version/item'", HTTPStatus.METHOD_NOT_ALLOWED) @@ -663,6 +664,7 @@ class Server(object): _id = cherrypy.request.headers.get("Transaction-Id") if not _id: _id = self.engine.new_item(session, engine_item, {}, None, cherrypy.request.headers) + rollback = {"session": session, "item": engine_item, "_id": _id, "force": True} completed = self.engine.upload_content(session, engine_item, _id, indata, kwargs, cherrypy.request.headers) if completed: self._set_location_header(topic, version, item, _id) @@ -671,6 +673,7 @@ class Server(object): outdata = {"id": _id} elif item == "ns_instances_content": _id = self.engine.new_item(session, engine_item, indata, kwargs) + rollback = {"session": session, "item": engine_item, "_id": _id, "force": True} self.engine.ns_action(session, _id, "instantiate", {}, None) self._set_location_header(topic, version, item, _id) outdata = {"id": _id} @@ -692,7 +695,8 @@ class Server(object): cherrypy.response.status = HTTPStatus.OK.value else: # len(args) > 1 if item == "ns_instances_content": - self.engine.ns_action(session, _id, "terminate", {"autoremove": True}, None) + opp_id = self.engine.ns_action(session, _id, "terminate", {"autoremove": True}, None) + outdata = {"_id": opp_id} cherrypy.response.status = HTTPStatus.ACCEPTED.value else: force = kwargs.get("FORCE") @@ -717,10 +721,15 @@ class Server(object): raise NbiException("Method {} not allowed".format(method), HTTPStatus.METHOD_NOT_ALLOWED) return self._format_out(outdata, session, _format) except (NbiException, EngineException, DbException, FsException, MsgException) as e: - if hasattr(outdata, "close"): # is an open file - outdata.close() cherrypy.log("Exception {}".format(e)) cherrypy.response.status = e.http_code.value + if hasattr(outdata, "close"): # is an open file + outdata.close() + if rollback: + try: + self.engine.del_item(**rollback) + except Exception as e2: + cherrypy.log("Rollback Exception {}: {}".format(rollback, e2)) error_text = str(e) if isinstance(e, MsgException): error_text = "{} has been '{}' but other modules cannot be informed because an error on bus".format(