#!/bin/sh
# PCP QA Test No. 751
# Exercise RPM Package Manager PMDA log rewriting rules
#
# Copyright (c) 2014 Red Hat.
#
seq=`basename $0`
echo "QA output created by $seq"

. ./common.rpm
_rpm_support_tests

status=1	# failure is the default!
$sudo rm -fr $tmp.* $seq.full
trap "_rpm_cleanup" 0 1 2 3 15

create_rewrite_logs()
{
    cat <<'End-of-File' >$tmp.log.conf
log mandatory on once {
  rpm.arch
  rpm.buildhost
  rpm.buildtime
  rpm.description
  rpm.epoch
  rpm.group
  rpm.installtime
  rpm.license
  rpm.packager
  rpm.release
  rpm.size
  rpm.sourcerpm
  rpm.summary
  rpm.url
  rpm.vendor
  rpm.version
  rpm.name
  rpm.refresh.count
  rpm.refresh.time.user
  rpm.refresh.time.sys
  rpm.refresh.time.elapsed
  rpm.datasize
  rpm.total.count
  rpm.total.bytes
}
End-of-File
    pmlogger -r -c $tmp.log.conf -T 2sec $tmp.log
    echo 'metric 123.1.10 { type -> U32 }' > $tmp.lrw.conf
    pmlogrewrite -c $tmp.lrw.conf -w $tmp.log $tmp.log-1
    migrate=$PCP_VAR_DIR/config/pmlogrewrite/rpm_migrate.conf
    pmlogrewrite -c $migrate -w $tmp.log-1 $tmp.log-2
    rm $tmp.log.conf $tmp.lrw.conf
    echo "+++ log +++" >>$seq.full
    pmdumplog -z -dil $tmp.log   | tee -a $seq.full >$tmp.log.dump
    echo "+++ log-1 +++" >>$seq.full
    pmdumplog -z -dil $tmp.log-1 | tee -a $seq.full >$tmp.log-1.dump
    echo "+++ log-2 +++" >>$seq.full
    pmdumplog -z -dil $tmp.log-2 | tee -a $seq.full >$tmp.log-2.dump
}

# real QA test starts here

echo
_rpm_pmda_prepare
create_rewrite_logs
echo "old -> new changes" | tee -a $seq.full
diff -u $tmp.log-1.dump $tmp.log-2.dump | tee -a $seq.full | sed -e '/^---/d' -e '/^+++/d'
echo "new -> ref changes ... expect none" | tee -a $seq.full
diff -u $tmp.log-2.dump $tmp.log.dump | tee -a $seq.full | sed -e '/^---/d' -e '/^+++/d'

# success, all done
status=0
exit
