aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-03-15 15:41:54 -0700
committerBen Pfaff <blp@nicira.com>2010-03-17 14:24:56 -0700
commit7360012bdf64effd898242a58634267e203a2795 (patch)
tree8f49d0007ef10c3fadc14bf2789c8df5c307d1a6 /tests
parent17d18afbfd65619e830d551cb002441519cde059 (diff)
ovsdb: Add support for weak references.
Diffstat (limited to 'tests')
-rw-r--r--tests/automake.mk2
-rw-r--r--tests/ovsdb-execution.at162
-rwxr-xr-xtests/ovsdb-monitor-sort.pl49
-rw-r--r--tests/ovsdb-monitor.at62
-rwxr-xr-xtests/uuidfilt.pl12
5 files changed, 272 insertions, 15 deletions
diff --git a/tests/automake.mk b/tests/automake.mk
index d6f67839..ebf2a018 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -215,7 +215,7 @@ tests_test_ovsdb_SOURCES = \
tests/test-ovsdb.c \
tests/idltest.c \
tests/idltest.h
-EXTRA_DIST += tests/uuidfilt.pl
+EXTRA_DIST += tests/uuidfilt.pl tests/ovsdb-monitor-sort.pl
tests_test_ovsdb_LDADD = ovsdb/libovsdb.a lib/libopenvswitch.a $(SSL_LIBS)
# idltest schema and IDL
diff --git a/tests/ovsdb-execution.at b/tests/ovsdb-execution.at
index ed28b2a9..dc4f3e88 100644
--- a/tests/ovsdb-execution.at
+++ b/tests/ovsdb-execution.at
@@ -30,6 +30,30 @@ m4_define([CONSTRAINT_SCHEMA],
"positive": {"type": {"key": {"type": "integer",
"minInteger": 1}}}}}}}]])
+m4_define([WEAK_SCHEMA],
+ [[{"name": "weak",
+ "tables": {
+ "a": {
+ "columns": {
+ "a": {"type": "integer"},
+ "a2a": {"type": {"key": {"type": "uuid",
+ "refTable": "a",
+ "refType": "weak"},
+ "min": 0, "max": "unlimited"}},
+ "a2a1": {"type": {"key": {"type": "uuid",
+ "refTable": "a",
+ "refType": "weak"}}},
+ "a2b": {"type": {"key": {"type": "uuid",
+ "refTable": "b",
+ "refType": "weak"}}}}},
+ "b": {
+ "columns": {
+ "b": {"type": "integer"},
+ "b2a": {"type": {"key": {"type": "uuid",
+ "refTable": "a",
+ "refType": "weak"},
+ "min": 0, "max": "unlimited"}}}}}}]])
+
# OVSDB_CHECK_EXECUTION(TITLE, SCHEMA, TRANSACTIONS, OUTPUT, [KEYWORDS])
#
# Runs "test-ovsdb execute" with the given SCHEMA and each of the
@@ -551,6 +575,144 @@ OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
[{"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}]
+]])
+
+OVSDB_CHECK_EXECUTION([weak references],
+ [WEAK_SCHEMA],
+ [[[["weak",
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 0,
+ "a2a": ["set", [["named-uuid", "row1"],
+ ["named-uuid", "row2"],
+ ["uuid", "0e767b36-6822-4044-8307-d58467e04669"]]],
+ "a2a1": ["named-uuid", "row1"],
+ "a2b": ["named-uuid", "row3"]},
+ "uuid-name": "row1"},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 1,
+ "a2a": ["set", [["named-uuid", "row1"],
+ ["named-uuid", "row2"]]],
+ "a2a1": ["named-uuid", "row2"],
+ "a2b": ["named-uuid", "row3"]},
+ "uuid-name": "row2"},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 2,
+ "a2a": ["set", [["named-uuid", "row1"],
+ ["named-uuid", "row2"]]],
+ "a2a1": ["named-uuid", "row2"],
+ "a2b": ["named-uuid", "row4"]}},
+ {"op": "insert",
+ "table": "b",
+ "row": {"b": 2,
+ "b2a": ["named-uuid", "row1"]},
+ "uuid-name": "row3"},
+ {"op": "insert",
+ "table": "b",
+ "row": {"b": 3,
+ "b2a": ["named-uuid", "row2"]},
+ "uuid-name": "row4"}]]],
+ dnl Check that the nonexistent row UUID we added to row a0 was deleted,
+ dnl and that other rows were inserted as requested.
+ [[["weak",
+ {"op": "select",
+ "table": "a",
+ "where": [],
+ "columns": ["_uuid", "a2a", "a2a1", "a2b"],
+ "sort": ["a"]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "b",
+ "where": [],
+ "columns": ["_uuid", "b", "b2a"],
+ "sort": ["b"]}]]],
+ dnl Try to insert invalid all-zeros weak reference (the default) into
+ dnl "a2b", which requires exactly one value.
+ [[["weak",
+ {"op": "insert",
+ "table": "a",
+ "row": {}}]]],
+ dnl Try to delete row from "b" that is referred to by weak references
+ dnl from "a" table "a2b" column that requires exactly one value.
+ [[["weak",
+ {"op": "delete",
+ "table": "b",
+ "where": [["b", "==", 3]]}]]],
+ dnl Try to delete row from "a" that is referred to by weak references
+ dnl from "a" table "a2a1" column that requires exactly one value.
+ [[["weak",
+ {"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 1]]}]]],
+ dnl Delete the row that had the reference that caused the previous
+ dnl deletion to fail, then check that other rows are unchanged.
+ [[["weak",
+ {"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 2]]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "a",
+ "where": [],
+ "columns": ["_uuid", "a2a", "a2a1", "a2b"],
+ "sort": ["a"]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "b",
+ "where": [],
+ "columns": ["_uuid", "b", "b2a"],
+ "sort": ["b"]}]]],
+ dnl Delete row a0 then check that references to it were removed.
+ [[["weak",
+ {"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "a",
+ "where": [],
+ "columns": ["_uuid", "a2a", "a2a1", "a2b"],
+ "sort": ["a"]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "b",
+ "where": [],
+ "columns": ["_uuid", "b", "b2a"],
+ "sort": ["b"]}]]],
+ dnl Delete row a1 then check that references to it were removed.
+ [[["weak",
+ {"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 1]]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "a",
+ "where": [],
+ "columns": ["_uuid", "a2a", "a2a1", "a2b"],
+ "sort": ["a"]}]]],
+ [[["weak",
+ {"op": "select",
+ "table": "b",
+ "where": [],
+ "columns": ["_uuid", "b", "b2a"],
+ "sort": ["b"]}]]]],
+ [[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]},{"uuid":["uuid","<4>"]}]
+[{"rows":[{"_uuid":["uuid","<0>"],"a2a":["set",[["uuid","<0>"],["uuid","<1>"]]],"a2a1":["uuid","<0>"],"a2b":["uuid","<3>"]},{"_uuid":["uuid","<1>"],"a2a":["set",[["uuid","<0>"],["uuid","<1>"]]],"a2a1":["uuid","<1>"],"a2b":["uuid","<3>"]},{"_uuid":["uuid","<2>"],"a2a":["set",[["uuid","<0>"],["uuid","<1>"]]],"a2a1":["uuid","<1>"],"a2b":["uuid","<4>"]}]}]
+[{"rows":[{"_uuid":["uuid","<3>"],"b":2,"b2a":["uuid","<0>"]},{"_uuid":["uuid","<4>"],"b":3,"b2a":["uuid","<1>"]}]}]
+[{"uuid":["uuid","<5>"]},{"details":"Weak reference column \"a2b\" in \"a\" row <5> (inserted within this transaction) contained all-zeros UUID (probably as the default value for this column) but deleting this value caused a constraint volation because this column is not allowed to be empty.","error":"constraint violation"}]
+[{"count":1},{"details":"Deletion of 1 weak reference(s) to deleted (or never-existing) rows from column \"a2b\" in \"a\" row <2> caused this column to become empty, but constraints on this column disallow an empty column.","error":"constraint violation"}]
+[{"count":1},{"details":"Deletion of 1 weak reference(s) to deleted (or never-existing) rows from column \"a2a1\" in \"a\" row <2> caused this column to become empty, but constraints on this column disallow an empty column.","error":"constraint violation"}]
+[{"count":1}]
+[{"rows":[{"_uuid":["uuid","<0>"],"a2a":["set",[["uuid","<0>"],["uuid","<1>"]]],"a2a1":["uuid","<0>"],"a2b":["uuid","<3>"]},{"_uuid":["uuid","<1>"],"a2a":["set",[["uuid","<0>"],["uuid","<1>"]]],"a2a1":["uuid","<1>"],"a2b":["uuid","<3>"]}]}]
+[{"rows":[{"_uuid":["uuid","<3>"],"b":2,"b2a":["uuid","<0>"]},{"_uuid":["uuid","<4>"],"b":3,"b2a":["uuid","<1>"]}]}]
+[{"count":1}]
+[{"rows":[{"_uuid":["uuid","<1>"],"a2a":["uuid","<1>"],"a2a1":["uuid","<1>"],"a2b":["uuid","<3>"]}]}]
+[{"rows":[{"_uuid":["uuid","<3>"],"b":2,"b2a":["set",[]]},{"_uuid":["uuid","<4>"],"b":3,"b2a":["uuid","<1>"]}]}]
+[{"count":1}]
+[{"rows":[]}]
+[{"rows":[{"_uuid":["uuid","<3>"],"b":2,"b2a":["set",[]]},{"_uuid":["uuid","<4>"],"b":3,"b2a":["set",[]]}]}]
]])])
EXECUTION_EXAMPLES
diff --git a/tests/ovsdb-monitor-sort.pl b/tests/ovsdb-monitor-sort.pl
new file mode 100755
index 00000000..12034f74
--- /dev/null
+++ b/tests/ovsdb-monitor-sort.pl
@@ -0,0 +1,49 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+# Breaks lines read from <STDIN> into groups using blank lines as
+# group separators, then sorts lines within the groups for
+# reproducibility.
+
+sub compare_lines {
+ my ($a, $b) = @_;
+
+ my $u = '[0-9a-fA-F]';
+ my $uuid_re = "${u}{8}-${u}{4}-${u}{4}-${u}{4}-${u}{12}";
+ if ($a =~ /^$uuid_re/) {
+ if ($b =~ /^$uuid_re/) {
+ return substr($a, 36) cmp substr($b, 36);
+ } else {
+ return 1;
+ }
+ } elsif ($b =~ /^$uuid_re/) {
+ return -1;
+ } else {
+ return $a cmp $b;
+ }
+}
+
+sub output_group {
+ my (@group) = @_;
+ print "$_\n" foreach sort { compare_lines($a, $b) } @group;
+}
+
+my @group = ();
+while (<STDIN>) {
+ chomp;
+ if ($_ eq '') {
+ output_group(@group);
+ @group = ();
+ print "\n";
+ } else {
+ if (/^,/ && @group) {
+ $group[$#group] .= "\n" . $_;
+ } else {
+ push(@group, $_);
+ }
+ }
+}
+
+output_group(@group) if @group;
diff --git a/tests/ovsdb-monitor.at b/tests/ovsdb-monitor.at
index 16e24719..0f29a05b 100644
--- a/tests/ovsdb-monitor.at
+++ b/tests/ovsdb-monitor.at
@@ -1,6 +1,6 @@
AT_BANNER([OVSDB -- ovsdb-server monitors])
-# OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], MONITOR-ARGS,
+# OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], DB, TABLE,
# TRANSACTIONS, OUTPUT, [KEYWORDS])
#
# Creates a database with the given SCHEMA, starts an ovsdb-server on
@@ -17,29 +17,29 @@ AT_BANNER([OVSDB -- ovsdb-server monitors])
# TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
m4_define([OVSDB_CHECK_MONITOR],
[AT_SETUP([$1])
- AT_KEYWORDS([ovsdb server monitor positive $7])
+ AT_KEYWORDS([ovsdb server monitor positive $8])
AT_DATA([schema], [$2
])
AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
m4_foreach([txn], [$3],
[AT_CHECK([ovsdb-tool transact db 'txn'], [0], [ignore], [ignore])])
AT_CHECK([ovsdb-server --detach --pidfile=$PWD/server-pid --remote=punix:socket --unixctl=$PWD/unixctl db], [0], [ignore], [ignore])
- AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid -d json monitor --format=csv unix:socket ordinals $4 > output],
+ AT_CHECK([ovsdb-client --detach --pidfile=$PWD/client-pid -d json monitor --format=csv unix:socket $4 $5 > output],
[0], [ignore], [ignore], [kill `cat server-pid`])
- m4_foreach([txn], [$5],
+ m4_foreach([txn], [$6],
[AT_CHECK([ovsdb-client transact unix:socket 'txn'], [0],
[ignore], [ignore], [kill `cat server-pid client-pid`])])
- AT_CHECK([ovsdb-client transact unix:socket '[[]]'], [0],
+ AT_CHECK([ovsdb-client transact unix:socket '[["$4"]]'], [0],
[ignore], [ignore], [kill `cat server-pid client-pid`])
AT_CHECK([ovs-appctl -t $PWD/unixctl -e exit], [0], [ignore], [ignore])
OVS_WAIT_UNTIL([test ! -e server-pid && test ! -e client-pid])
- AT_CHECK([perl $srcdir/uuidfilt.pl output], [0], [$6], [ignore])
+ AT_CHECK([perl $srcdir/ovsdb-monitor-sort.pl < output | perl $srcdir/uuidfilt.pl], [0], [$7], [ignore])
AT_CLEANUP])
OVSDB_CHECK_MONITOR([monitor insert into empty table],
[ORDINAL_SCHEMA],
[],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "insert",
"table": "ordinals",
@@ -54,7 +54,7 @@ OVSDB_CHECK_MONITOR([monitor insert into populated table],
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "insert",
"table": "ordinals",
@@ -72,7 +72,7 @@ OVSDB_CHECK_MONITOR([monitor delete],
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "delete",
"table": "ordinals",
@@ -90,7 +90,7 @@ OVSDB_CHECK_MONITOR([monitor row update],
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "update",
"table": "ordinals",
@@ -110,7 +110,7 @@ OVSDB_CHECK_MONITOR([monitor no-op row updates],
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "update",
"table": "ordinals",
@@ -133,7 +133,7 @@ OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "insert",
"table": "ordinals",
@@ -150,14 +150,13 @@ row,action,name,number,_version
<2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
]])
-
OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
[ORDINAL_SCHEMA],
[[[["ordinals",
{"op": "insert",
"table": "ordinals",
"row": {"number": 10, "name": "ten"}}]]]],
- [ordinals],
+ [ordinals], [ordinals],
[[[["ordinals",
{"op": "insert",
"table": "ordinals",
@@ -180,3 +179,38 @@ row,action,name,number,_version
<2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
]])
+OVSDB_CHECK_MONITOR([monitor weak reference change],
+ [WEAK_SCHEMA],
+ [[[["weak",
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 0,
+ "a2a1": ["named-uuid", "a0"],
+ "a2b": ["named-uuid", "b2"]},
+ "uuid-name": "a0"},
+ {"op": "insert",
+ "table": "a",
+ "row": {"a": 1,
+ "a2a": ["named-uuid", "a0"],
+ "a2a1": ["named-uuid", "a1"],
+ "a2b": ["named-uuid", "b2"]},
+ "uuid-name": "a1"},
+ {"op": "insert",
+ "table": "b",
+ "row": {"b": 2},
+ "uuid-name": "b2"}]]]],
+ [weak], [a],
+ [[[["weak",
+ {"op": "delete",
+ "table": "a",
+ "where": [["a", "==", 0]]}]]]],
+ [[row,action,a,a2a,a2b,a2a1,_version
+<0>,initial,0,"[""set"",[]]","[""uuid"",""<1>""]","[""uuid"",""<0>""]","[""uuid"",""<2>""]"
+<3>,initial,1,"[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<3>""]","[""uuid"",""<4>""]"
+
+row,action,a,a2a,a2b,a2a1,_version
+<0>,delete,0,"[""set"",[]]","[""uuid"",""<1>""]","[""uuid"",""<0>""]","[""uuid"",""<2>""]"
+<3>,old,,"[""uuid"",""<0>""]",,,
+,new,1,"[""set"",[]]","[""uuid"",""<1>""]","[""uuid"",""<3>""]","[""uuid"",""<5>""]"
+]])
+
diff --git a/tests/uuidfilt.pl b/tests/uuidfilt.pl
index 6f003a52..835f13b5 100755
--- a/tests/uuidfilt.pl
+++ b/tests/uuidfilt.pl
@@ -13,9 +13,21 @@ sub lookup_uuid {
return "<$uuids{$uuid}>";
}
+sub sort_set {
+ my ($s) = @_;
+ my (@uuids) = sort { $a <=> $b } (grep(/\d+/, split(/(\d+)/, $s)));
+ return '["set",[' . join(',', map('["uuid","<' . $_ . '>"]', @uuids)) . ']]';
+}
+
my $u = '[0-9a-fA-F]';
my $uuid_re = "${u}{8}-${u}{4}-${u}{4}-${u}{4}-${u}{12}";
while (<>) {
s/($uuid_re)/lookup_uuid($1)/eg;
+
+ # Sort sets like this:
+ # [["uuid","<1>"],["uuid","<0>"]]
+ # to look like this:
+ # [["uuid","<0>"],["uuid","<1>"]]
+ s/(\["set",\[(,?\["uuid","<\d+>"\])+\]\])/sort_set($1)/ge;
print $_;
}