From: tierno Date: Wed, 27 Jun 2018 14:06:17 +0000 (+0200) Subject: Fixed VNF deletion NotFound reporting X-Git-Tag: BUILD_v4.0.1_1~9 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FRO.git;a=commitdiff_plain;h=cec213a7e459fa550beb5220b044d86b210d251f Fixed VNF deletion NotFound reporting Change-Id: I7de95f5123421103df96ca23ae2b155c7cb32de8 Signed-off-by: tierno --- diff --git a/openmanod b/openmanod index 4f308883..89511216 100755 --- 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.68-r578" +__version__ = "0.5.69-r579" version_date = "Jun 2018" database_version = 31 # expected database schema version diff --git a/osm_ro/db_base.py b/osm_ro/db_base.py index 1d8ee651..9b4432e8 100644 --- a/osm_ro/db_base.py +++ b/osm_ro/db_base.py @@ -652,10 +652,10 @@ class db_base(): self.logger.debug(cmd) self.cur.execute(cmd) number = self.cur.rowcount - if number==0: - return -HTTP_Not_Found, "No %s found with %s '%s'" %(error_item_text, what, uuid_name) - elif number>1 and not allow_serveral: - return -HTTP_Bad_Request, "More than one %s found with %s '%s'" %(error_item_text, what, uuid_name) + if number == 0: + raise db_base_Exception("No {} found with {} '{}'".format(error_item_text, what, uuid_name), http_code=HTTP_Not_Found) + elif number > 1 and not allow_serveral: + raise db_base_Exception("More than one {} found with {} '{}'".format(error_item_text, what, uuid_name), http_code=HTTP_Conflict) if allow_serveral: rows = self.cur.fetchall() else: @@ -667,7 +667,8 @@ class db_base(): def get_uuid(self, uuid): '''check in the database if this uuid is already present''' - for retry_ in range(0,2): + tries = 2 + while tries: try: with self.con: self.cur = self.con.cursor(mdb.cursors.DictCursor) @@ -675,9 +676,8 @@ class db_base(): rows = self.cur.fetchall() return self.cur.rowcount, rows except (mdb.Error, AttributeError) as e: - print "nfvo_db.get_uuid DB Exception %d: %s" % (e.args[0], e.args[1]) - r,c = self._format_error(e) - if r!=-HTTP_Request_Timeout or retry_==1: return r,c + self._format_error(e, tries) + tries -= 1 def get_uuid_from_name(self, table, name): '''Searchs in table the name and returns the uuid