Skip to content

Commit

Permalink
ovsdb: Fix mutation of newly inserted rows from Python IDL.
Browse files Browse the repository at this point in the history
This patch fixes the scenario, where the mutate operation on a row
is sent in the same transaction as row insert operation. It was
obvserved that this mutate operation was not getting committed
to the OVSDB.

To get around the above problem the "where" condition in an
mutate operation is modified to use the named-uuid to identify
a row created in the current transaction.

Signed-off-by: Amitabha Biswas <[email protected]>
Suggested-by: Richard Theis <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
azbiswas authored and blp committed Aug 30, 2016
1 parent 5802610 commit b3220c6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Alfredo Finelli [email protected]
Alin Serdean [email protected]
Ambika Arora [email protected]
Amit Bose [email protected]
Amitabha Biswas [email protected]
Andrew Evans [email protected]
Andrew Kampjes [email protected]
Andrew Lambeth [email protected]
Expand Down Expand Up @@ -416,6 +417,7 @@ Ralf Heiringhoff [email protected]
Ram Jothikumar [email protected]
Ramana Reddy [email protected]
Ray Li [email protected]
Richard Theis [email protected]
RishiRaj Maulick [email protected]
Rob Sherwood [email protected]
Robert Strickler [email protected]
Expand Down
8 changes: 7 additions & 1 deletion python/ovs/db/idl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,13 @@ def commit(self):
addop = False
op = {"table": row._table.name}
op["op"] = "mutate"
op["where"] = _where_uuid_equals(row.uuid)
if row._data is None:
# New row
op["where"] = self._substitute_uuids(
_where_uuid_equals(row.uuid))
else:
# Existing row
op["where"] = _where_uuid_equals(row.uuid)
op["mutations"] = []
if '_removes' in row._mutations.keys():
for col, dat in six.iteritems(row._mutations['_removes']):
Expand Down
14 changes: 10 additions & 4 deletions tests/ovsdb-idl.at
Original file line number Diff line number Diff line change
Expand Up @@ -1160,10 +1160,13 @@ OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN([set, simple3 idl-partial-update-set-c
]])

OVSDB_CHECK_IDL_PY([partial-set idl],
[['["idltest", {"op":"insert", "table":"simple3",
"row":{"name":"mySet1","uset":["set", [[ "uuid", "0005b872-f9e5-43be-ae02-3184b9680e75" ], [ "uuid", "000d2f6a-76af-412f-b59d-e7bcd3e84eff" ]]]} }, {"op":"insert", "table":"simple4", "row":{"name":"seed"}}]']
[['["idltest", {"op":"insert", "table":"simple3", "uuid-name":"newrow",
"row":{"name":"mySet1","uset":["set", [[ "uuid", "0005b872-f9e5-43be-ae02-3184b9680e75" ]]]} },
{"op":"insert", "table":"simple4", "row":{"name":"seed"}},
{"op":"mutate", "table":"simple3", "where":[["_uuid", "==", ["named-uuid", "newrow"]]],
"mutations": [["uset", "insert", ["set", [["uuid", "000d2f6a-76af-412f-b59d-e7bcd3e84eff"]]]]]}]']
],
['partialrenamesetadd' 'partialduplicateadd' 'partialsetdel' 'partialsetref' 'partialsetoverrideops'],
['partialrenamesetadd' 'partialduplicateadd' 'partialsetdel' 'partialsetref' 'partialsetoverrideops' 'partialsetmutatenew'],
[[000: name=mySet1 uset=[<0> <1>]
001: commit, status=success
002: name=String2 uset=[<0> <1> <2>]
Expand All @@ -1175,7 +1178,10 @@ OVSDB_CHECK_IDL_PY([partial-set idl],
008: name=String2 uset=[<0> <1> <3>]
009: commit, status=success
010: name=String2 uset=[<3>]
011: done
011: commit, status=success
012: name=String2 uset=[<3>]
012: name=String3 uset=[<4>]
013: done
]])

m4_define([OVSDB_CHECK_IDL_NOTIFY_PY],
Expand Down
6 changes: 6 additions & 0 deletions tests/test-ovsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ def notify(event, row, updates=None):
uuid.UUID("0026b3ba-571b-4729-8227-d860a5210ab8"))
row.__setattr__('uset',
[uuid.UUID("0026b3ba-571b-4729-8227-d860a5210ab8")])
elif name == 'partialsetmutatenew':
new_row41 = txn.insert(idl.tables["simple4"])
new_row41.__setattr__('name', 'new_row41')
new_row3 = txn.insert(idl.tables["simple3"])
setattr(new_row3, 'name', 'String3')
new_row3.addvalue('uset', new_row41.uuid)
else:
sys.stderr.write("unknown command %s\n" % name)
sys.exit(1)
Expand Down

0 comments on commit b3220c6

Please sign in to comment.