From 63fd63c69823e119292bc6e91e668c6d942a3b24 Mon Sep 17 00:00:00 2001 From: Peter Stamfest Date: Fri, 5 Sep 2014 08:39:42 +0200 Subject: [PATCH] Fix tune related test scripts to work in the presence of a caching daemon. Also do explicit "forgetting" of just tuned RRD, because "tune" is never done via rrdcached. --- src/rrd_tune.c | 18 ++++++++++++++++-- tests/functions | 6 +++++- tests/tune1 | 7 +++++++ tests/tune2 | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/rrd_tune.c b/src/rrd_tune.c index ad41d73f..4d73d410 100644 --- a/src/rrd_tune.c +++ b/src/rrd_tune.c @@ -88,6 +88,7 @@ int rrd_tune( rrd_file_t *rrd_file = NULL; char *opt_daemon = NULL; char double_str[ 12 ]; + const char *in_filename = NULL; struct option long_options[] = { {"heartbeat", required_argument, 0, 'h'}, {"minimum", required_argument, 0, 'i'}, @@ -145,7 +146,7 @@ int rrd_tune( // connect to daemon (will take care of environment variable automatically) if (rrdc_connect(opt_daemon) != 0) { - rrd_set_error("Cannot connect to daemon"); + rrd_set_error("Cannot connect to daemon"); return 1; } @@ -164,7 +165,7 @@ int rrd_tune( the back, starting with optind. This means the file name has travelled to argv[optind] */ - const char *in_filename = argv[optind]; + in_filename = argv[optind]; if (rrdc_is_any_connected()) { // is it a good idea to just ignore the error ???? @@ -412,6 +413,19 @@ int rrd_tune( rc = 0; done: + if (in_filename && rrdc_is_any_connected()) { + // save any errors.... + char *e = strdup(rrd_get_error()); + // is it a good idea to just ignore the error ???? + rrdc_forget(in_filename); + rrd_clear_error(); + + if (e && *e) { + rrd_set_error(e); + } + if (e) free(e); + + } if (rrd_file) { rrd_close(rrd_file); } diff --git a/tests/functions b/tests/functions index f68ecc43..0b081652 100644 --- a/tests/functions +++ b/tests/functions @@ -124,10 +124,14 @@ function stop_cached { fi } +function is_cached { + [ -n "$RRDCACHED_ADDRESS" ] +} + function exit_if_cached_running { local E="$1" local MSG="$2" - if [ -n "$RRDCACHED_ADDRESS" ] ; then + if is_cached ; then echo >&2 "$MSG" exit ${E:-1} fi diff --git a/tests/tune1 b/tests/tune1 index ee0e0d5a..83e581ef 100755 --- a/tests/tune1 +++ b/tests/tune1 @@ -17,11 +17,18 @@ done $RRDTOOL update ${BUILD}org.rrd --template a $U report "update" +# NOTE: for rrdcached based tests, we must flush before we can copy... +is_cached && ( $RRDTOOL flushcached ${BUILD}org.rrd || fail flushcached) + + cp ${BUILD}org.rrd ${BUILD}a.rrd $RRDTOOL tune ${BUILD}a.rrd --heartbeat a:90 --minimum b:-100 $RRDTOOL dump ${BUILD}a.rrd | $DIFF - ${BASE}a-mod1.dump report "tune heartbeat/minimum" +# NOTE: for rrdcached based tests, we must flush before we can copy... +is_cached && ( $RRDTOOL flushcached ${BUILD}org.rrd || fail flushcached ) + cp ${BUILD}org.rrd ${BUILD}a.rrd $RRDTOOL tune ${BUILD}a.rrd --data-source-type a:COUNTER --data-source-rename b:c $RRDTOOL dump ${BUILD}a.rrd | $DIFF - ${BASE}a-mod2.dump diff --git a/tests/tune2 b/tests/tune2 index 378e68c3..f720dd1d 100755 --- a/tests/tune2 +++ b/tests/tune2 @@ -11,10 +11,10 @@ $RRDTOOL create ${BUILD}org.rrd --start 1300000000 --step 60 DS:a:GAUGE:120:0:U $RRDTOOL dump ${BUILD}org.rrd | $DIFF - ${BASE}org.dump report create +is_cached && ( $RRDTOOL flushcached ${BUILD}org.rrd || fail flushcached ) cp ${BUILD}org.rrd ${BUILD}a.rrd # this must fail -$RRDTOOL tune ${BUILD}a.rrd --beta 1.4 2>/dev/null -[ $? != 0 ] +! $RRDTOOL tune ${BUILD}a.rrd --beta 1.4 2>/dev/null report "out of range beta error" $RRDTOOL dump ${BUILD}a.rrd | $DIFF - ${BASE}org.dump report "RRD unchanged" -- 2.47.2