ovs_lib: Fix native implementation of db_list
Move the code to list records into the transaction. Closes-Bug: #1473038 Closes-Bug: #1473049 Closes-Bug: #1475253 Change-Id: I9f367f5ba1ecc50b9bb94c6f52507033d0139611
This commit is contained in:
parent
213d02a997
commit
73207ddd5e
@ -351,42 +351,43 @@ class PortToBridgeCommand(BaseCommand):
|
||||
class DbListCommand(BaseCommand):
|
||||
def __init__(self, api, table, records, columns, if_exists):
|
||||
super(DbListCommand, self).__init__(api)
|
||||
self.requested_info = {'records': records, 'columns': columns,
|
||||
'table': table}
|
||||
self.table = self.api._tables[table]
|
||||
self.columns = columns or self.table.columns.keys() + ['_uuid']
|
||||
self.table = table
|
||||
self.columns = columns
|
||||
self.if_exists = if_exists
|
||||
if records:
|
||||
self.records = []
|
||||
for record in records:
|
||||
self.records = records
|
||||
|
||||
def run_idl(self, txn):
|
||||
table_schema = self.api._tables[self.table]
|
||||
columns = self.columns or table_schema.columns.keys() + ['_uuid']
|
||||
if self.records:
|
||||
row_uuids = []
|
||||
for record in self.records:
|
||||
try:
|
||||
self.records.append(idlutils.row_by_record(
|
||||
self.api.idl, table, record).uuid)
|
||||
row_uuids.append(idlutils.row_by_record(
|
||||
self.api.idl, self.table, record).uuid)
|
||||
except idlutils.RowNotFound:
|
||||
if self.if_exists:
|
||||
continue
|
||||
raise
|
||||
# NOTE(kevinbenton): this is converted to a RuntimeError
|
||||
# for compat with the vsctl version. It might make more
|
||||
# sense to change this to a RowNotFoundError in the future.
|
||||
raise RuntimeError(_LE(
|
||||
"Row doesn't exist in the DB. Request info: "
|
||||
"Table=%(table)s. Columns=%(columns)s. "
|
||||
"Records=%(records)s.") % {
|
||||
"table": self.table,
|
||||
"columns": self.columns,
|
||||
"records": self.records,
|
||||
})
|
||||
else:
|
||||
self.records = self.table.rows.keys()
|
||||
|
||||
def run_idl(self, txn):
|
||||
try:
|
||||
row_uuids = table_schema.rows.keys()
|
||||
self.result = [
|
||||
{
|
||||
c: idlutils.get_column_value(self.table.rows[uuid], c)
|
||||
for c in self.columns
|
||||
if not self.if_exists or uuid in self.table.rows
|
||||
c: idlutils.get_column_value(table_schema.rows[uuid], c)
|
||||
for c in columns
|
||||
}
|
||||
for uuid in self.records
|
||||
for uuid in row_uuids
|
||||
]
|
||||
except KeyError:
|
||||
# NOTE(kevinbenton): this is converted to a RuntimeError for compat
|
||||
# with the vsctl version. It might make more sense to change this
|
||||
# to a RowNotFoundError in the future.
|
||||
raise RuntimeError(_LE(
|
||||
"Row removed from DB during listing. Request info: "
|
||||
"Table=%(table)s. Columns=%(columns)s. "
|
||||
"Records=%(records)s.") % self.requested_info)
|
||||
|
||||
|
||||
class DbFindCommand(BaseCommand):
|
||||
|
Loading…
Reference in New Issue
Block a user