Skip to content

Commit

Permalink
tests: Use environment variable for default timeout.
Browse files Browse the repository at this point in the history
Introduce new 'OVS_CTL_TIMEOUT' environment variable
that, if set, will be used as a default timeout for
OVS control utilities. Setting it in 'atlocal.in' will
cover all the hangs inside the testsuite, even when
utils called in a subshell.

Signed-off-by: Ilya Maximets <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
igsilya authored and blp committed Aug 15, 2018
1 parent cbcf40a commit 9551e80
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 34 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Post-v2.10.0
---------------------
- The environment variable OVS_SYSLOG_METHOD, if set, is now used
as the default syslog method.
- The environment variable OVS_CTL_TIMEOUT, if set, is now used
as the default timeout for control utilities.


v2.10.0 - xx xxx xxxx
Expand Down
18 changes: 18 additions & 0 deletions lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ get_boot_time(void)
return boot_time;
}

/* This is a wrapper for setting timeout in control utils.
* The value of OVS_CTL_TIMEOUT environment variable will be used by
* default if 'secs' is not specified. */
void
ctl_timeout_setup(unsigned int secs)
{
if (!secs) {
char *env = getenv("OVS_CTL_TIMEOUT");

if (env && env[0]) {
str_to_uint(env, 10, &secs);
}
}
if (secs) {
time_alarm(secs);
}
}

/* Returns a pointer to a string describing the program version. The
* caller must not modify or free the returned string.
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const char *get_subprogram_name(void);
unsigned int get_page_size(void);
long long int get_boot_time(void);

void ctl_timeout_setup(unsigned int secs);

void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);

OVS_NO_RETURN void out_of_memory(void);
Expand Down
8 changes: 2 additions & 6 deletions ovn/utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ main(int argc, char *argv[])
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
}
ctl_timeout_setup(timeout);

error = run_prerequisites(commands, n_commands, idl);
if (error) {
Expand Down Expand Up @@ -5381,9 +5379,7 @@ nbctl_client(const char *socket_name,
svec_add(&args, argv[i]);
}

if (timeout) {
time_alarm(timeout);
}
ctl_timeout_setup(timeout);

struct jsonrpc *client;
int error = unixctl_client_create(socket_name, &client);
Expand Down
4 changes: 1 addition & 3 deletions ovn/utilities/ovn-sbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ main(int argc, char *argv[])
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
}
ctl_timeout_setup(timeout);

/* Initialize IDL. */
idl = the_idl = ovsdb_idl_create(db, &sbrec_idl_class, false, true);
Expand Down
6 changes: 3 additions & 3 deletions ovsdb/ovsdb-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,11 @@ parse_options(int argc, char *argv[])
{NULL, 0, NULL, 0},
};
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
unsigned int timeout = 0;

table_style.format = TF_TABLE;

for (;;) {
unsigned int timeout = 0;
int c;

c = getopt_long(argc, argv, short_options, long_options, NULL);
Expand Down Expand Up @@ -368,8 +368,6 @@ parse_options(int argc, char *argv[])
case 't':
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}
break;

Expand All @@ -393,6 +391,8 @@ parse_options(int argc, char *argv[])
}
}
free(short_options);

ctl_timeout_setup(timeout);
}

static void
Expand Down
8 changes: 7 additions & 1 deletion python/ovs/fatal_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@ def _init():


def signal_alarm(timeout):
if not timeout:
env_timeout = os.environ.get('OVS_CTL_TIMEOUT')
if env_timeout:
timeout = int(env_timeout)
if not timeout:
return

if sys.platform == "win32":
import os
import time
import threading

Expand Down
3 changes: 1 addition & 2 deletions tests/appctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def main():
help="wait at most SECS seconds for a response")
args = parser.parse_args()

if args.timeout:
signal_alarm(int(args.timeout))
signal_alarm(int(args.timeout) if args.timeout else None)

ovs.vlog.Vlog.init()
target = args.target
Expand Down
4 changes: 4 additions & 0 deletions tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,7 @@ unset OVN_SB_DB
# Prevent logging to syslog during tests.
OVS_SYSLOG_METHOD=null
export OVS_SYSLOG_METHOD

# Set default timeout for control utils
OVS_CTL_TIMEOUT=30
export OVS_CTL_TIMEOUT
6 changes: 3 additions & 3 deletions tests/test-ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)
{NULL, 0, NULL, 0},
};
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
unsigned int timeout = 0;

for (;;) {
unsigned int timeout = 0;
int c;

c = getopt_long(argc, argv, short_options, long_options, NULL);
Expand All @@ -108,8 +108,6 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)
case 't':
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}
break;

Expand Down Expand Up @@ -140,6 +138,8 @@ parse_options(int argc, char *argv[], struct test_ovsdb_pvt_context *pvt)
}
}
free(short_options);

ctl_timeout_setup(timeout);
}

static void
Expand Down
4 changes: 3 additions & 1 deletion tests/test-ovsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def main(argv):
sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg))
sys.exit(1)

timeout = None
for key, value in options:
if key in ['-h', '--help']:
usage()
Expand All @@ -833,10 +834,11 @@ def main(argv):
except TypeError:
raise error.Error("value %s on -t or --timeout is not at "
"least 1" % value)
signal_alarm(timeout)
else:
sys.exit(0)

signal_alarm(timeout)

if not args:
sys.stderr.write("%s: missing command argument "
"(use --help for help)\n" % ovs.util.PROGRAM_NAME)
Expand Down
6 changes: 3 additions & 3 deletions utilities/ovs-appctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ parse_command_line(int argc, char *argv[])
char *short_options = xasprintf("+%s", short_options_);
const char *target;
int e_options;
unsigned int timeout = 0;

target = NULL;
e_options = 0;
for (;;) {
int option;
unsigned int timeout = 0;

option = getopt_long(argc, argv, short_options, long_options, NULL);
if (option == -1) {
Expand Down Expand Up @@ -168,8 +168,6 @@ parse_command_line(int argc, char *argv[])
case 'T':
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
ovs_fatal(0, "value %s on -T or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}
break;

Expand All @@ -189,6 +187,8 @@ parse_command_line(int argc, char *argv[])
free(short_options_);
free(short_options);

ctl_timeout_setup(timeout);

if (optind >= argc) {
ovs_fatal(0, "at least one non-option argument is required "
"(use --help for help)");
Expand Down
7 changes: 4 additions & 3 deletions utilities/ovs-dpctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ parse_options(int argc, char *argv[])
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);

bool set_names = false;
unsigned int timeout = 0;

for (;;) {
unsigned int timeout = 0;
int c;

c = getopt_long(argc, argv, short_options, long_options, NULL);
Expand Down Expand Up @@ -143,8 +144,6 @@ parse_options(int argc, char *argv[])
case 't':
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}
break;

Expand All @@ -170,6 +169,8 @@ parse_options(int argc, char *argv[])
}
free(short_options);

ctl_timeout_setup(timeout);

if (!set_names) {
dpctl_p.names = dpctl_p.verbosity > 0;
}
Expand Down
6 changes: 3 additions & 3 deletions utilities/ovs-ofctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ parse_options(int argc, char *argv[])
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
uint32_t versions;
enum ofputil_protocol version_protocols;
unsigned int timeout = 0;

/* For now, ovs-ofctl only enables OpenFlow 1.0 by default. This is
* because ovs-ofctl implements command such as "add-flow" as raw OpenFlow
Expand All @@ -272,7 +273,6 @@ parse_options(int argc, char *argv[])
set_allowed_ofp_versions("OpenFlow10");

for (;;) {
unsigned int timeout = 0;
int c;

c = getopt_long(argc, argv, short_options, long_options, NULL);
Expand All @@ -284,8 +284,6 @@ parse_options(int argc, char *argv[])
case 't':
if (!str_to_uint(optarg, 10, &timeout) || !timeout) {
ovs_fatal(0, "value %s on -t or --timeout is invalid", optarg);
} else {
time_alarm(timeout);
}
break;

Expand Down Expand Up @@ -391,6 +389,8 @@ parse_options(int argc, char *argv[])
}
}

ctl_timeout_setup(timeout);

if (n_criteria) {
/* Always do a final sort pass based on priority. */
add_sort_criterion(SORT_DESC, "priority");
Expand Down
4 changes: 1 addition & 3 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ main(int argc, char *argv[])
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
}
ctl_timeout_setup(timeout);

/* Initialize IDL. */
idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class, false, retry);
Expand Down
4 changes: 1 addition & 3 deletions vtep/vtep-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ main(int argc, char *argv[])
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
}
ctl_timeout_setup(timeout);

/* Initialize IDL. */
idl = the_idl = ovsdb_idl_create(db, &vteprec_idl_class, false, false);
Expand Down

0 comments on commit 9551e80

Please sign in to comment.