Merge "OVS native DBListcommand if_exists support"

This commit is contained in:
Jenkins 2015-07-03 04:24:20 +00:00 committed by Gerrit Code Review
commit 67ceaa4840
2 changed files with 42 additions and 10 deletions

View File

@ -351,24 +351,42 @@ 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.if_exists = if_exists
if records:
self.records = [
idlutils.row_by_record(self.api.idl, table, record).uuid
for record in records]
self.records = []
for record in records:
try:
self.records.append(idlutils.row_by_record(
self.api.idl, table, record).uuid)
except idlutils.RowNotFound:
if self.if_exists:
continue
raise
else:
self.records = self.table.rows.keys()
def run_idl(self, txn):
self.result = [
{
c: idlutils.get_column_value(self.table.rows[uuid], c)
for c in self.columns
}
for uuid in self.records
]
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)
class DbFindCommand(BaseCommand):

View File

@ -14,6 +14,7 @@
# under the License.
import collections
import mock
import uuid
from neutron.agent.common import ovs_lib
@ -197,6 +198,19 @@ class OVSBridgeTestCase(OVSBridgeTestBase):
expected = set([x.vif_id for x in vif_ports])
self.assertEqual(expected, ports)
def test_get_vif_port_set_with_missing_port(self):
self.create_ovs_port()
vif_ports = [self.create_ovs_vif_port()]
# return an extra port to make sure the db list ignores it
orig = self.br.get_port_name_list
new_port_name_list = lambda: orig() + ['anotherport']
mock.patch.object(self.br, 'get_port_name_list',
new=new_port_name_list).start()
ports = self.br.get_vif_port_set()
expected = set([vif_ports[0].vif_id])
self.assertEqual(expected, ports)
def test_get_port_tag_dict(self):
# Simple case tested in port test_set_get_clear_db_val
pass