X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fdb_base.py;fp=osm_ro%2Fdb_base.py;h=9b4432e838f6032f3151d734832fb8bed5262613;hb=cec213a7e459fa550beb5220b044d86b210d251f;hp=1d8ee651550618ccba4a6a4449eeef71d53b7dfa;hpb=b42fd9bdcea865bd3c6d4a546a6f294ff69e1ef4;p=osm%2FRO.git 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