More consistemcy updates to the database layer
Add "RETURNING foo_id" to all UPDATE calls, so we can return it to
callers. Also make sure that all UPDATEs get commits to match.
Change-Id: I2fa417dcb38a5612bbb9dac102718430d73343af
diff --git a/db/db.py b/db/db.py
index 5853627..dd4ba91 100644
--- a/db/db.py
+++ b/db/db.py
@@ -334,7 +334,7 @@
if port is None:
raise InputError("Port ID %d does not exist" % int(port_id))
try:
- sql = "UPDATE port SET is_locked=%s WHERE port_id=%s"
+ sql = "UPDATE port SET is_locked=%s WHERE port_id=%s RETURNING port_id"
data = (is_locked, port_id)
self.cursor.execute(sql, data)
port_id = self.cursor.fetchone()[0]
@@ -357,7 +357,7 @@
else:
raise InputError("Port mode %s is not valid" % mode)
try:
- sql = "UPDATE port SET is_trunk=%s WHERE port_id=%s"
+ sql = "UPDATE port SET is_trunk=%s WHERE port_id=%s RETURNING port_id"
data = (is_trunk, port_id)
self.cursor.execute(sql, data)
port_id = self.cursor.fetchone()[0]
@@ -380,12 +380,15 @@
raise InputError("VLAN ID %d does not exist" % int(vlan_id))
try:
- sql = "UPDATE port SET current_vlan_id=%s WHERE port_id=%s"
+ sql = "UPDATE port SET current_vlan_id=%s WHERE port_id=%s RETURNING port_id"
data = (vlan_id, port_id)
self.cursor.execute(sql, data)
+ port_id = self.cursor.fetchone()[0]
+ self.connection.commit()
except:
self.connection.rollback()
raise
+ return port_id
def restore_default_vlan(self, port_id):
port = self.get_port_by_id(port_id)
@@ -396,12 +399,15 @@
raise CriticalError("The port is locked")
try:
- sql = "UPDATE port SET current_vlan_id=base_vlan_id WHERE port_id=%s"
+ sql = "UPDATE port SET current_vlan_id=base_vlan_id WHERE port_id=%s RETURNING port_id"
data = (port_id,)
self.cursor.execute(sql, data)
+ port_id = self.cursor.fetchone()[0]
+ self.connection.commit()
except:
self.connection.rollback()
raise
+ return port_id
def _dump_table(self, table):
result = []