From fe042bfa645c48a048f82af1cfe2334e3b804f28 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Thu, 6 Dec 2012 12:31:19 +1030 Subject: [PATCH] Servald 'config [ set|del ... ] ... ' command Update all test scripts to avoid repetitive executeOk_servald invocations. --- commandline.c | 58 ++++++++++++++++++++------------------- tests/config | 33 ++++++++++++++++++----- tests/directory_service | 60 ++++++++++++++++++++++------------------- tests/dnahelper | 13 ++++----- tests/dnaprotocol | 30 +++++++++++---------- tests/rhizomeprotocol | 33 ++++++++++++----------- tests/rhizomestress | 17 ++++++------ tests/routing | 20 +++++++------- tests/server | 7 ++--- 9 files changed, 154 insertions(+), 117 deletions(-) diff --git a/commandline.c b/commandline.c index 6a2e9dba..c253dfbb 100644 --- a/commandline.c +++ b/commandline.c @@ -926,10 +926,6 @@ int app_mdp_ping(int argc, const char *const *argv, const struct command_line_op int app_config_set(int argc, const char *const *argv, const struct command_line_option *o, void *context) { if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); - const char *var, *val; - if ( cli_arg(argc, argv, o, "variable", &var, is_configvarname, NULL) - || cli_arg(argc, argv, o, "value", &val, NULL, "")) - return -1; if (create_serval_instance_dir() == -1) return -1; // @@ -948,26 +944,32 @@ int app_config_set(int argc, const char *const *argv, const struct command_line_ if (cf_om_reload() == -1) return -1; // - if (cf_om_set(&cf_om_root, var, val) == -1 || cf_om_save() == -1) - return -1; - if (cf_reload() == -1) // logs an error if the new config is bad - return 2; - return 0; -} - -int app_config_del(int argc, const char *const *argv, const struct command_line_option *o, void *context) -{ - if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); - const char *var; - if (cli_arg(argc, argv, o, "variable", &var, is_configvarname, NULL)) - return -1; - if (create_serval_instance_dir() == -1) - return -1; - // See app_config_set() - if (cf_om_reload() == -1) - return -1; - // - if (cf_om_set(&cf_om_root, var, NULL) == -1 || cf_om_save() == -1) + const char *var[argc - 1]; + const char *val[argc - 1]; + int nvar = 0; + int i; + for (i = 1; i < argc; ++i) { + int iv; + if (strcmp(argv[i], "set") == 0) { + if (i + 2 > argc) + return WHYF("malformed command at argv[%d]: 'set' not followed by two arguments", i); + var[nvar] = argv[iv = ++i]; + val[nvar] = argv[++i]; + } else if (strcmp(argv[i], "del") == 0) { + if (i + 1 > argc) + return WHYF("malformed command at argv[%d]: 'del' not followed by one argument", i); + var[nvar] = argv[iv = ++i]; + val[nvar] = NULL; + } else + return WHYF("malformed command at argv[%d]: unsupported action '%s'", i, argv[i]); + if (!is_configvarname(var[nvar])) + return WHYF("malformed command at argv[%d]: '%s' is not a valid config option name", iv, var[nvar]); + ++nvar; + } + for (i = 0; i < nvar; ++i) + if (cf_om_set(&cf_om_root, var[i], val[i]) == -1) + return -1; + if (cf_om_save() == -1) return -1; if (cf_reload() == -1) // logs an error if the new config is bad return 2; @@ -1908,10 +1910,10 @@ struct command_line_option command_line_options[]={ "Display information about any running Serval Mesh node."}, {app_mdp_ping,{"mdp","ping","","[]",NULL},CLIFLAG_STANDALONE, "Attempts to ping specified node via Mesh Datagram Protocol (MDP)."}, - {app_config_set,{"config","set","","",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG, - "Set specified configuration variable."}, - {app_config_del,{"config","del","",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG, - "Set specified configuration variable."}, + {app_config_set,{"config","set","","","...",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG, + "Set and del specified configuration variables."}, + {app_config_set,{"config","del","","...",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG, + "Del and set specified configuration variables."}, {app_config_get,{"config","get","[]",NULL},CLIFLAG_STANDALONE|CLIFLAG_PERMISSIVE_CONFIG, "Get specified configuration variable."}, {app_vomp_console,{"console",NULL},0, diff --git a/tests/config b/tests/config index 4f7a1a44..783af898 100755 --- a/tests/config +++ b/tests/config @@ -88,10 +88,11 @@ test_SetGet() { doc_GetAll="Get all config items" test_GetAll() { - executeOk_servald config set debug.verbose true - executeOk_servald config set log.show_pid true - executeOk_servald config set server.chdir /tmp/nothing - executeOk_servald config set rhizome.enable no + executeOk_servald config \ + set debug.verbose true \ + set log.show_pid true \ + set server.chdir /tmp/nothing \ + set rhizome.enable no executeOk_servald config get assertStdoutLineCount '==' 4 assertStdoutGrep --stdout --matches=1 '^debug\.verbose=true$' @@ -100,6 +101,25 @@ test_GetAll() { assertStdoutGrep --stdout --matches=1 '^rhizome\.enable=no$' } +doc_SetDelMixed="Set and del config items in single command" +test_SetDelMixed() { + executeOk_servald config \ + set debug.verbose true \ + set log.show_pid true \ + set server.chdir /tmp/nothing \ + set rhizome.enable no + executeOk_servald config \ + set debug.verbose false \ + del log.show_pid \ + set log.show_time 1 \ + del server.chdir \ + del rhizome.enable + executeOk_servald config get + assertStdoutLineCount '==' 2 + assertStdoutGrep --stdout --matches=1 '^debug\.verbose=false$' + assertStdoutGrep --stdout --matches=1 '^log\.show_time=1$' +} + doc_SetTwice="Set a single config item twice" test_SetTwice() { executeOk_servald config set debug.verbose yes @@ -120,8 +140,7 @@ test_DelNull() { doc_Del="Delete single config item" test_Del() { - executeOk_servald config set debug.verbose yes - executeOk_servald config set log.show_pid true + executeOk_servald config set debug.verbose yes set log.show_pid true executeOk_servald config get assertStdoutLineCount '==' 2 executeOk_servald config del debug.verbose @@ -143,7 +162,7 @@ test_OptionNames() { assertExitStatus --stderr '!=' 0 execute $servald config set .verbose yes assertExitStatus --stderr '!=' 0 - execute $servald config set debug..verbose yes + execute $servald config del debug..verbose assertExitStatus --stderr '!=' 0 } diff --git a/tests/directory_service b/tests/directory_service index 94d72089..f8b1f06e 100755 --- a/tests/directory_service +++ b/tests/directory_service @@ -21,9 +21,10 @@ source "${0%/*}/../testframework.sh" source "${0%/*}/../testdefs.sh" configure_servald_server() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.mdprequests Yes + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set debug.mdprequests Yes } setup() { @@ -38,8 +39,9 @@ setup() { DIDD=$DIDD1 NAMED=$NAMED1 set_instance +A - executeOk_servald config set dna.helper.executable "$servald_build_root/directory_service" - executeOk_servald config set debug.dnahelper on + executeOk_servald config \ + set dna.helper.executable "$servald_build_root/directory_service" \ + set debug.dnahelper on foreach_instance +B +C +D executeOk_servald config set directory.service $SIDA start_servald_instances +A +B +C +D } @@ -79,12 +81,13 @@ test_publish() { } start_routing_instance() { - executeOk_servald config set server.dummy_interface_dir "$SERVALD_VAR" - executeOk_servald config set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" - executeOk_servald config set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.mdprequests Yes + executeOk_servald config \ + set server.dummy_interface_dir "$SERVALD_VAR" \ + set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" \ + set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" \ + set log.show_pid on \ + set log.show_time on \ + set debug.mdprequests Yes start_servald_server } @@ -96,26 +99,29 @@ setup_routing() { >$SERVALD_VAR/dummyB >$SERVALD_VAR/dummyC set_instance +A - executeOk_servald config set interfaces.0.dummy dummyB - executeOk_servald config set interfaces.0.mdp_tick_ms 0 - executeOk_servald config set interfaces.1.dummy dummyC - executeOk_servald config set interfaces.1.mdp_tick_ms 0 - executeOk_servald config set dna.helper.executable "$servald_build_root/directory_service" - executeOk_servald config set debug.dnahelper on + executeOk_servald config \ + set interfaces.0.dummy dummyB \ + set interfaces.0.mdp_tick_ms 0 \ + set interfaces.1.dummy dummyC \ + set interfaces.1.mdp_tick_ms 0 \ + set dna.helper.executable "$servald_build_root/directory_service" \ + set debug.dnahelper on start_routing_instance set_instance +B - executeOk_servald config set interfaces.0.dummy dummyB - executeOk_servald config set interfaces.0.mdp_tick_ms 0 - executeOk_servald config set directory.service $SIDA - execute $servald config set hosts.$SIDA.address 127.0.0.1 - executeOk_servald config set hosts.$SIDA.interface "dummyB" + executeOk_servald config \ + set interfaces.0.dummy dummyB \ + set interfaces.0.mdp_tick_ms 0 \ + set directory.service $SIDA \ + set hosts.$SIDA.address 127.0.0.1 \ + set hosts.$SIDA.interface "dummyB" start_routing_instance set_instance +C - executeOk_servald config set interfaces.1.dummy dummyC - executeOk_servald config set interfaces.1.mdp_tick_ms 0 - executeOk_servald config set directory.service $SIDA - execute $servald config set hosts.$SIDA.address 127.0.0.1 - executeOk_servald config set hosts.$SIDA.interface "dummyC" + executeOk_servald config \ + set interfaces.1.dummy dummyC \ + set interfaces.1.mdp_tick_ms 0 \ + set directory.service $SIDA \ + set hosts.$SIDA.address 127.0.0.1 \ + set hosts.$SIDA.interface "dummyC" start_routing_instance } diff --git a/tests/dnahelper b/tests/dnahelper index 01a2d2ef..229af277 100755 --- a/tests/dnahelper +++ b/tests/dnahelper @@ -42,12 +42,13 @@ teardown() { # Called by start_servald_instances immediately before starting the server # process in each instance. configure_servald_server() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.dnahelper on - executeOk_servald config set dna.helper.executable "$dnahelper" - executeOk_servald config set dna.helper.argv.1 "Hello," - executeOk_servald config set dna.helper.argv.2 "World!" + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set debug.dnahelper on \ + set dna.helper.executable "$dnahelper" \ + set dna.helper.argv.1 "Hello," \ + set dna.helper.argv.2 "World!" } setup_dnahelper() { diff --git a/tests/dnaprotocol b/tests/dnaprotocol index 50cf8326..9c50fbcf 100755 --- a/tests/dnaprotocol +++ b/tests/dnaprotocol @@ -58,17 +58,18 @@ teardown() { } set_server_vars() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set mdp.iftype.wifi.tick_ms 100 - executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1 - executeOk_servald config set debug.interfaces Yes - executeOk_servald config set debug.packetformats No - executeOk_servald config set debug.routing No - executeOk_servald config set debug.tx No - executeOk_servald config set debug.rx No - executeOk_servald config set debug.mdprequests Yes - executeOk_servald config set debug.keyring Yes + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set mdp.iftype.wifi.tick_ms 100 \ + set mdp.selfannounce.ticks_per_full_address 1 \ + set debug.interfaces Yes \ + set debug.packetformats No \ + set debug.routing No \ + set debug.tx No \ + set debug.rx No \ + set debug.mdprequests Yes \ + set debug.keyring Yes } doc_LookupWildcard="Lookup by wildcard" @@ -139,9 +140,10 @@ EOF foreach_instance +A +B +C +D create_single_identity configure_servald_server() { set_server_vars - executeOk_servald config set debug.dnahelper on - executeOk_servald config set dna.helper.executable "$dnahelper" - executeOk_servald config set dna.helper.argv.1 "$instance_name" + executeOk_servald config \ + set debug.dnahelper on \ + set dna.helper.executable "$dnahelper" \ + set dna.helper.argv.1 "$instance_name" } start_servald_instances +A +B +C +D wait_until --sleep=0.25 instances_reach_each_other +A +B +C +D diff --git a/tests/rhizomeprotocol b/tests/rhizomeprotocol index 2d091cd3..652b078a 100755 --- a/tests/rhizomeprotocol +++ b/tests/rhizomeprotocol @@ -36,14 +36,15 @@ teardown() { # Called by start_servald_instances for each instance. configure_servald_server() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.rhizome on - executeOk_servald config set debug.rhizometx on - executeOk_servald config set debug.rhizomerx on - executeOk_servald config set server.respawn_on_crash off - executeOk_servald config set mdp.iftype.wifi.tick_ms 500 - executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1 + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set debug.rhizome on \ + set debug.rhizometx on \ + set debug.rhizomerx on \ + set server.respawn_on_crash off \ + set mdp.iftype.wifi.tick_ms 500 \ + set mdp.selfannounce.ticks_per_full_address 1 } setup_curl_7() { @@ -206,8 +207,9 @@ setup_HttpAddLocal() { setup_curl_7 setup_common set_instance +A - executeOk_servald config set rhizome.api.addfile.uri_path "/rhizome/secretaddfile" - executeOk_servald config set rhizome.api.addfile.default_author $SIDA + executeOk_servald config \ + set rhizome.api.addfile.uri_path "/rhizome/secretaddfile" \ + set rhizome.api.addfile.default_author $SIDA start_servald_instances +A wait_until rhizome_http_server_started +A get_rhizome_server_port PORTA +A @@ -232,11 +234,12 @@ setup_sync() { wait_until rhizome_http_server_started +A get_rhizome_server_port PORTA +A set_instance +B - executeOk_servald config set log.show_time on - executeOk_servald config set debug.rhizome on - executeOk_servald config set debug.rhizometx on - executeOk_servald config set debug.rhizomerx on - executeOk_servald config set rhizome.direct.peer.0 "http://${addr_localhost}:${PORTA}" + executeOk_servald config \ + set log.show_time on \ + set debug.rhizome on \ + set debug.rhizometx on \ + set debug.rhizomerx on \ + set rhizome.direct.peer.0 "http://${addr_localhost}:${PORTA}" rhizome_add_file file2 BID2=$BID VERSION2=$VERSION diff --git a/tests/rhizomestress b/tests/rhizomestress index 00745a96..c2fa8cb2 100755 --- a/tests/rhizomestress +++ b/tests/rhizomestress @@ -36,14 +36,15 @@ teardown() { # Called by start_servald_instances for each instance. configure_servald_server() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.rhizome on - executeOk_servald config set debug.rhizometx on - executeOk_servald config set debug.rhizomerx on - executeOk_servald config set server.respawn_on_crash off - executeOk_servald config set mdp.iftype.wifi.tick_ms 500 - executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1 + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set debug.rhizome on \ + set debug.rhizometx on \ + set debug.rhizomerx on \ + set server.respawn_on_crash off \ + set mdp.iftype.wifi.tick_ms 500 \ + set mdp.selfannounce.ticks_per_full_address 1 } doc_FileTransferStress="Stress - five nodes each sharing 16 bundles" diff --git a/tests/routing b/tests/routing index b4ff1212..27b3304a 100755 --- a/tests/routing +++ b/tests/routing @@ -21,9 +21,10 @@ source "${0%/*}/../testframework.sh" source "${0%/*}/../testdefs.sh" configure_servald_server() { - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.mdprequests Yes + executeOk_servald config \ + set log.show_pid on \ + set log.show_time on \ + set debug.mdprequests Yes } add_interface() { @@ -34,12 +35,13 @@ add_interface() { } start_routing_instance() { - executeOk_servald config set server.dummy_interface_dir "$SERVALD_VAR" - executeOk_servald config set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" - executeOk_servald config set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" - executeOk_servald config set log.show_pid on - executeOk_servald config set log.show_time on - executeOk_servald config set debug.mdprequests Yes + executeOk_servald config \ + set server.dummy_interface_dir "$SERVALD_VAR" \ + set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" \ + set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" \ + set log.show_pid on \ + set log.show_time on \ + set debug.mdprequests Yes start_servald_server } diff --git a/tests/server b/tests/server index 90586955..0529b0b9 100755 --- a/tests/server +++ b/tests/server @@ -28,9 +28,10 @@ setup() { setup_interfaces() { >$TFWTMP/dummy - executeOk_servald config set interfaces "+>$TFWTMP/dummy" - executeOk_servald config set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" - executeOk_servald config set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" + executeOk_servald config \ + set interfaces "+>$TFWTMP/dummy" \ + set monitor.socket "org.servalproject.servald.monitor.socket.$TFWUNIQUE.$instance_name" \ + set mdp.socket "org.servalproject.servald.mdp.socket.$TFWUNIQUE.$instance_name" } teardown() {