Skip to content

Commit

Permalink
add tests for bigiq, fix issue #9
Browse files Browse the repository at this point in the history
add tests for bigiq, fix issue #9
  • Loading branch information
simonkowallik authored May 18, 2019
2 parents 377e828 + e04ddd0 commit afb1a75
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ before_script:
script:
- ./tests/test_fileget.sh
- ./tests/test_diagnostics.sh
- ./tests/test_qkviewdelete.sh
- ./tests/test_qkviewdelete.sh
- ./tests/test_fileget_bigiq.sh
- ./tests/test_diagnostics_bigiq.sh
- ./tests/test_qkviewdelete_bigiq.sh
3 changes: 2 additions & 1 deletion ihac-qkviewlist
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0" --user-agent
| perl -ne 's/\r\n//g;
if(m|http/1.. 30\d|gi) {print STDERR "Error: not authenticated.\n";exit 1}
if(!m|http/1.. (404)|gi && m|http/1.. (40\d)|gi) {print STDERR "Error: received $1 from server.\n";exit 1}
my ($serial, $hostname, $case, $date, $id) = ();
if(m|<chassis_serial>(.*)</chassis_serial>|gi) {$serial=$1}
if(m|<hostname>(.*)</hostname>|gi) {$hostname=$1}
if(m|<f5_support_case>(.*)</f5_support_case>|gi) {$case=$1}
Expand All @@ -44,4 +45,4 @@ curl -si$IHACPROXY -H"Accept: application/vnd.f5.ihealth.api.v1.0" --user-agent
if ( defined($id)) {
printf "%d %-30s %-31s %-12s %s\n", $id, $hostname, $serial, scalar localtime($date), $case;
undef $id, $hostname, $serial, $date, $case;
}'
}'
2 changes: 2 additions & 0 deletions tests/diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
Binary file added tests/qkview_bigiq.tgz
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/test_diagnostics_bigiq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -ev

# test specific setup
bigiq_qkviewid=$(<./bigiq_qkviewid)


# check if Sevirity is part of the response
[[ $(./ihac-diagnostics $bigiq_qkviewid | grep -e 'Severity: LOW' -e 'Severity: MEDIUM' -e 'Severity: HIGH' | wc -l) -gt 0 ]] || exit 1


# check if SOLs/K entries exist
[[ $(./ihac-diagnostics $bigiq_qkviewid | grep -e 'SOLs:.*f5\.com' | wc -l) -gt 0 ]] || exit 1


# check if json is returned
./ihac-diagnostics --json $bigiq_qkviewid | jq . >/dev/null 2>&1 || exit 1


# check if valid xml is returned
./ihac-diagnostics --xml $bigiq_qkviewid | xmllint - >/dev/null 2>&1 || exit 1


# check behaviour when qkview does not exist
[[ $(./ihac-diagnostics 245245245 2>&1) == "Error: qkview ID not found." ]] || exit 1
26 changes: 26 additions & 0 deletions tests/test_fileget_bigiq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -ev

# test specific setup
bigiq_qkviewid=$(<./bigiq_qkviewid)
mkdir -p ./fileget_bigiq


# test simple file fetch
./ihac-fileget $bigiq_qkviewid /VERSION | grep '^Product:' > /dev/null || exit 1


# test directory ./directory-does-not-exist does not exist
missing_directory=$(./ihac-fileget -o ./directory-does-not-exist/ $bigiq_qkviewid /config/bigip.conf 2>&1 && exit 1) || \
echo "$missing_directory" | grep 'directory-does-not-exist' > /dev/null || exit 1


# download multiple files to output directory
./ihac-fileget --output-directory ./fileget_bigiq/ $bigiq_qkviewid /VERSION /config/bigip.conf && \
grep 'TMSH-VERSION' ./fileget_bigiq/config/bigip.conf && \
grep '^Product:' ./fileget_bigiq/VERSION


# download multiple files to output directory using wildcards
./ihac-fileget --output-directory ./fileget_bigiq/ $bigiq_qkviewid /config/bigip*.conf /etc/security/* && \
[[ $(find ./fileget_bigiq -type f | wc -l) -gt 2 ]] || exit 1
17 changes: 17 additions & 0 deletions tests/test_qkviewdelete_bigiq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -ev

# test specific setup
bigiq_qkviewid=$(<./bigiq_qkviewid)


# test qkview deletion
[[ "$(./ihac-qkviewdelete $bigiq_qkviewid)" == "$bigiq_qkviewid OK" ]] || exit 1


# check if qkview was removed from ihealth
./ihac-qkviewlist | grep $bigiq_qkviewid && exist 1 || true


# check behaviour when qkview does not exist
[[ $(./ihac-qkviewdelete 245245245 2>&1) == "Error: qkview ID not found." ]] || exit 1
7 changes: 6 additions & 1 deletion tests/test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ broken_qkviewid=$(./ihac-qkviewadd ./tests/qkview.tgz | egrep -o '([0-9]+)')
echo "$broken_qkviewid" > ./broken_qkviewid
[[ -z $broken_qkviewid ]] && echo "broken_qkviewid empty" && exit 1

# upload bigiq qkview
bigiq_qkviewid=$(./ihac-qkviewadd ./tests/qkview_bigiq.tgz | egrep -o '([0-9]+)')
echo "$bigiq_qkviewid" > ./bigiq_qkviewid
[[ -z $bigiq_qkviewid ]] && echo "bigiq_qkviewid empty" && exit 1

# wait for ihealth to finish analysis
while [[ "$(./ihac-filelist $qkviewid | wc -l)" -eq "0" ]]
do
sleep 10; echo -n '.'
done
echo 'done'
echo 'done'

0 comments on commit afb1a75

Please sign in to comment.