Skip to content

Commit 0aa6a73

Browse files
otherwiseguyigsilya
authored andcommitted
python: ovsdb-idl: Fix persist_uuid references.
When inserting a Row with persist_uuid=True, the Row will have a 'uuid' element and not a 'named-uuid' element, so ensure that other operations in the transaction refer to the row by 'uuid'. Fixes: 55b9507 ("ovsdb-idl: Add the support to specify the uuid for row insert.") Signed-off-by: Terry Wilson <[email protected]> Signed-off-by: Ilya Maximets <[email protected]>
1 parent b11084d commit 0aa6a73

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

python/ovs/db/idl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ def _substitute_uuids(self, json):
17311731
and ovs.ovsuuid.is_valid_string(json[1])):
17321732
uuid = ovs.ovsuuid.from_string(json[1])
17331733
row = self._txn_rows.get(uuid, None)
1734-
if row and row._data is None:
1734+
if row and row._data is None and not row._persist_uuid:
17351735
return ["named-uuid", _uuid_name_from_uuid(uuid)]
17361736
else:
17371737
return [self._substitute_uuids(elem) for elem in json]

tests/ovsdb-idl.at

+10-2
Original file line numberDiff line numberDiff line change
@@ -2826,7 +2826,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_C],
28262826
[0], [stdout], [stderr])
28272827
AT_CHECK([sort stdout],
28282828
[0], [$3])
2829-
AT_CHECK([grep $4 stderr], [0], [ignore])
2829+
m4_if([$4], [], [], [AT_CHECK([grep $4 stderr], [0], [ignore])])
28302830
OVSDB_SERVER_SHUTDOWN
28312831
AT_CLEANUP])
28322832

@@ -2838,7 +2838,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_PY],
28382838
[0], [stdout], [stderr])
28392839
AT_CHECK([sort stdout],
28402840
[0], [$3])
2841-
AT_CHECK([grep $4 stderr], [0], [ignore])
2841+
m4_if([$4], [], [], [AT_CHECK([grep $4 stderr], [0], [ignore])])
28422842
OVSDB_SERVER_SHUTDOWN
28432843
AT_CLEANUP])
28442844

@@ -2876,6 +2876,14 @@ OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert],
28762876
]],
28772877
[['This UUID would duplicate a UUID already present within the table or deleted within the same transaction']])
28782878

2879+
OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert uref],
2880+
[['insert_uuid_uref d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36 689420a0-515b-4c0f-8eba-7ad59a344b54']],
2881+
[[000: empty
2882+
001: commit, status=success
2883+
002: table simple3: name= uset=[] uref=[689420a0-515b-4c0f-8eba-7ad59a344b54] uuid=d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36
2884+
002: table simple4: name= uuid=689420a0-515b-4c0f-8eba-7ad59a344b54
2885+
003: done
2886+
]])
28792887

28802888
OVSDB_CHECK_IDL_PY([simple idl, python, add_op],
28812889
[],

tests/test-ovsdb.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,10 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
24512451
struct ovsdb_idl_txn *txn;
24522452
enum ovsdb_idl_txn_status status;
24532453
bool increment = false;
2454+
/* FIXME: ovsdb_idl_check_consistency() doesn't currently handle refs added
2455+
* in the same txn, so if any op does this, we need to skip the check until
2456+
* that is fixed. */
2457+
bool skip_pre_commit_consistency_check = false;
24542458

24552459
txn = ovsdb_idl_txn_create(idl);
24562460
ovsdb_idl_check_consistency(idl);
@@ -2517,6 +2521,26 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
25172521
}
25182522
s = idltest_simple_insert_persist_uuid(txn, &s_uuid);
25192523
idltest_simple_set_i(s, atoi(arg2));
2524+
} else if (!strcmp(name, "insert_uuid_uref")) {
2525+
struct idltest_simple3 *s3;
2526+
struct idltest_simple4 *s4;
2527+
2528+
if (!arg1 || !arg2) {
2529+
ovs_fatal(0,
2530+
"\"insert_uuid_uref\" command requires 2 arguments");
2531+
}
2532+
2533+
struct uuid s3_uuid;
2534+
struct uuid s4_uuid;
2535+
if (!uuid_from_string(&s3_uuid, arg1) ||
2536+
!uuid_from_string(&s4_uuid, arg2)) {
2537+
ovs_fatal(
2538+
0, "\"insert_uuid_uref\" command requires 2 valid uuids");
2539+
}
2540+
s4 = idltest_simple4_insert_persist_uuid(txn, &s4_uuid);
2541+
s3 = idltest_simple3_insert_persist_uuid(txn, &s3_uuid);
2542+
idltest_simple3_set_uref(s3, &s4, 1);
2543+
skip_pre_commit_consistency_check = true;
25202544
} else if (!strcmp(name, "delete")) {
25212545
const struct idltest_simple *s;
25222546

@@ -2585,7 +2609,9 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
25852609
} else {
25862610
ovs_fatal(0, "unknown command %s", name);
25872611
}
2588-
ovsdb_idl_check_consistency(idl);
2612+
if (!skip_pre_commit_consistency_check) {
2613+
ovsdb_idl_check_consistency(idl);
2614+
}
25892615
}
25902616

25912617
status = ovsdb_idl_txn_commit_block(txn);

tests/test-ovsdb.py

+11
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,17 @@ def notify(event, row, updates=None):
518518
s = txn.insert(idl.tables["simple"], new_uuid=uuid.UUID(args[0]),
519519
persist_uuid=True)
520520
s.i = int(args[1])
521+
elif name == "insert_uuid_uref":
522+
if len(args) != 2:
523+
sys.stderr.write('"set" command requires 2 argument\n')
524+
sys.exit(1)
525+
526+
s4 = txn.insert(idl.tables["simple4"], new_uuid=uuid.UUID(args[1]),
527+
persist_uuid=True)
528+
s3 = txn.insert(idl.tables["simple3"], new_uuid=uuid.UUID(args[0]),
529+
persist_uuid=True)
530+
s3.uref = s4
531+
521532
elif name == "add_op":
522533
if len(args) != 1:
523534
sys.stderr.write('"add_op" command requires 1 argument\n')

0 commit comments

Comments
 (0)