]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Merge "Handle non-index lookups in native OVSDB backend"
authorJenkins <jenkins@review.openstack.org>
Sun, 12 Apr 2015 21:28:15 +0000 (21:28 +0000)
committerGerrit Code Review <review@openstack.org>
Sun, 12 Apr 2015 21:28:15 +0000 (21:28 +0000)
1  2 
neutron/agent/ovsdb/native/commands.py
neutron/agent/ovsdb/native/idlutils.py
neutron/tests/functional/agent/test_ovs_lib.py

index 1c260009d97b01516f80abfd44a0ccab3042fe2a,7b5e746917a732b18d953c82592d230381915c82..bcb237cf10f4e696acea604f0bffc3d3f2c8b388
@@@ -20,13 -22,71 +22,77 @@@ from ovs import jsonrp
  from ovs import poller
  from ovs import stream
  
+ from neutron.common import exceptions
+ RowLookup = collections.namedtuple('RowLookup',
+                                    ['table', 'column', 'uuid_column'])
+ # Tables with no index in OVSDB and special record lookup rules
+ _LOOKUP_TABLE = {
+     'Controller': RowLookup('Bridge', 'name', 'controller'),
+     'Flow_Table': RowLookup('Flow_Table', 'name', None),
+     'IPFIX': RowLookup('Bridge', 'name', 'ipfix'),
+     'Mirror': RowLookup('Mirror', 'name', None),
+     'NetFlow': RowLookup('Bridge', 'name', 'netflow'),
+     'QoS': RowLookup('Port', 'name', 'qos'),
+     'Queue': RowLookup(None, None, None),
+     'sFlow': RowLookup('Bridge', 'name', 'sflow'),
+     'SSL': RowLookup('Open_vSwitch', None, 'ssl'),
+ }
+ _NO_DEFAULT = object()
+ class RowNotFound(exceptions.NeutronException):
+     message = _("Cannot find %(table)s with %(col)s=%(match)s")
+ def row_by_value(idl_, table, column, match, default=_NO_DEFAULT):
+     """Lookup an IDL row in a table by column/value"""
+     tab = idl_.tables[table]
+     for r in tab.rows.values():
+         if getattr(r, column) == match:
+             return r
+     if default is not _NO_DEFAULT:
+         return default
+     raise RowNotFound(table=table, col=column, match=match)
+ def row_by_record(idl_, table, record):
+     t = idl_.tables[table]
+     try:
+         if isinstance(record, uuid.UUID):
+             return t.rows[record]
+         uuid_ = uuid.UUID(record)
+         return t.rows[uuid_]
+     except ValueError:
+         # Not a UUID string, continue lookup by other means
+         pass
+     except KeyError:
+         raise RowNotFound(table=table, col='uuid', match=record)
+     rl = _LOOKUP_TABLE.get(table, RowLookup(table, get_index_column(t), None))
+     # no table means uuid only, no column is just SSL which we don't need
+     if rl.table is None:
+         raise ValueError(_("Table %s can only be queried by UUID") % table)
+     if rl.column is None:
+         raise NotImplementedError(_("'.' searches are not implemented"))
+     row = row_by_value(idl_, rl.table, rl.column, record)
+     if rl.uuid_column:
+         rows = getattr(row, rl.uuid_column)
+         if len(rows) != 1:
+             raise RowNotFound(table=table, col=_('record'), match=record)
+         row = rows[0]
+     return row
  
 +class ExceptionResult(object):
 +    def __init__(self, ex, tb):
 +        self.ex = ex
 +        self.tb = tb
 +
 +
  def get_schema_helper(connection):
      err, strm = stream.Stream.open_block(
          stream.Stream.open(connection))