/*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
parse_options(int argc, char *argv[])
{
static struct option long_options[] = {
- {"timeout", required_argument, 0, 't'},
- {"verbose", optional_argument, 0, 'v'},
- {"help", no_argument, 0, 'h'},
- {0, 0, 0, 0},
+ {"timeout", required_argument, NULL, 't'},
+ {"verbose", optional_argument, NULL, 'v'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0},
};
char *short_options = long_options_to_short_options(long_options);
" parse string DATUMs as data of given TYPE, and re-serialize\n"
" parse-column NAME OBJECT\n"
" parse column NAME with info OBJECT, and re-serialize\n"
- " parse-table NAME OBJECT\n"
+ " parse-table NAME OBJECT [DEFAULT-IS-ROOT]\n"
" parse table NAME with info OBJECT\n"
" parse-row TABLE ROW..., and re-serialize\n"
" parse each ROW of defined TABLE\n"
do_parse_table(int argc OVS_UNUSED, char *argv[])
{
struct ovsdb_table_schema *ts;
+ bool default_is_root;
struct json *json;
+ default_is_root = argc > 3 && !strcmp(argv[3], "true");
+
json = parse_json(argv[2]);
check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
json_destroy(json);
- print_and_free_json(ovsdb_table_schema_to_json(ts));
+ print_and_free_json(ovsdb_table_schema_to_json(ts, default_is_root));
ovsdb_table_schema_destroy(ts);
}
ovsdb_table_destroy(table); /* Also destroys 'ts'. */
}
+/* Inserts a row, without bothering to update metadata such as refcounts. */
+static void
+put_row(struct ovsdb_table *table, struct ovsdb_row *row)
+{
+ const struct uuid *uuid = ovsdb_row_get_uuid(row);
+ if (!ovsdb_table_get_row(table, uuid)) {
+ hmap_insert(&table->rows, &row->hmap_node, uuid_hash(uuid));
+ }
+}
+
struct do_query_cbdata {
struct uuid *row_uuids;
int *counts;
UUID_ARGS(ovsdb_row_get_uuid(row)));
}
cbdata.row_uuids[i] = *ovsdb_row_get_uuid(row);
- ovsdb_table_put_row(table, row);
+ put_row(table, row);
}
json_destroy(json);
/* Parse column set. */
json = parse_json(argv[4]);
- check_ovsdb_error(ovsdb_column_set_from_json(json, table, &columns));
+ check_ovsdb_error(ovsdb_column_set_from_json(json, table->schema,
+ &columns));
json_destroy(json);
/* Parse rows, add to table. */
ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
UUID_ARGS(ovsdb_row_get_uuid(row)));
}
- ovsdb_table_put_row(table, row);
+ put_row(table, row);
}
json_destroy(json);
static void
do_transact_commit(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
- ovsdb_txn_commit(do_transact_txn, false);
+ ovsdb_error_destroy(ovsdb_txn_commit(do_transact_txn, false));
do_transact_txn = NULL;
}
idltest_simple_set_s(s, arg3);
} else if (!strcmp(arg2, "u")) {
struct uuid uuid;
- uuid_from_string(&uuid, arg3);
+ if (!uuid_from_string(&uuid, arg3)) {
+ ovs_fatal(0, "\"%s\" is not a valid UUID", arg3);
+ }
idltest_simple_set_u(s, uuid);
} else if (!strcmp(arg2, "r")) {
idltest_simple_set_r(s, atof(arg3));
"i=%d", atoi(arg1));
}
idltest_simple_delete(s);
+ } else if (!strcmp(name, "verify")) {
+ const struct idltest_simple *s;
+
+ if (!arg2 || arg3) {
+ ovs_fatal(0, "\"verify\" command requires 2 arguments");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"verify\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+
+ if (!strcmp(arg2, "i")) {
+ idltest_simple_verify_i(s);
+ } else if (!strcmp(arg2, "b")) {
+ idltest_simple_verify_b(s);
+ } else if (!strcmp(arg2, "s")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "u")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "r")) {
+ idltest_simple_verify_r(s);
+ } else {
+ ovs_fatal(0, "\"verify\" command asks for unknown column %s",
+ arg2);
+ }
} else if (!strcmp(name, "increment")) {
if (!arg2 || arg3) {
- ovs_fatal(0, "\"set\" command requires 2 arguments");
+ ovs_fatal(0, "\"increment\" command requires 2 arguments");
}
ovsdb_idl_txn_increment(txn, arg1, arg2, NULL);
increment = true;
+ } else if (!strcmp(name, "abort")) {
+ ovsdb_idl_txn_abort(txn);
+ break;
+ } else if (!strcmp(name, "destroy")) {
+ printf("%03d: destroy\n", step);
+ ovsdb_idl_txn_destroy(txn);
+ return;
} else {
ovs_fatal(0, "unknown command %s", name);
}
idltest_init();
- idl = ovsdb_idl_create(argv[1], &idltest_idl_class);
+ idl = ovsdb_idl_create(argv[1], &idltest_idl_class, true);
if (argc > 2) {
struct stream *stream;
{ "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
{ "sort-atoms", 2, 2, do_sort_atoms },
{ "parse-column", 2, 2, do_parse_column },
- { "parse-table", 2, 2, do_parse_table },
+ { "parse-table", 2, 3, do_parse_table },
{ "parse-rows", 2, INT_MAX, do_parse_rows },
{ "compare-rows", 2, INT_MAX, do_compare_rows },
{ "parse-conditions", 2, INT_MAX, do_parse_conditions },