bstinson / centos / t_functional

Forked from centos/t_functional 4 years ago
Clone

Blame tests/p_abrt-cli/10-abrt-cli-reporting-test.sh

Matej Habrnal e4efea
#!/bin/bash
Matej Habrnal e4efea
# Author: Matej Habrnal <mhabrnal@redhat.com>
Matej Habrnal e4efea
Matej Habrnal e4efea
TEST_DIR="tests/p_abrt-cli"
Matej Habrnal e4efea
source $TEST_DIR/_lib.sh
Matej Habrnal e4efea
source $TEST_DIR/_CentOSBugTracker.conf
Matej Habrnal e4efea
401300
t_Log "Running $0 - test reporting to CentOS Bug Tracker"
401300
401300
# testing if bugs-test.centos.org is reachable for that test ..
401300
curl --silent -I http://bugs-test.centos.org/my_view_page.php|grep -q "HTTP/1.1 200 OK"
401300
if [ "$?" -ne "0" ];then
401300
  t_Log "Mantis test instance doesn't seem reachable ... SKIP"
401300
  exit 0
401300
fi
401300
Matej Habrnal e4efea
# run only on centos 7 or greater
Matej Habrnal 50921c
[[ $centos_ver -lt 7 ]] && exit 0
Matej Habrnal e4efea
Matej Habrnal e4efea
Matej Habrnal e4efea
conf_file="/etc/libreport/events/report_CentOSBugTracker.conf"
Matej Habrnal 50921c
abrt_action_conf_file="/etc/abrt/abrt-action-save-package-data.conf"
Matej Habrnal e4efea
Matej Habrnal e4efea
cat > /etc/libreport/events.d/test_event.conf << _EOF_
Matej Habrnal e4efea
EVENT=notify
Matej Habrnal e4efea
        touch /tmp/abrt-done
Matej Habrnal e4efea
EVENT=notify-dup
Matej Habrnal e4efea
        touch /tmp/abrt-done
Matej Habrnal e4efea
_EOF_
Matej Habrnal e4efea
Matej Habrnal e4efea
function wait_for_hooks() {
Matej Habrnal e4efea
    echo "Waiting for all hooks to end"
Matej Habrnal e4efea
    local c=0
Matej Habrnal e4efea
    while [ ! -f "/tmp/abrt-done" ]; do
Matej Habrnal e4efea
        sleep 0.1
Matej Habrnal e4efea
        let c=$c+1
Matej Habrnal e4efea
        if [ $c -gt 3000 ]; then
Matej Habrnal e4efea
            echo "Timeout"
Matej Habrnal e4efea
            break
Matej Habrnal e4efea
        fi
Matej Habrnal e4efea
    done
Matej Habrnal e4efea
    t=$( echo "scale=2; $c/10" | bc )
Matej Habrnal e4efea
    echo "Hooks ended in $t seconds"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function get_crash_path()
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    crash_PATH="$(abrt-cli list 2> /dev/null | grep Directory | awk '{ print $2 }' | tail -n1)"
Matej Habrnal e4efea
Matej Habrnal e4efea
    if [ ! -d "$crash_PATH" ]; then
Matej Habrnal e4efea
        echo "No crash dir generated, this shouldn't happen"
Matej Habrnal e4efea
        exit 1
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
    echo "crash dir path: $crash_PATH"
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function check_prior_crashes()
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    abrt-cli list 2> /dev/null >cli-list.log
Matej Habrnal e4efea
    count_of_crashes=`wc -l < cli-list.log`
Matej Habrnal e4efea
    rm -f cli-list.log
Matej Habrnal e4efea
Matej Habrnal e4efea
    if [[ $count_of_crashes != 0 ]]; then
Matej Habrnal e4efea
        echo "There are some existing crashes"
Matej Habrnal e4efea
        exit 1
Matej Habrnal e4efea
    fi
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function generate_crash()
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    echo "Generate crash"
Matej Habrnal e4efea
    sleep 1000 &
Matej Habrnal e4efea
    kill -SIGSEGV $!
Matej Habrnal e4efea
    sleep 3
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function set_configuration()
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    conf_file_original=`cat $conf_file`
Matej Habrnal 50921c
    abrt_action_conf_file_original=`cat $abrt_action_conf_file`
Matej Habrnal e4efea
Matej Habrnal e4efea
    cat > $conf_file << EOF
Matej Habrnal e4efea
Mantisbt_MantisbtURL = $URL
Matej Habrnal e4efea
Mantisbt_Login = $LOGIN
Matej Habrnal e4efea
Mantisbt_Password = $PASSWORD
Matej Habrnal e4efea
Mantisbt_SSLVerify = $SSLVERIFY
Matej Habrnal e4efea
EOF
Matej Habrnal 50921c
Matej Habrnal 50921c
    cat > $abrt_action_conf_file << EOF
621a24
OpenGPGCheck = no
Matej Habrnal 50921c
BlackList = nspluginwrapper, valgrind, strace, mono-core
Matej Habrnal 50921c
ProcessUnpackaged = no
Matej Habrnal 50921c
BlackListedPaths = /usr/share/doc/*, */example*, /usr/bin/nspluginviewer, /usr/lib/xulrunner-*/plugin-container
Matej Habrnal 50921c
Interpreters = python2, python2.7, python, python3, python3.3, perl, perl5.16.2
Matej Habrnal 50921c
EOF
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
function restore_configuration()
Matej Habrnal e4efea
{
Matej Habrnal e4efea
    echo $conf_file_original > $conf_file
Matej Habrnal 50921c
    echo $abrt_action_conf_file_original > $abrt_action_conf_file
Matej Habrnal e4efea
}
Matej Habrnal e4efea
Matej Habrnal e4efea
rlJournalStart
Matej Habrnal e4efea
    rlPhaseStartSetup
Matej Habrnal e4efea
        LANG=""
Matej Habrnal e4efea
        export LANG
Matej Habrnal e4efea
Matej Habrnal e4efea
        check_prior_crashes
Matej Habrnal e4efea
Matej Habrnal 50921c
        systemctl start abrtd
Matej Habrnal 50921c
        systemctl start abrt-ccpp
Matej Habrnal 50921c
Matej Habrnal e4efea
        orig_editor=`echo $EDITOR`
Matej Habrnal e4efea
        export EDITOR=cat
Matej Habrnal e4efea
Matej Habrnal e4efea
        TmpDir=$(mktemp -d)
Matej Habrnal e4efea
        cp $TEST_DIR/_expect $TmpDir/expect
Matej Habrnal e4efea
        cp $TEST_DIR/_expect_report $TmpDir/expect_report
Matej Habrnal e4efea
Matej Habrnal e4efea
        pushd $TmpDir
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
Matej Habrnal e4efea
    rlPhaseStartTest "testing workflow"
Matej Habrnal e4efea
        generate_crash
Matej Habrnal e4efea
        get_crash_path
Matej Habrnal e4efea
        wait_for_hooks
Matej Habrnal e4efea
Matej Habrnal e4efea
        rlRun "./expect $crash_PATH &> abrt-cli.log" 0 "run abrt-cli report CRASH_DIR"
Matej Habrnal e4efea
Matej Habrnal e4efea
        rlAssertGrep "CentOS Bug Tracker User name:" abrt-cli.log
Matej Habrnal e4efea
        rlAssertGrep "CentOS Bug Tracker Password:" abrt-cli.log
Matej Habrnal e4efea
Matej Habrnal 814705
        mv -fv abrt-cli.log p_abrt-cli-testing_workflow.log
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
Matej Habrnal e4efea
    rlPhaseStartTest "create a new issue"
Matej Habrnal e4efea
        #set url, username and password
Matej Habrnal e4efea
        set_configuration
Matej Habrnal e4efea
Matej Habrnal e4efea
        echo "I am comment. abrt-cli testing" > $crash_PATH/comment
Matej Habrnal e4efea
        hash=`date +%s`
Matej Habrnal e4efea
        echo $hash > $crash_PATH/duphash
Matej Habrnal e4efea
        rlRun "./expect_report $crash_PATH &> abrt-cli.log" 0 "run report-cli -e report_CentOSBugTracker CRASH_DIR"
Matej Habrnal e4efea
Matej Habrnal e4efea
        rlAssertGrep "Checking for duplicates" abrt-cli.log
Matej Habrnal e4efea
        rlAssertGrep "Creating a new issue" abrt-cli.log
Matej Habrnal e4efea
        rlAssertGrep "Adding External URL to issue" abrt-cli.log
Matej Habrnal c5a56e
        rlAssertNotGrep "Failed to create a new issue" abrt-cli.log
Matej Habrnal c5a56e
        rlAssertNotGrep "504 Gateway Time-out" abrt-cli.log
Matej Habrnal c5a56e
Matej Habrnal c5a56e
        grep -q "504 Gateway Time-out" abrt-cli.log
Matej Habrnal c5a56e
        if [ "$?" -eq "0" ];then
Matej Habrnal c5a56e
            echo "!!! Server $URL respond with '504 Gateway Time-out' !!!"
Matej Habrnal c5a56e
        fi
Matej Habrnal e4efea
Matej Habrnal e4efea
        #get issue id
Matej Habrnal e4efea
        issue_id=`grep "Status: new " abrt-cli.log | grep -e [0-9]* -o`
Matej Habrnal c5a56e
        if [ "_$issue_id" == "_" ];then
Matej Habrnal c5a56e
            echo "No ID of created issue"
Matej Habrnal c5a56e
        else
Matej Habrnal c5a56e
            echo "Created issue $issue_id"
Matej Habrnal c5a56e
        fi
Matej Habrnal e4efea
Matej Habrnal 814705
        mv -fv abrt-cli.log p_abrt-cli-created_new_issue.log
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
Matej Habrnal e4efea
    rlPhaseStartTest "duplicate issue"
Matej Habrnal e4efea
Matej Habrnal e4efea
        rlRun "./expect_report $crash_PATH &> abrt-cli.log" 0 "run report-cli -e report_CentOSBugTracker CRASH_DIR"
Matej Habrnal e4efea
Matej Habrnal e4efea
        rlAssertGrep "Checking for duplicates" abrt-cli.log
Matej Habrnal e4efea
        rlAssertGrep "Bug is already reported:" abrt-cli.log
Matej Habrnal e4efea
        rlAssertGrep "Adding new comment to issue" abrt-cli.log
Matej Habrnal e4efea
Matej Habrnal 814705
        mv -fv abrt-cli.log p_abrt-cli-duplicate_issue.log
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
Matej Habrnal e4efea
    rlPhaseStartTest "check created issue"
Matej Habrnal e4efea
Matej Habrnal e4efea
        data="<SOAP-ENV:Envelope xmlns:ns3=\"http://futureware.biz/mantisconnect\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns0=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns2=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><SOAP-ENV:Header/><ns1:Body><ns3:mc_issue_get><username xsi:type=\"ns2:string\">$LOGIN</username><password xsi:type=\"ns2:string\">$PASSWORD</password><issue_id xsi:type=\"ns2:integer\">$issue_id</issue_id></ns3:mc_issue_get></ns1:Body></SOAP-ENV:Envelope>"
Matej Habrnal e4efea
Matej Habrnal 50921c
        curl --data "$data" -H "Content-Type:text/xml" $URL"/api/soap/mantisconnect.php" > curl.log
Matej Habrnal e4efea
        rlAssertGrep "<summary xsi:type=\"xsd:string\">\[abrt\]" curl.log
Matej Habrnal e4efea
        rlAssertGrep "I am comment. abrt-cli testing" curl.log
Matej Habrnal e4efea
        rlAssertGrep "AttachmentData\[[0-9]*\]" curl.log -e
Matej Habrnal e4efea
        rlAssertNotGrep "AttachmentData\[0\]" curl.log
Matej Habrnal e4efea
        rlAssertGrep "CustomFieldValueForIssueData\[[0-9]*\]" curl.log -e
Matej Habrnal e4efea
        rlAssertNotGrep "CustomFieldValueForIssueData\[0\]" curl.log
Matej Habrnal 50921c
        rlAssertGrep "IssueNoteData\[1\]\"" curl.log
Matej Habrnal e4efea
Matej Habrnal 814705
        mv -fv curl.log p_abrt-cli-check_created_issue.log
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
Matej Habrnal e4efea
    rlPhaseStartCleanup
Matej Habrnal e4efea
        restore_configuration
Matej Habrnal e4efea
        rlRun "abrt-cli remove $crash_PATH" 0
Matej Habrnal e4efea
        rlBundleLogs #create test statistic
Matej Habrnal 814705
        # copy all log to /tmp/
Matej Habrnal 814705
        cp -v p_abrt-cli*.log /tmp/
Matej Habrnal e4efea
        popd # TmpDir
Matej Habrnal e4efea
        rm -rf $TmpDir
Matej Habrnal e4efea
        export EDITOR=$orig_editor
Matej Habrnal e4efea
        rm -f "/tmp/abrt-done"
Matej Habrnal e4efea
    rlPhaseEnd
Matej Habrnal e4efea
    rlJournalPrintText
Matej Habrnal e4efea
rlJournalEnd