Skip to content

Commit

Permalink
python/ovs/db/idl.py: Transaction._substitute doesn't handle list/tuple
Browse files Browse the repository at this point in the history
Since Transaction._substitute doesn't substitute elements of list/tuple,
setting list references results in transaction error. Teach it such case.

Example:
{"op": "update",
 "row":{"bridges":["set",[["uuid",
                           "1f42bc19-307f-42e7-a9c0-c12178bd8b51"],
                          ["uuid",
                           "f97e0c76-7146-489d-9bed-29bc704f65fe"]]]},
 "table": "Open_vSwitch",
 "where":[["_uuid", "==", ["uuid",
                           "20c2a046-ae7e-4453-a576-11034db24985"]]]}

In the above case, uuid in "row" aren't replaced by "named-uuid" because
the function doesn't look into elements of lists.
When list/tuple is found, look into elements recursively.

Signed-off-by: Isaku Yamahata <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Isaku Yamahata authored and blp committed Sep 13, 2012
1 parent 158edc8 commit 225b582
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python/ovs/db/idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,8 @@ def _substitute_uuids(self, json):
row = self._txn_rows.get(uuid, None)
if row and row._data is None:
return ["named-uuid", _uuid_name_from_uuid(uuid)]
else:
return [self._substitute_uuids(elem) for elem in json]
return json

def __disassemble(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/ovsdb-idl.at
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,13 @@ OVSDB_CHECK_IDL([external-linking idl, consistent ops],
002: i=1 k=1 ka=[] l2=0 uuid=<1>
003: done
]])

OVSDB_CHECK_IDL_PY([external-linking idl, insert ops],
[],
[['linktest']],
[[000: empty
001: commit, status=success
002: i=1 k=1 ka=[1] l2= uuid=<0>
002: i=2 k=1 ka=[1 2] l2= uuid=<1>
003: done
]])
11 changes: 10 additions & 1 deletion tests/test-ovsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def print_idl(idl, step):
for row in l2.itervalues():
s = ["%03d: i=%s l1=" % (step, row.i)]
if row.l1:
s.append(str(row.l1.i))
s.append(str(row.l1[0].i))
s.append(" uuid=%s" % row.uuid)
print(''.join(s))
n += 1
Expand Down Expand Up @@ -312,6 +312,15 @@ def idl_set(idl, commands, step):
sys.stdout.flush()
txn.abort()
return
elif name == "linktest":
l1_0 = txn.insert(idl.tables["link1"])
l1_0.i = 1
l1_0.k = [l1_0]
l1_0.ka = [l1_0]
l1_1 = txn.insert(idl.tables["link1"])
l1_1.i = 2
l1_1.k = [l1_0]
l1_1.ka = [l1_0, l1_1]
else:
sys.stderr.write("unknown command %s\n" % name)
sys.exit(1)
Expand Down

0 comments on commit 225b582

Please sign in to comment.