1 AT_BANNER([OVSDB -- ovsdb-server monitors])
3 OVS_START_SHELL_HELPERS
4 # ovsdb_check_monitor SCHEMA_FUNC DB TABLE OUTPUT COLUMNS
5 # PRE-MONITOR-TXN... -- TRANSACTION...
6 ovsdb_check_monitor () {
7 local schema_func=$1 db=$2 table=$3 output=$4 columns=$5
8 shift; shift; shift; shift; shift
10 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
11 while test "$1" != "--"; do
12 AT_CHECK([ovsdb-tool transact db "$1"], [0], [ignore], [ignore])
16 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file db > ovsdb-server.stdout 2> ovsdb-server.stderr],
18 on_exit 'kill `cat ovsdb-server.pid`'
19 if test "$IS_WIN32" = "yes"; then
20 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --log-file -d json monitor --format=csv unix:socket $db $table $columns > output 2> ovsdb-client.stderr &],
21 [0], [ignore], [ignore])
24 AT_CHECK([ovsdb-client -vjsonrpc --detach --no-chdir --pidfile --log-file -d json monitor --format=csv unix:socket $db $table $columns > output 2> ovsdb-client.stderr],
25 [0], [ignore], [ignore])
27 on_exit 'kill `cat ovsdb-client.pid`'
28 for txn in ${1+"$@"} '[["'$db'"]]'; do
29 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
31 OVS_APP_EXIT_AND_WAIT_BY_TARGET([ovsdb-server], [ovsdb-server.pid])
32 OVS_WAIT_UNTIL([test ! -e ovsdb-client.pid])
33 AT_CHECK_UNQUOTED([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0], [$output], [ignore])
37 # OVSDB_CHECK_MONITOR(TITLE, SCHEMA, [PRE-MONITOR-TXN], DB, TABLE,
38 # TRANSACTIONS, OUTPUT, [COLUMNS], [KEYWORDS])
40 # Creates a database with the given SCHEMA, starts an ovsdb-server on
41 # that database, and runs each of the TRANSACTIONS (which should be a
42 # quoted list of quoted strings) against it with ovsdb-client one at a
43 # time. COLUMNS, if specified, is passed to ovsdb-client as the set
44 # of columns and operations to select.
46 # Checks that the overall output is OUTPUT, but UUIDs in the output
47 # are replaced by markers of the form <N> where N is a number. The
48 # first unique UUID is replaced by <0>, the next by <1>, and so on.
49 # If a given UUID appears more than once it is always replaced by the
52 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
53 m4_define([OVSDB_CHECK_MONITOR],
55 AT_KEYWORDS([ovsdb server monitor positive $9])
56 AT_CAPTURE_FILE([ovsdb-server.log])
57 AT_CAPTURE_FILE([ovsdb-server.stdout])
58 AT_CAPTURE_FILE([ovsdb-server.stderr])
59 AT_CAPTURE_FILE([ovsdb-client.log])
60 AT_CAPTURE_FILE([ovsdb-client.stderr])
61 ovsdb_check_monitor '$2' '$4' '$5' '$7' '$8' \
62 m4_foreach([txn], [$3], ['txn' ]) -- \
63 m4_foreach([txn], [$6], ['txn' ])
66 # OVSDB_CHECK_MONITOR_COND(TITLE, SCHEMA, [PRE-MONITOR-TXN], DB, TABLE,
67 # TRANSACTIONS, OUTPUT, CONDITIONS, [COLUMNS], [KEYWORDS],
68 # [CONDITIONS_CHANGE])
70 # Creates a database with the given SCHEMA, starts an ovsdb-server on
71 # that database, and runs each of the TRANSACTIONS (which should be a
72 # quoted list of quoted strings) against it with ovsdb-client one at a
73 # time. COLUMNS, if specified, is passed to ovsdb-client as the set
74 # of columns and operations to select.
76 # Checks that the overall output is OUTPUT, but UUIDs in the output
77 # are replaced by markers of the form <N> where N is a number. The
78 # first unique UUID is replaced by <0>, the next by <1>, and so on.
79 # If a given UUID appears more than once it is always replaced by the
82 # TITLE is provided to AT_SETUP and KEYWORDS to AT_KEYWORDS.
83 m4_define([OVSDB_CHECK_MONITOR_COND],
85 AT_KEYWORDS([ovsdb server monitor monitor-cond positive $10])
87 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
88 for txn in m4_foreach([txn], [$3], ['txn' ]); do
89 AT_CHECK([ovsdb-tool transact db "$txn"], [0], [ignore], [ignore])
91 AT_CAPTURE_FILE([ovsdb-server-log])
92 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
93 on_exit 'kill `cat ovsdb-server.pid`'
94 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond --format=csv unix:socket $4 '[$8]' $5 $9 > output],
95 [0], [ignore], [ignore])
96 on_exit 'kill `cat ovsdb-client.pid`'
97 for txn in m4_foreach([txn], [$6], ['txn' ]); do
98 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0],
99 [ignore], [ignore], [kill `cat server-pid client-pid`])
101 for cond in m4_foreach([cond], [$10], ['cond' ]); do
102 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/cond_change $5 "$cond"], [0], [ignore], [ignore])
104 AT_CHECK([ovsdb-client transact unix:socket '[["$4"]]'], [0],
106 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
107 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
108 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0], [$7], [ignore])
111 OVSDB_CHECK_MONITOR([monitor insert into empty table],
114 [ordinals], [ordinals],
118 "row": {"number": 0, "name": "zero"}}]]]],
119 [[row,action,name,number,_version
120 <0>,insert,"""zero""",0,"[""uuid"",""<1>""]"
123 OVSDB_CHECK_MONITOR([monitor insert into populated table],
128 "row": {"number": 10, "name": "ten"}}]]]],
129 [ordinals], [ordinals],
133 "row": {"number": 0, "name": "zero"}}]]]],
134 [[row,action,name,number,_version
135 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
137 row,action,name,number,_version
138 <2>,insert,"""zero""",0,"[""uuid"",""<3>""]"
141 OVSDB_CHECK_MONITOR([monitor delete],
146 "row": {"number": 10, "name": "ten"}}]]]],
147 [ordinals], [ordinals],
151 "where": [["number", "==", 10]]}]]]],
152 [[row,action,name,number,_version
153 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
155 row,action,name,number,_version
156 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
159 OVSDB_CHECK_MONITOR([monitor row update],
164 "row": {"number": 10, "name": "ten"}}]]]],
165 [ordinals], [ordinals],
169 "where": [["number", "==", 10]],
170 "row": {"name": "five plus five"}}]]]],
171 [[row,action,name,number,_version
172 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
174 row,action,name,number,_version
175 <0>,old,"""ten""",,"[""uuid"",""<1>""]"
176 ,new,"""five plus five""",10,"[""uuid"",""<2>""]"
179 OVSDB_CHECK_MONITOR([monitor no-op row updates],
184 "row": {"number": 10, "name": "ten"}}]]]],
185 [ordinals], [ordinals],
189 "where": [["number", "==", 10]],
190 "row": {"number": 10, "name": "ten"}}]]],
194 "row": {"number": 9, "name": "nine"}}]]]],
195 [[row,action,name,number,_version
196 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
198 row,action,name,number,_version
199 <2>,insert,"""nine""",9,"[""uuid"",""<3>""]"
202 OVSDB_CHECK_MONITOR([monitor insert-and-update transaction],
207 "row": {"number": 10, "name": "ten"}}]]]],
208 [ordinals], [ordinals],
212 "row": {"number": 9, "name": "nine"},
213 "uuid-name": "nine"},
216 "where": [["_uuid", "==", ["named-uuid", "nine"]]],
217 "row": {"name": "three squared"}}]]]],
218 [[row,action,name,number,_version
219 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
221 row,action,name,number,_version
222 <2>,insert,"""three squared""",9,"[""uuid"",""<3>""]"
225 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
230 "row": {"number": 10, "name": "ten"}}]]]],
231 [ordinals], [ordinals],
235 "row": {"number": 9, "name": "nine"},
236 "uuid-name": "nine"},
239 "where": [["_uuid", "==", ["named-uuid", "nine"]]],
240 "row": {"name": "three squared"}},
243 "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
246 "row": {"number": 7, "name": "seven"}}]]]],
247 [[row,action,name,number,_version
248 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
250 row,action,name,number,_version
251 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
254 OVSDB_CHECK_MONITOR([monitor weak reference change],
260 "a2a1": ["named-uuid", "a0"],
261 "a2b": ["named-uuid", "b2"]},
266 "a2a": ["named-uuid", "a0"],
267 "a2a1": ["named-uuid", "a1"],
268 "a2b": ["named-uuid", "b2"]},
273 "uuid-name": "b2"}]]]],
278 "where": [["a", "==", 0]]}]]]],
279 [[row,action,a,a2a,a2a1,a2b,_version
280 <0>,initial,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
281 <3>,initial,1,"[""uuid"",""<0>""]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<4>""]"
283 row,action,a,a2a,a2a1,a2b,_version
284 <0>,delete,0,"[""set"",[]]","[""uuid"",""<0>""]","[""uuid"",""<1>""]","[""uuid"",""<2>""]"
285 <3>,old,,"[""uuid"",""<0>""]",,,"[""uuid"",""<4>""]"
286 ,new,1,"[""set"",[]]","[""uuid"",""<3>""]","[""uuid"",""<1>""]","[""uuid"",""<5>""]"
289 OVSDB_CHECK_MONITOR([monitor insert-update-and-delete transaction],
294 "row": {"number": 10, "name": "ten"}}]]]],
295 [ordinals], [ordinals],
299 "row": {"number": 9, "name": "nine"},
300 "uuid-name": "nine"},
303 "where": [["_uuid", "==", ["named-uuid", "nine"]]],
304 "row": {"name": "three squared"}},
307 "where": [["_uuid", "==", ["named-uuid", "nine"]]]},
310 "row": {"number": 7, "name": "seven"}}]]]],
311 [[row,action,name,number,_version
312 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
314 row,action,name,number,_version
315 <2>,insert,"""seven""",7,"[""uuid"",""<3>""]"
318 AT_BANNER([ovsdb -- ovsdb-monitor monitor only some operations])
320 m4_define([OVSDB_MONITOR_INITIAL],
324 "row": {"number": 10, "name": "ten"}}]]]])
325 m4_define([OVSDB_MONITOR_TXNS],
329 "row": {"number": 5, "name": "five"}}]]],
333 "where": [["name", "==", "five"]],
334 "row": {"name": "FIVE"}}]]],
340 OVSDB_CHECK_MONITOR([monitor all operations],
341 [ordinal_schema], [OVSDB_MONITOR_INITIAL],
342 [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
343 [[row,action,name,number,_version
344 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
346 row,action,name,number,_version
347 <2>,insert,"""five""",5,"[""uuid"",""<3>""]"
349 row,action,name,number,_version
350 <2>,old,"""five""",,"[""uuid"",""<3>""]"
351 ,new,"""FIVE""",5,"[""uuid"",""<4>""]"
353 row,action,name,number,_version
354 <2>,delete,"""FIVE""",5,"[""uuid"",""<4>""]"
355 <0>,delete,"""ten""",10,"[""uuid"",""<1>""]"
358 dnl A monitor with "initial" only doesn't really make sense,
359 dnl but it's still allowed and should work.
360 OVSDB_CHECK_MONITOR([monitor initial only],
361 [ordinal_schema], [OVSDB_MONITOR_INITIAL],
362 [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
363 [[row,action,name,number,_version
364 <0>,initial,"""ten""",10,"[""uuid"",""<1>""]"
365 ]], [!insert,!delete,!modify])
367 OVSDB_CHECK_MONITOR([monitor insert only],
368 [ordinal_schema], [OVSDB_MONITOR_INITIAL],
369 [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
370 [[row,action,name,number,_version
371 <0>,insert,"""five""",5,"[""uuid"",""<1>""]"
372 ]], [!initial,!delete,!modify])
374 OVSDB_CHECK_MONITOR([monitor delete only],
375 [ordinal_schema], [OVSDB_MONITOR_INITIAL],
376 [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
377 [[row,action,name,number,_version
378 <0>,delete,"""FIVE""",5,"[""uuid"",""<1>""]"
379 <2>,delete,"""ten""",10,"[""uuid"",""<3>""]"
380 ]], [!initial,!insert,!modify])
382 OVSDB_CHECK_MONITOR([monitor modify only],
383 [ordinal_schema], [OVSDB_MONITOR_INITIAL],
384 [ordinals], [ordinals], [OVSDB_MONITOR_TXNS],
385 [[row,action,name,number,_version
386 <0>,old,"""five""",,"[""uuid"",""<1>""]"
387 ,new,"""FIVE""",5,"[""uuid"",""<2>""]"
388 ]], [!initial,!insert,!delete])
390 AT_BANNER([ovsdb -- ovsdb-monitor-cond conditional monitor only some operations])
392 OVSDB_CHECK_MONITOR_COND([monitor-cond empty condition],
397 "row": {"number": 0, "name": "zero"}},
400 "row": {"number": 1, "name": "one"}},
403 "row": {"number": 2, "name": "two"}}]]]],
404 [ordinals], [ordinals],
408 "row": {"number": 10, "name": "ten"}},
411 "row": {"number": 11, "name": "eleven"}}]]]],
412 [[row,action,name,number,_version
413 <0>,initial,"""one""",1,"[""uuid"",""<1>""]"
414 <2>,initial,"""two""",2,"[""uuid"",""<3>""]"
415 <4>,initial,"""zero""",,"[""uuid"",""<5>""]"
417 row,action,name,number,_version
418 <6>,insert,"""eleven""",11,"[""uuid"",""<7>""]"
419 <8>,insert,"""ten""",10,"[""uuid"",""<9>""]"
423 OVSDB_CHECK_MONITOR_COND([monitor-cond multiple conditions],
428 "row": {"number": 0, "name": "zero"}},
431 "row": {"number": 1, "name": "one"}},
434 "row": {"number": 2, "name": "two"}}]]]],
435 [ordinals], [ordinals],
439 "row": {"number": 10, "name": "ten"}},
442 "row": {"number": 11, "name": "eleven"}}]]]],
443 [[row,action,name,number,_version
444 <0>,initial,"""one""",1,"[""uuid"",""<1>""]"
446 row,action,name,number,_version
447 <2>,insert,"""ten""",10,"[""uuid"",""<3>""]"
449 [[["name","==","one"],["name","==","ten"]]])
451 OVSDB_CHECK_MONITOR_COND([monitor-cond delete from populated table],
456 "row": {"number": 0, "name": "zero"}},
459 "row": {"number": 1, "name": "one"}},
462 "row": {"number": 2, "name": "two"}}]]]],
463 [ordinals], [ordinals],
468 [[row,action,name,number,_version
469 <0>,initial,"""one""",1,"[""uuid"",""<1>""]"
471 row,action,name,number,_version
474 [[["name","==","one"],["name","==","ten"]]])
476 OVSDB_CHECK_MONITOR_COND([monitor-cond insert due to modify],
481 "row": {"number": 0, "name": "zero"}},
484 "row": {"number": 1, "name": "one"}},
487 "row": {"number": 2, "name": "two"}}]]]],
488 [ordinals], [ordinals],
492 "where": [["name", "==", "one"]],
493 "row": {"name": "ONE"}}]]]],
494 [[row,action,name,number,_version
495 <0>,insert,"""ONE""",1,"[""uuid"",""<1>""]"
497 [[["name","==","ONE"]]],
498 [!initial,!delete,!modify])
500 OVSDB_CHECK_MONITOR_COND([monitor-cond delete due to modify],
505 "row": {"number": 0, "name": "zero"}},
508 "row": {"number": 1, "name": "one"}},
511 "row": {"number": 2, "name": "two"}}]]]],
512 [ordinals], [ordinals],
516 "where": [["name", "==", "one"]],
517 "row": {"name": "ONE"}}]]]],
518 [[row,action,name,number,_version
521 [[["name","==","one"]]],
522 [!initial,!insert,!modify])
524 OVSDB_CHECK_MONITOR_COND([monitor-cond condition non-monitored columns],
529 "row": {"number": 0, "name": "zero"}},
532 "row": {"number": 1, "name": "one"}},
535 "row": {"number": 2, "name": "two"}}]]]],
536 [ordinals], [ordinals],
540 "row": {"number": 10, "name": "ten"}},
543 "row": {"number": 11, "name": "eleven"}}]]]],
550 [[["name","==","one"],["name","==","ten"]]],
553 OVSDB_CHECK_MONITOR_COND([monitor-cond-change],
558 "row": {"number": 0, "name": "zero"}},
561 "row": {"number": 1, "name": "one"}},
564 "row": {"number": 2, "name": "two"}}]]]],
565 [ordinals], [ordinals],
567 [[row,action,name,number,_version
568 <0>,initial,"""one""",1,"[""uuid"",""<1>""]"
569 <2>,initial,"""two""",2,"[""uuid"",""<3>""]"
570 <4>,initial,"""zero""",,"[""uuid"",""<5>""]"
572 row,action,name,number,_version
575 row,action,name,number,_version
578 row,action,name,number,_version
581 row,action,name,number,_version
582 <0>,insert,"""one""",1,"[""uuid"",""<1>""]"
583 <2>,insert,"""two""",2,"[""uuid"",""<3>""]"
584 <4>,insert,"""zero""",,"[""uuid"",""<5>""]"
588 [[[[["name","==","one"],["name","==","two"]]]],
589 [[[["name","==","one"]]]],
594 AT_SETUP(monitor-cond-change with many sessions pending)
595 AT_KEYWORDS([ovsdb server monitor monitor-cond negative])
596 ordinal_schema > schema
597 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
598 AT_CAPTURE_FILE([ovsdb-server-log])
600 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
601 on_exit 'kill `cat ovsdb-server.pid`'
602 for txn in m4_foreach([txn], [[[["ordinals",
605 "row": {"number": 0, "name": "zero"}},
608 "row": {"number": 1, "name": "one"}},
611 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
612 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
615 # 1001 clients monitoring column "name" and with condition for "name" only.
616 # The clients are created in a way that the 991th client will request condition
617 # change, so that the chance is high that the condition change will be handled
618 # before some pending changes are freed.
620 cond='[[["name","==","ten"]]]'
621 for i in `seq 1 990`; do
622 AT_CHECK([ovsdb-client -vjsonrpc --pidfile=ovsdb-client$i.pid --detach --no-chdir -d json monitor-cond --format=csv unix:socket ordinals $cond ordinals ["name"]], [0], [ignore], [ignore])
625 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond --format=csv unix:socket ordinals $cond ordinals ["name"] > output],
626 [0], [ignore], [ignore])
628 for i in `seq 991 1000`; do
629 AT_CHECK([ovsdb-client -vjsonrpc --pidfile=ovsdb-client$i.pid --detach --no-chdir -d json monitor-cond --format=csv unix:socket ordinals $cond ordinals ["name"]], [0], [ignore], [ignore])
632 for txn in m4_foreach([txn], [[[["ordinals",
635 "row": {"number": 10, "name": "ten"}}]]]], ['txn' ]); do
636 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0],
637 [ignore], [ignore], [kill `cat server-pid client-pid`])
640 # Change the condition so that a new column "number" is added to monitor table.
641 cond='[[["number","==",1]]]'
642 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/cond_change ordinals $cond], [0], [ignore], [ignore])
644 # Give some time for the server to flush and free pending changes
645 # (to crash, when n_columns is not handled properly)
648 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
650 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
651 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
652 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0], [[row,action,name
662 # Test monitor-cond-since with zero uuid, which shouldn't
663 # be found in server and server should send all rows
665 AT_SETUP([monitor-cond-since not found])
666 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
667 ordinal_schema > schema
668 AT_CHECK([ovsdb-tool create-cluster db schema unix:db.raft], [0], [stdout], [ignore])
669 AT_CAPTURE_FILE([ovsdb-server-log])
670 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
671 on_exit 'kill `cat ovsdb-server.pid`'
672 for txn in m4_foreach([txn], [[[["ordinals",
675 "row": {"number": 0, "name": "zero"}},
678 "row": {"number": 1, "name": "one"}},
681 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
682 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
685 # Omitting the last_id parameter in ovsdb-client monitor-cond-since command
686 # will by default using all zero uuid, which doesn't exist in any history txn.
687 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
688 [0], [ignore], [ignore])
689 on_exit 'kill `cat ovsdb-client.pid`'
690 for txn in m4_foreach([txn], [[[["ordinals",
693 "row": {"number": 10, "name": "ten"}},
696 "row": {"number": 11, "name": "eleven"}}]]]], ['txn' ]); do
697 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0],
698 [ignore], [ignore], [kill `cat server-pid client-pid`])
700 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
702 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
703 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
704 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
705 [[found: false, last_id: <0>
706 row,action,name,number,_version
707 <1>,initial,"""one""",1,"[""uuid"",""<2>""]"
710 row,action,name,number,_version
711 <4>,insert,"""ten""",10,"[""uuid"",""<5>""]"
716 # Test monitor-cond-since in ovsdb server restart scenario.
717 # ovsdb-client should receive only new changes after the
718 # specific transaction id.
719 AT_SETUP([monitor-cond-since db restart])
720 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
721 ordinal_schema > schema
722 AT_CHECK([ovsdb-tool create-cluster db schema unix:db.raft], [0], [stdout], [ignore])
723 AT_CAPTURE_FILE([ovsdb-server-log])
724 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
725 on_exit 'kill `cat ovsdb-server.pid`'
726 for txn in m4_foreach([txn], [[[["ordinals",
729 "row": {"number": 0, "name": "zero"}},
732 "row": {"number": 1, "name": "one"}},
735 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
736 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
739 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
740 [0], [ignore], [ignore])
741 on_exit 'kill `cat ovsdb-client.pid`'
742 OVS_WAIT_UNTIL([grep last_id output])
744 kill `cat ovsdb-client.pid`
745 kill `cat ovsdb-server.pid`
746 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
748 # Remember the last_id, which will be used for monitor-cond-since later.
749 last_id=`grep last_id output | awk '{print $4}'`
751 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
753 # Some new changes made to db after restarting the server.
754 for txn in m4_foreach([txn], [[[["ordinals",
757 "row": {"number": 10, "name": "ten"}},
760 "row": {"number": 11, "name": "eleven"}}]]]], ['txn' ]); do
761 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0],
762 [ignore], [ignore], [kill `cat server-pid client-pid`])
765 # Use last_id to monitor and get only the new changes.
766 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals $last_id '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
767 [0], [ignore], [ignore])
769 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
771 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
772 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
773 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
774 [[found: true, last_id: <0>
775 row,action,name,number,_version
776 <1>,insert,"""ten""",10,"[""uuid"",""<2>""]"
781 # Test monitor-cond-since with last_id found in server
782 # but there is no new change after that transaction.
783 AT_SETUP([monitor-cond-since found but no new rows])
784 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
785 ordinal_schema > schema
786 AT_CHECK([ovsdb-tool create-cluster db schema unix:db.raft], [0], [stdout], [ignore])
787 AT_CAPTURE_FILE([ovsdb-server-log])
788 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
789 on_exit 'kill `cat ovsdb-server.pid`'
790 for txn in m4_foreach([txn], [[[["ordinals",
793 "row": {"number": 0, "name": "zero"}},
796 "row": {"number": 1, "name": "one"}},
799 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
800 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
802 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
803 [0], [ignore], [ignore])
804 on_exit 'kill `cat ovsdb-client.pid`'
805 OVS_WAIT_UNTIL([grep last_id output])
807 kill `cat ovsdb-client.pid`
808 OVS_WAIT_UNTIL([test ! -e ovsdb-client.pid])
809 last_id=`grep last_id output | awk '{print $4}'`
810 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals $last_id '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
811 [0], [ignore], [ignore])
813 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
815 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
816 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
817 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
818 [[found: true, last_id: <0>
823 # Test monitor-cond-since against empty DB
824 AT_SETUP([monitor-cond-since empty db])
825 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
826 ordinal_schema > schema
827 AT_CHECK([ovsdb-tool create-cluster db schema unix:db.raft], [0], [stdout], [ignore])
828 AT_CAPTURE_FILE([ovsdb-server-log])
829 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
830 on_exit 'kill `cat ovsdb-server.pid`'
831 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
832 [0], [ignore], [ignore])
833 on_exit 'kill `cat ovsdb-client.pid`'
834 OVS_WAIT_UNTIL([grep last_id output])
836 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
838 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
839 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
840 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
841 [[found: false, last_id: <0>
846 # Test monitor-cond-since with cond-change followed.
847 AT_SETUP([monitor-cond-since condition change])
848 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
849 ordinal_schema > schema
850 AT_CHECK([ovsdb-tool create-cluster db schema unix:db.raft], [0], [stdout], [ignore])
851 AT_CAPTURE_FILE([ovsdb-server-log])
852 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
853 on_exit 'kill `cat ovsdb-server.pid`'
854 for txn in m4_foreach([txn], [[[["ordinals",
857 "row": {"number": 0, "name": "zero"}},
860 "row": {"number": 1, "name": "one"}},
863 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
864 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
866 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[]]' ordinals > output], [0], [ignore], [ignore])
867 on_exit 'kill `cat ovsdb-client.pid`'
868 for cond in m4_foreach([cond],
869 [[[[["name","==","one"],["name","==","two"]]]],
870 [[[["name","==","one"]]]],
872 [[[true]]]], ['cond' ]); do
873 AT_CHECK([ovs-appctl -t ovsdb-client ovsdb-client/cond_change ordinals "$cond"], [0], [ignore], [ignore])
875 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
877 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
878 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
879 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
880 [[found: false, last_id: <0>
881 row,action,name,number,_version
882 <1>,initial,"""one""",1,"[""uuid"",""<2>""]"
883 <3>,initial,"""two""",2,"[""uuid"",""<4>""]"
884 <5>,initial,"""zero""",,"[""uuid"",""<6>""]"
887 row,action,name,number,_version
891 row,action,name,number,_version
895 row,action,name,number,_version
899 row,action,name,number,_version
900 <1>,insert,"""one""",1,"[""uuid"",""<2>""]"
901 <3>,insert,"""two""",2,"[""uuid"",""<4>""]"
902 <5>,insert,"""zero""",,"[""uuid"",""<6>""]"
907 # Test monitor-cond-since with non-cluster mode server
908 AT_SETUP([monitor-cond-since non-cluster])
909 AT_KEYWORDS([ovsdb server monitor monitor-cond-since positive])
910 ordinal_schema > schema
911 AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
912 AT_CAPTURE_FILE([ovsdb-server-log])
913 AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1])
914 on_exit 'kill `cat ovsdb-server.pid`'
915 for txn in m4_foreach([txn], [[[["ordinals",
918 "row": {"number": 0, "name": "zero"}},
921 "row": {"number": 1, "name": "one"}},
924 "row": {"number": 2, "name": "two"}}]]]], ['txn' ]); do
925 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0], [ignore], [ignore])
928 AT_CHECK([ovsdb-client -vjsonrpc --pidfile --detach --no-chdir -d json monitor-cond-since --format=csv unix:socket ordinals '[[["name","==","one"],["name","==","ten"]]]' ordinals > output],
929 [0], [ignore], [ignore])
930 on_exit 'kill `cat ovsdb-client.pid`'
931 for txn in m4_foreach([txn], [[[["ordinals",
934 "row": {"number": 10, "name": "ten"}},
937 "row": {"number": 11, "name": "eleven"}}]]]], ['txn' ]); do
938 AT_CHECK([ovsdb-client transact unix:socket "$txn"], [0],
939 [ignore], [ignore], [kill `cat server-pid client-pid`])
941 AT_CHECK([ovsdb-client transact unix:socket '[["ordinals"]]'], [0],
943 AT_CHECK([ovs-appctl -t ovsdb-server -e exit], [0], [ignore], [ignore])
944 OVS_WAIT_UNTIL([test ! -e ovsdb-server.pid && test ! -e ovsdb-client.pid])
946 # Transaction shouldn't be found, and last_id returned should always
947 # be the same (all zero uuid)
948 AT_CHECK([$PYTHON $srcdir/ovsdb-monitor-sort.py < output | uuidfilt], [0],
949 [[found: false, last_id: <0>
950 row,action,name,number,_version
951 <1>,initial,"""one""",1,"[""uuid"",""<2>""]"
954 row,action,name,number,_version
955 <3>,insert,"""ten""",10,"[""uuid"",""<4>""]"