]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
ovs_lib: Fix native implementation of db_list
authorYAMAMOTO Takashi <yamamoto@midokura.com>
Thu, 16 Jul 2015 10:56:21 +0000 (19:56 +0900)
committerYAMAMOTO Takashi <yamamoto@midokura.com>
Mon, 20 Jul 2015 23:22:48 +0000 (08:22 +0900)
Move the code to list records into the transaction.

Closes-Bug: #1473038
Closes-Bug: #1473049
Closes-Bug: #1475253
Change-Id: I9f367f5ba1ecc50b9bb94c6f52507033d0139611

neutron/agent/ovsdb/native/commands.py

index 973c4cac1f4c26bd5fbff8097c8bf7a09b720202..17e5e525ce2b49a40d8ea6b5a1fbabc4e12b7a55 100644 (file)
@@ -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:
-            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
-                }
-                for uuid in self.records
-            ]
-        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)
+            row_uuids = table_schema.rows.keys()
+        self.result = [
+            {
+                c: idlutils.get_column_value(table_schema.rows[uuid], c)
+                for c in columns
+            }
+            for uuid in row_uuids
+        ]
 
 
 class DbFindCommand(BaseCommand):