__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
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:
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)
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