Add tests for the OVSDB IDL on-demand column mode. This commit includes three tests to verify the correct functionality of the on-demand fetching at row, column, and table level.
Co-Authored-By: Randall Esquivel <randall.esqui...@hpe.com> Co-Authored-By: Arnoldo Lutz <arnoldo.lutz.guev...@hpe.com> Signed-off-by: Sebastian Arguello <sebastian.argue...@hpe.com> Signed-off-by: Arnoldo Lutz <arnoldo.lutz.guev...@hpe.com> Signed-off-by: Randall Esquivel <randall.esqui...@hpe.com> --- This is the pull request with this change: https://github.com/openvswitch/ovs/pull/110 --- tests/ovsdb-idl.at | 165 ++++++++++++++++++++++++++++++++++++ tests/test-ovsdb.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 408 insertions(+) diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index 33d508c..efd8217 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -800,3 +800,168 @@ OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, various ops], 014: updated columns: ba i ia r ra s 015: done ]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-column-row unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COL_ROW([on-demand-fetch-col-row, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}}, + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After changes with fetch for ua column in only one row +002: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<1> +003: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-column unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_COLUMN([on-demand-fetch-column, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}}, + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After fetch for entire s column +002: i=1 r=2 b=true s=name u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +003: i=1 r=2 b=true s=name u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +]]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE_C], + [AT_SETUP([$1 - C]) + AT_KEYWORDS([ovsdb idl on-demand fetch positive $5]) + AT_CHECK([ovsdb-tool create db $abs_srcdir/idltest.ovsschema], + [0], [stdout], [ignore]) + AT_CHECK([ovsdb-server '-vPATTERN:console:ovsdb-server|%c|%m' --detach --no-chdir --pidfile="`pwd`"/pid --remote=punix:socket --unixctl="`pwd`"/unixctl db], [0], [ignore], [ignore]) + m4_if([$2], [], [], + [AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore], [kill `cat pid`])]) + AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-fetch-table unix:socket $2], + [0], [stdout], [ignore], [kill `cat pid`]) + AT_CHECK([sort stdout | ${PERL} $srcdir/uuidfilt.pl]m4_if([$6],,, [[| $6]]), + [0], [$3], [], [kill `cat pid`]) + OVSDB_SERVER_SHUTDOWN + AT_CLEANUP]) + +m4_define([OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE], + [OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE_C($@)]) + +OVSDB_CHECK_IDL_ON_DEMAND_FETCH_TABLE([on-demand-fetch-table, simple idl, initially populated], + [['["idltest", + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}}, + {"op": "insert", + "table": "simple", + "row": {"i": 1, + "r": 2.0, + "b": true, + "s": "name", + "u": ["uuid", "84f5c8f5-ac76-4dbc-a24f-8860eb407fc1"], + "ia": ["set", [1, 2, 3]], + "ra": ["set", [-0.5]], + "ba": ["set", [true]], + "sa": ["set", ["abc", "def"]], + "ua": ["set", [["uuid", "69443985-7806-45e2-b35f-574a04e720f9"], + ["uuid", "aad11ef0-816a-4b01-93e6-03b8b4256b98"]]]}} + ]']], + [[000: Initial. On-demand columns: [s ia ua] +000: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<1> +001: i=1 r=2 b=true s= u=<0> ia=[] ra=[-0.5] ba=[true] sa=[abc def] ua=[] uuid=<2> +002: After complete table fetch +002: i=1 r=2 b=true s=name u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<1> +003: i=1 r=2 b=true s=name u=<0> ia=[1 2 3] ra=[-0.5] ba=[true] sa=[abc def] ua=[<3> <4>] uuid=<2> +]]) diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index dbb6897..1633c0d 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (C) 2016 Hewlett Packard Enterprise Development LP * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -198,6 +199,11 @@ usage(void) " connect to SERVER and dump the contents of the database\n" " as seen initially by the IDL implementation and after\n" " executing each TRANSACTION. (Each TRANSACTION must modify\n" + " the database or this command will hang.)\n" + " idl-fetch SERVER [TRANSACTION...]\n" + " connect to SERVER and dump the contents of the database\n" + " as seen initially by the IDL implementation and after\n" + " executing each TRANSACTION. (Each TRANSACTION must modify\n" " the database or this command will hang.)\n", program_name, program_name); vlog_usage(); @@ -2179,6 +2185,240 @@ do_idl(struct ovs_cmdl_context *ctx) printf("%03d: done\n", step); } +static void +do_fetch_column_row(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* get ondemand column of second row */ + printf("%03d: After changes with fetch for ua column in only one row\n", + step); + s = idltest_simple_first(idl); + idltest_simple_fetch_ua(idl, s); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_row_fetch_pending(s)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + +static void +do_fetch_column(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* Print simple data after fetching s column */ + printf("%03d: After fetch for entire s column\n", step); + s = idltest_simple_first(idl); + idltest_simple_fetch_col_s(idl); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_s_fetch_pending(idl)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + +static void +do_fetch_table(struct ovs_cmdl_context *ctx) +{ + struct jsonrpc *rpc; + struct ovsdb_idl *idl; + unsigned int seqno = 0; + int step = 0; + int error; + const struct idltest_simple *s; + + idltest_init(); + + idl = ovsdb_idl_create(ctx->argv[1], &idltest_idl_class, true, true); + if (ctx->argc > 2) { + struct stream *stream; + + error = stream_open_block(jsonrpc_stream_open(ctx->argv[1], &stream, + DSCP_DEFAULT), &stream); + if (error) { + ovs_fatal(error, "failed to connect to \"%s\"", ctx->argv[1]); + } + rpc = jsonrpc_open(stream); + } else { + rpc = NULL; + } + + ovsdb_idl_add_table(idl, &idltest_table_simple); + ovsdb_idl_add_column(idl, &idltest_simple_col_b); + ovsdb_idl_add_column(idl, &idltest_simple_col_ba); + ovsdb_idl_add_column(idl, &idltest_simple_col_i); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ia); + ovsdb_idl_add_column(idl, &idltest_simple_col_r); + ovsdb_idl_add_column(idl, &idltest_simple_col_ra); + ovsdb_idl_add_column(idl, &idltest_simple_col_sa); + ovsdb_idl_add_column(idl, &idltest_simple_col_u); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_s); + ovsdb_idl_add_on_demand_column(idl, &idltest_table_simple, + &idltest_simple_col_ua); + + ovsdb_idl_get_initial_snapshot(idl); + ovsdb_idl_run(idl); + + /* Wait for update. */ + for (;;) { + ovsdb_idl_run(idl); + if (ovsdb_idl_get_seqno(idl) != seqno) { + break; + } + jsonrpc_run(rpc); + + ovsdb_idl_wait(idl); + jsonrpc_wait(rpc); + poll_block(); + } + + /* Print initial simple data without fetching column. */ + printf("%03d: Initial. On-demand columns: [s ia ua]\n", step); + s = idltest_simple_first(idl); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + /* fetch complete table */ + printf("%03d: After complete table fetch\n", step); + idltest_simple_fetch_table(idl); + do { + ovsdb_idl_run(idl); + } while (idltest_simple_is_table_fetch_pending(idl)); + IDLTEST_SIMPLE_FOR_EACH(s, idl) { + print_idl_row_simple(s, step++); + } + + ovsdb_idl_destroy(idl); +} + static struct ovs_cmdl_command all_commands[] = { { "log-io", NULL, 2, INT_MAX, do_log_io }, { "default-atoms", NULL, 0, 0, do_default_atoms }, @@ -2207,6 +2447,9 @@ static struct ovs_cmdl_command all_commands[] = { { "execute", NULL, 2, INT_MAX, do_execute }, { "trigger", NULL, 2, INT_MAX, do_trigger }, { "idl", NULL, 1, INT_MAX, do_idl }, + { "idl-fetch-column-row", NULL, 1, INT_MAX, do_fetch_column_row }, + { "idl-fetch-column", NULL, 1, INT_MAX, do_fetch_column }, + { "idl-fetch-table", NULL, 1, INT_MAX, do_fetch_table }, { "help", NULL, 0, INT_MAX, do_help }, { NULL, NULL, 0, 0, NULL }, }; -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev