Merge "master" into "next".
[sliver-openvswitch.git] / tests / ovsdb-execution.at
index bb9d6cf..ca155a1 100644 (file)
@@ -1,7 +1,7 @@
 AT_BANNER([OVSDB -- execution])
 
 m4_define([ORDINAL_SCHEMA],
-  [[{"name": "mydb",
+  [[{"name": "ordinals",
      "tables": {
        "ordinals": {
          "columns": {
@@ -11,6 +11,20 @@ m4_define([ORDINAL_SCHEMA],
 m4_define([CONSTRAINT_SCHEMA],
   [[{"name": "constraints",
      "tables": {
+       "a": {
+         "columns": {
+           "a": {"type": "integer"},
+           "a2a": {"type": {"key": {"type": "uuid", "refTable": "a"},
+                            "min": 0, "max": "unlimited"}},
+           "a2b": {"type": {"key": {"type": "uuid", "refTable": "b"},
+                            "min": 0, "max": "unlimited"}}}},
+       "b": {
+         "columns": {
+           "b": {"type": "integer"},
+           "b2a": {"type": {"key": {"type": "uuid", "refTable": "a"},
+                            "min": 0, "max": "unlimited"}},
+           "b2b": {"type": {"key": {"type": "uuid", "refTable": "b"},
+                            "min": 0, "max": "unlimited"}}}},
        "constrained": {
          "columns": {
            "positive": {"type": {"key": {"type": "integer",
@@ -39,10 +53,12 @@ m4_define([OVSDB_CHECK_EXECUTION],
 m4_define([EXECUTION_EXAMPLES], [
 OVSDB_CHECK_EXECUTION([insert row, query table],
   [ORDINAL_SCHEMA], 
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": []}]]]],
   [[[{"uuid":["uuid","<0>"]}]
@@ -51,16 +67,20 @@ OVSDB_CHECK_EXECUTION([insert row, query table],
 
 OVSDB_CHECK_EXECUTION([insert rows, query by value],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}}]]],
-   [[[{"op": "insert",
+   [[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 1, "name": "one"}}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": [["name", "==", "zero"]]}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": [["name", "==", "one"]]}]]]],
   [[[{"uuid":["uuid","<0>"]}]
@@ -71,7 +91,8 @@ OVSDB_CHECK_EXECUTION([insert rows, query by value],
 
 OVSDB_CHECK_EXECUTION([insert rows, query by named-uuid],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"},
@@ -90,19 +111,23 @@ OVSDB_CHECK_EXECUTION([insert rows, query by named-uuid],
 
 OVSDB_CHECK_EXECUTION([insert rows, update rows by value],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"}]]],
-   [[[{"op": "insert",
+   [[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 1, "name": "one"},
        "uuid-name": "first"}]]],
-   [[[{"op": "update",
+   [[["ordinals",
+      {"op": "update",
        "table": "ordinals",
        "where": [["name", "==", "zero"]],
        "row": {"name": "nought"}}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": [],
        "sort": ["number"]}]]]],
@@ -114,19 +139,23 @@ OVSDB_CHECK_EXECUTION([insert rows, update rows by value],
 
 OVSDB_CHECK_EXECUTION([insert rows, mutate rows],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"}]]],
-   [[[{"op": "insert",
+   [[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 1, "name": "one"},
        "uuid-name": "first"}]]],
-   [[[{"op": "mutate",
+   [[["ordinals",
+      {"op": "mutate",
        "table": "ordinals",
        "where": [["name", "==", "zero"]],
        "mutations": [["number", "+=", 2]]}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": [],
        "sort": ["number"]}]]]],
@@ -138,7 +167,8 @@ OVSDB_CHECK_EXECUTION([insert rows, mutate rows],
 
 OVSDB_CHECK_EXECUTION([insert rows, delete by named-uuid],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"},
@@ -158,18 +188,22 @@ OVSDB_CHECK_EXECUTION([insert rows, delete by named-uuid],
 
 OVSDB_CHECK_EXECUTION([insert rows, delete rows by value],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"}]]],
-   [[[{"op": "insert",
+   [[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 1, "name": "one"},
        "uuid-name": "first"}]]],
-   [[[{"op": "delete",
+   [[["ordinals",
+      {"op": "delete",
        "table": "ordinals",
        "where": [["name", "==", "zero"]]}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": []}]]]],
   [[[{"uuid":["uuid","<0>"]}]
@@ -180,18 +214,22 @@ OVSDB_CHECK_EXECUTION([insert rows, delete rows by value],
 
 OVSDB_CHECK_EXECUTION([insert rows, delete by (non-matching) value],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"}]]],
-   [[[{"op": "insert",
+   [[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 1, "name": "one"},
        "uuid-name": "first"}]]],
-   [[[{"op": "delete",
+   [[["ordinals",
+      {"op": "delete",
        "table": "ordinals",
        "where": [["name", "==", "nought"]]}]]],
-   [[[{"op": "select",
+   [[["ordinals",
+      {"op": "select",
        "table": "ordinals",
        "where": [],
        "sort": ["number"]}]]]],
@@ -203,7 +241,8 @@ OVSDB_CHECK_EXECUTION([insert rows, delete by (non-matching) value],
 
 OVSDB_CHECK_EXECUTION([insert rows, delete all],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"},
        "uuid-name": "first"},
@@ -223,7 +262,8 @@ OVSDB_CHECK_EXECUTION([insert rows, delete all],
 
 OVSDB_CHECK_EXECUTION([insert row, query table, commit],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "select",
@@ -236,7 +276,8 @@ OVSDB_CHECK_EXECUTION([insert row, query table, commit],
 
 OVSDB_CHECK_EXECUTION([insert row, query table, commit durably],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "select",
@@ -249,7 +290,8 @@ OVSDB_CHECK_EXECUTION([insert row, query table, commit durably],
 
 OVSDB_CHECK_EXECUTION([equality wait with correct rows],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -268,7 +310,8 @@ OVSDB_CHECK_EXECUTION([equality wait with correct rows],
 
 OVSDB_CHECK_EXECUTION([equality wait with extra row],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -288,7 +331,8 @@ OVSDB_CHECK_EXECUTION([equality wait with extra row],
 
 OVSDB_CHECK_EXECUTION([equality wait with missing row],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -306,7 +350,8 @@ OVSDB_CHECK_EXECUTION([equality wait with missing row],
 
 OVSDB_CHECK_EXECUTION([inequality wait with correct rows],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -325,7 +370,8 @@ OVSDB_CHECK_EXECUTION([inequality wait with correct rows],
 
 OVSDB_CHECK_EXECUTION([inequality wait with extra row],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -345,7 +391,8 @@ OVSDB_CHECK_EXECUTION([inequality wait with extra row],
 
 OVSDB_CHECK_EXECUTION([inequality wait with missing row],
   [ORDINAL_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["ordinals",
+      {"op": "insert",
        "table": "ordinals",
        "row": {"number": 0, "name": "zero"}},
       {"op": "insert",
@@ -363,19 +410,131 @@ OVSDB_CHECK_EXECUTION([inequality wait with missing row],
 
 OVSDB_CHECK_EXECUTION([insert and update constraints],
   [CONSTRAINT_SCHEMA],
-  [[[[{"op": "insert",
+  [[[["constraints",
+      {"op": "insert",
        "table": "constrained",
        "row": {}}]]],
-   [[[{"op": "insert",
+   [[["constraints",
+      {"op": "insert",
        "table": "constrained",
        "row": {"positive": -1}}]]],
-   [[[{"op": "update",
+   [[["constraints",
+      {"op": "update",
        "table": "constrained",
        "where": [],
        "row": {"positive": -2}}]]]],
   [[[{"details":"0 is less than minimum allowed value 1","error":"constraint violation"}]
 [{"details":"-1 is less than minimum allowed value 1","error":"constraint violation"}]
 [{"details":"-2 is less than minimum allowed value 1","error":"constraint violation"}]
+]])
+
+OVSDB_CHECK_EXECUTION([referential integrity -- simple],
+  [CONSTRAINT_SCHEMA],
+  [[[["constraints",
+      {"op": "insert",
+       "table": "b",
+       "row": {"b": 1},
+       "uuid-name": "brow"},
+      {"op": "insert",
+       "table": "a",
+       "row": {"a": 0,
+               "a2b": ["set", [["named-uuid", "brow"]]]}},
+      {"op": "insert",
+       "table": "a",
+       "row": {"a": 1,
+               "a2b": ["set", [["named-uuid", "brow"]]]}},
+      {"op": "insert",
+       "table": "a",
+       "row": {"a": 2,
+               "a2b": ["set", [["named-uuid", "brow"]]]}}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": []}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 0]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": []}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 1]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": []}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 2]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": []}]]]],
+  [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]
+[{"count":1},{"details":"cannot delete b row <0> because of 3 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1},{"details":"cannot delete b row <0> because of 2 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1},{"details":"cannot delete b row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1}]
+[{"count":1}]
+]])
+
+OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
+  [CONSTRAINT_SCHEMA],
+  [[[["constraints",
+      {"op": "insert",
+       "table": "a",
+       "row": {"a": 0,
+               "a2b": ["set", [["named-uuid", "row2"]]],
+               "a2a": ["set", [["named-uuid", "row1"]]]},
+       "uuid-name": "row1"},
+      {"op": "insert",
+       "table": "b",
+       "row": {"b": 1,
+               "b2b": ["set", [["named-uuid", "row2"]]],
+               "b2a": ["set", [["named-uuid", "row1"]]]},
+       "uuid-name": "row2"}]]],
+   [[["constraints",
+      {"op": "insert",
+       "table": "a",
+       "row": {"a2b": ["set", [["uuid", "b516b960-5b19-4fc2-bb82-fe1cbd6d0241"]]]}}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 0]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": [["b", "==", 1]]}]]],
+   dnl Try the deletions again to make sure that the refcounts got rolled back.
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 0]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "b",
+       "where": [["b", "==", 1]]}]]],
+   [[["constraints",
+      {"op": "delete",
+       "table": "a",
+       "where": [["a", "==", 0]]},
+      {"op": "delete",
+       "table": "b",
+       "where": [["b", "==", 1]]}]]]],
+  [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
+[{"uuid":["uuid","<2>"]},{"details":"reference to nonexistent row <3>","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
+[{"count":1},{"count":1}]
 ]])])
 
 EXECUTION_EXAMPLES