Skip to content

Commit c35ff51

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 3db925a commit c35ff51

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

python/ovs/db/idl.py

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

tests/ovsdb-idl.at

+10-2
Original file line numberDiff line numberDiff line change
@@ -2812,7 +2812,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_C],
28122812
[0], [stdout], [stderr])
28132813
AT_CHECK([sort stdout],
28142814
[0], [$3])
2815-
AT_CHECK([grep $4 stderr], [0], [ignore])
2815+
m4_if([$4], [], [], [AT_CHECK([grep $4 stderr], [0], [ignore])])
28162816
OVSDB_SERVER_SHUTDOWN
28172817
AT_CLEANUP])
28182818

@@ -2824,7 +2824,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_PY],
28242824
[0], [stdout], [stderr])
28252825
AT_CHECK([sort stdout],
28262826
[0], [$3])
2827-
AT_CHECK([grep $4 stderr], [0], [ignore])
2827+
m4_if([$4], [], [], [AT_CHECK([grep $4 stderr], [0], [ignore])])
28282828
OVSDB_SERVER_SHUTDOWN
28292829
AT_CLEANUP])
28302830

@@ -2862,6 +2862,14 @@ OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert],
28622862
]],
28632863
[['This UUID would duplicate a UUID already present within the table or deleted within the same transaction']])
28642864

2865+
OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert uref],
2866+
[['insert_uuid_uref d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36 689420a0-515b-4c0f-8eba-7ad59a344b54']],
2867+
[[000: empty
2868+
001: commit, status=success
2869+
002: table simple3: name= uset=[] uref=[689420a0-515b-4c0f-8eba-7ad59a344b54] uuid=d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36
2870+
002: table simple4: name= uuid=689420a0-515b-4c0f-8eba-7ad59a344b54
2871+
003: done
2872+
]])
28652873

28662874
m4_define([OVSDB_CHECK_IDL_CHANGE_AWARE],
28672875
[AT_SETUP([simple idl, database change aware, online conversion - $1])

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

+10
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ def notify(event, row, updates=None):
451451
s = txn.insert(idl.tables["simple"], new_uuid=uuid.UUID(args[0]),
452452
persist_uuid=True)
453453
s.i = int(args[1])
454+
elif name == "insert_uuid_uref":
455+
if len(args) != 2:
456+
sys.stderr.write('"set" command requires 2 argument\n')
457+
sys.exit(1)
458+
459+
s4 = txn.insert(idl.tables["simple4"], new_uuid=uuid.UUID(args[1]),
460+
persist_uuid=True)
461+
s3 = txn.insert(idl.tables["simple3"], new_uuid=uuid.UUID(args[0]),
462+
persist_uuid=True)
463+
s3.uref = s4
454464
elif name == "delete":
455465
if len(args) != 1:
456466
sys.stderr.write('"delete" command requires 1 argument\n')

0 commit comments

Comments
 (0)