"number": {"type": "integer"},
"name": {"type": "string"}}}}}]])
+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",
+ "minInteger": 1}}}}}}}]])
+
# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
#
# Runs "test-ovsdb execute" with the given SCHEMA and each of the
m4_define([OVSDB_CHECK_EXECUTION],
[AT_SETUP([$1])
AT_KEYWORDS([ovsdb execute execution positive $5])
- OVS_CHECK_LCOV([test-ovsdb execute '$2' m4_foreach([txn], [$3], [ 'txn'])],
+ AT_CHECK([test-ovsdb execute '$2' m4_foreach([txn], [$3], [ 'txn'])],
[0], [stdout], [])
AT_CHECK([perl $srcdir/uuidfilt.pl stdout], [0], [$4])
AT_CLEANUP])
"rows": [{"name": "one", "number": 1}]}]]]],
[[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{}]
]])
-])
+
+OVSDB_CHECK_EXECUTION([insert and update constraints],
+ [CONSTRAINT_SCHEMA],
+ [[[[{"op": "insert",
+ "table": "constrained",
+ "row": {}}]]],
+ [[[{"op": "insert",
+ "table": "constrained",
+ "row": {"positive": -1}}]]],
+ [[[{"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],
+ [[[[{"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"]]]}}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 1]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": []}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 2]]}]]],
+ [[[{"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],
+ [[[[{"op": "declare",
+ "uuid-name": "row1"},
+ {"op": "declare",
+ "uuid-name": "row2"},
+ {"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"}]]],
+ [[[{"op": "insert",
+ "table": "a",
+ "row": {"a2b": ["set", [["uuid", "b516b960-5b19-4fc2-bb82-fe1cbd6d0241"]]]}}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]],
+ dnl Try the deletions again to make sure that the refcounts got rolled back.
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[[{"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]],
+ [[[{"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]},
+ {"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 1]]}]]]],
+ [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<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