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'.

Signed-off-by: Terry Wilson <[email protected]>
---
 python/ovs/db/idl.py |  2 +-
 tests/ovsdb-idl.at   | 12 ++++++++++--
 tests/test-ovsdb.c   | 28 +++++++++++++++++++++++++++-
 tests/test-ovsdb.py  | 11 +++++++++++
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index abb82154b..384428c3f 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -1731,7 +1731,7 @@ class Transaction(object):
                     and ovs.ovsuuid.is_valid_string(json[1])):
                 uuid = ovs.ovsuuid.from_string(json[1])
                 row = self._txn_rows.get(uuid, None)
-                if row and row._data is None:
+                if row and row._data is None and not row._persist_uuid:
                     return ["named-uuid", _uuid_name_from_uuid(uuid)]
             else:
                 return [self._substitute_uuids(elem) for elem in json]
diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at
index 5244358e3..638169ce6 100644
--- a/tests/ovsdb-idl.at
+++ b/tests/ovsdb-idl.at
@@ -2826,7 +2826,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_C],
             [0], [stdout], [stderr])
    AT_CHECK([sort stdout],
             [0], [$3])
-   AT_CHECK([grep $4 stderr], [0], [ignore])
+   m4_if([$4], [AT_CHECK([grep $4 stderr])], [0], [ignore])
    OVSDB_SERVER_SHUTDOWN
    AT_CLEANUP])
 
@@ -2838,7 +2838,7 @@ m4_define([OVSDB_CHECK_IDL_PERS_UUID_INSERT_PY],
             [0], [stdout], [stderr])
    AT_CHECK([sort stdout],
             [0], [$3])
-   AT_CHECK([grep $4 stderr], [0], [ignore])
+   m4_if([$4], [AT_CHECK([grep $4 stderr])], [0], [ignore])
    OVSDB_SERVER_SHUTDOWN
    AT_CLEANUP])
 
@@ -2876,6 +2876,14 @@ OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent 
uuid insert],
 ]],
   [['This UUID would duplicate a UUID already present within the table or 
deleted within the same transaction']])
 
+OVSDB_CHECK_IDL_PERS_UUID_INSERT([simple idl, persistent uuid insert uref],
+  [['insert_uuid_uref d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36 
689420a0-515b-4c0f-8eba-7ad59a344b54']],
+  [[000: empty
+001: commit, status=success
+002: table simple3: name= uset=[] uref=[689420a0-515b-4c0f-8eba-7ad59a344b54] 
uuid=d7f2845f-2e8d-46a9-8330-f6d0b7d2ca36
+002: table simple4: name= uuid=689420a0-515b-4c0f-8eba-7ad59a344b54
+003: done
+]])
 
 OVSDB_CHECK_IDL_PY([simple idl, python, add_op],
   [],
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index e88912693..685321f9c 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -2452,6 +2452,10 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
     struct ovsdb_idl_txn *txn;
     enum ovsdb_idl_txn_status status;
     bool increment = false;
+    /* FIXME ovsdb_idl_check_consistency() doesn't currently handle refs added
+     * in the same txn, so if any op does this, we need to skip the check until
+     * that is fixed */
+    bool skip_pre_commit_consistency_check = false;
 
     txn = ovsdb_idl_txn_create(idl);
     ovsdb_idl_check_consistency(idl);
@@ -2518,6 +2522,26 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
             }
             s = idltest_simple_insert_persist_uuid(txn, &s_uuid);
             idltest_simple_set_i(s, atoi(arg2));
+        } else if (!strcmp(name, "insert_uuid_uref")) {
+            struct idltest_simple3 *s3;
+            struct idltest_simple4 *s4;
+
+            if (!arg1 || !arg2) {
+                ovs_fatal(0,
+                          "\"insert_uuid_uref\" command requires 2 arguments");
+            }
+
+            struct uuid s3_uuid;
+            struct uuid s4_uuid;
+            if (!uuid_from_string(&s3_uuid, arg1) ||
+                !uuid_from_string(&s4_uuid, arg2)) {
+                 ovs_fatal(
+                    0, "\"insert_uuid_uref\" command requires 2 valid uuids");
+            }
+            s4 = idltest_simple4_insert_persist_uuid(txn, &s4_uuid);
+            s3 = idltest_simple3_insert_persist_uuid(txn, &s3_uuid);
+            idltest_simple3_set_uref(s3, &s4, 1);
+            skip_pre_commit_consistency_check = true;
         } else if (!strcmp(name, "delete")) {
             const struct idltest_simple *s;
 
@@ -2586,7 +2610,9 @@ idl_set(struct ovsdb_idl *idl, char *commands, int step)
         } else {
             ovs_fatal(0, "unknown command %s", name);
         }
-        ovsdb_idl_check_consistency(idl);
+        if (!skip_pre_commit_consistency_check) {
+            ovsdb_idl_check_consistency(idl);
+        }
     }
 
     status = ovsdb_idl_txn_commit_block(txn);
diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py
index ed47e2447..b690b4f07 100644
--- a/tests/test-ovsdb.py
+++ b/tests/test-ovsdb.py
@@ -518,6 +518,17 @@ def idl_set(idl, commands, step):
             s = txn.insert(idl.tables["simple"], new_uuid=uuid.UUID(args[0]),
                            persist_uuid=True)
             s.i = int(args[1])
+        elif name == "insert_uuid_uref":
+            if len(args) != 2:
+                sys.stderr.write('"set" command requires 2 argument\n')
+                sys.exit(1)
+
+            s4 = txn.insert(idl.tables["simple4"], new_uuid=uuid.UUID(args[1]),
+                            persist_uuid=True)
+            s3 = txn.insert(idl.tables["simple3"], new_uuid=uuid.UUID(args[0]),
+                            persist_uuid=True)
+            s3.uref = s4
+
         elif name == "add_op":
             if len(args) != 1:
                 sys.stderr.write('"add_op" command requires 1 argument\n')
-- 
2.47.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to