#!/bin/bash

. $(dirname $0)/functions

BASE=$BASEDIR/modify4-test
BUILD=$BUILDDIR/modify4-test

# create 2 RRDs only differing in the way that the second contains an additional RRA
# test: remove the additional RRA from the second and compare dumps
# test: add the additional RRA to the first and compare dumps 


$RRDTOOL create ${BUILD}a1.rrd --start 1300000000 --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 || fail create1
$RRDTOOL create ${BUILD}a2.rrd --start 1300000000 --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 RRA:AVERAGE:0.5:4:10 || fail create2

# add 50 values - note that we do NOT add it exactly for boundary times, and 
# that we end at a NON CDP boundary for 5-PDP RRAs:
N=10
UPDATE=
for T in $(seq 1300000050 60 1300002990) ; do
        UPDATE="$UPDATE $T:$N"
	let N=$N+10
done

$RRDTOOL update ${BUILD}a1.rrd --template a $UPDATE || fail update1
$RRDTOOL update ${BUILD}a2.rrd --template a $UPDATE || fail update2

$RRDTOOL dump ${BUILD}a1.rrd | $DIFF9 ${BASE}a1-create.dump -
report create 1
$RRDTOOL dump ${BUILD}a2.rrd | $DIFF9 ${BASE}a2-create.dump -
report create 2

cp ${BASE}a2.rrd ${BASE}b2.rrd
$RRDTOOL tune ${BUILD}b2.rrd DELRRA:5 || fail modify

$RRDTOOL dump ${BUILD}b2.rrd | $DIFF9 ${BASE}a1-create.dump -
report "remove additional RRA from second - must then be equal original first"

cp ${BASE}a1.rrd ${BASE}b1.rrd
$RRDTOOL tune ${BUILD}b1.rrd RRA:AVERAGE:0.5:4:10 || fail modify

$RRDTOOL dump ${BUILD}b1.rrd | $DIFF9 ${BASE}a2-create.dump -
report "add additional RRA to first - must then be equal original second"

