From 162d9aeb589a868e9bafcea73924834b220c643a Mon Sep 17 00:00:00 2001
From: Susant Sahani <ssahani@gmail.com>
Date: Feb 14 2019 13:14:08 +0000
Subject: standard-test-beakerlib: Move beakerlib bash scripts to own file


see https://pagure.io/standard-test-roles/issue/286

---

diff --git a/roles/standard-test-beakerlib/files/beakerlib-test.sh b/roles/standard-test-beakerlib/files/beakerlib-test.sh
new file mode 100755
index 0000000..f770350
--- /dev/null
+++ b/roles/standard-test-beakerlib/files/beakerlib-test.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Called from main.yml to run beakerlib tests
+# beakerlib-test.sh {{ tenv_workdir }} {{ remote_artifacts }} {{ item }}
+
+export OUTPUTFILE=/dev/stdout TEST=$3
+export PATH="$PATH:$1"
+
+logfile=$2/$(echo $3 | sed -e 's/\//-/g').log
+
+exec 2>>$logfile 1>>$logfile
+cd $1
+
+if [ -f $3 ]; then
+    cd $(dirname $3)
+    /bin/sh -e ./$(basename $3)
+elif [ -d $3 ]; then
+    cd $3
+    # get-test-deps - is part of beakerlib-libraries
+    get-test-deps -i .
+    if [ -f Makefile ] && command -p -v make >/dev/null 2>&1; then
+        make run
+    elif [ -f runtest.sh ]; then
+        /bin/sh -e ./runtest.sh
+    else
+        echo "FAIL don't know how to run test $3"
+    fi
+else
+    echo "FAIL test $3 does not appear to be a file or directory"
+fi
diff --git a/roles/standard-test-beakerlib/files/log-summary-artifact.sh b/roles/standard-test-beakerlib/files/log-summary-artifact.sh
new file mode 100755
index 0000000..7c44cdf
--- /dev/null
+++ b/roles/standard-test-beakerlib/files/log-summary-artifact.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Called from main.yml to make the master tests summary log artifact
+# beakerlib-test.sh {{ tenv_workdir }} {{ remote_artifacts }} {{ item }}
+
+log_file_name=$(echo $2 | sed -e 's/\//-/g').log
+logfile=$1/${log_file_name}
+
+status="FAIL"
+
+if grep -q '\[ *FAIL *\]' "$logfile"; then
+    status="FAIL"
+elif grep -q '\[ *PASS *\]' "$logfile"; then
+    status="PASS"
+elif grep -q FAIL "$logfile"; then
+    status="FAIL"
+elif grep -q PASS "$logfile"; then
+    status="PASS"
+else
+    status="FAIL"
+fi
+
+echo "${status} $2" >> $1/test.log
+mv ${logfile} $1/${status}_${log_file_name}
diff --git a/roles/standard-test-beakerlib/tasks/main.yml b/roles/standard-test-beakerlib/tasks/main.yml
index f2a4d1a..e91f09b 100644
--- a/roles/standard-test-beakerlib/tasks/main.yml
+++ b/roles/standard-test-beakerlib/tasks/main.yml
@@ -52,29 +52,7 @@
 
 - block:
   - name: Run beakerlib tests
-    shell: |
-      export OUTPUTFILE=/dev/stdout TEST={{ item }}
-      export PATH="$PATH:{{ tenv_workdir }}"
-      logfile={{ remote_artifacts }}/$(echo {{ item }} | sed -e 's/\//-/g').log
-      exec 2>>$logfile 1>>$logfile
-      cd {{ tenv_workdir }}
-      if [ -f {{ item }} ]; then
-         cd $(dirname {{ item }})
-         /bin/sh -e ./$(basename {{ item }})
-      elif [ -d {{ item }} ]; then
-        cd {{ item }}
-        # get-test-deps - is part of beakerlib-libraries
-        get-test-deps -i .
-        if [ -f Makefile ] && command -p -v make >/dev/null 2>&1; then
-          make run
-        elif [ -f runtest.sh ]; then
-          /bin/sh -e ./runtest.sh
-        else
-          echo "FAIL don't know how to run test {{ item }}"
-        fi
-      else
-        echo "FAIL test {{ item }} does not appear to be a file or directory"
-      fi
+    script: ../files/beakerlib-test.sh {{ tenv_workdir }} {{ remote_artifacts }} {{ item }}
     with_items:
     - "{{ tests }}"
     - "{{ filter_tests }}"
@@ -83,23 +61,7 @@
 
   always:
   - name: Make the master tests summary log artifact
-    shell: |
-      log_file_name=$(echo {{ item }} | sed -e 's/\//-/g').log
-      logfile={{ remote_artifacts }}/${log_file_name}
-      status="FAIL"
-      if grep -q '\[ *FAIL *\]' "$logfile"; then
-        status="FAIL"
-      elif grep -q '\[ *PASS *\]' "$logfile"; then
-        status="PASS"
-      elif grep -q FAIL "$logfile"; then
-        status="FAIL"
-      elif grep -q PASS "$logfile"; then
-        status="PASS"
-      else
-        status="FAIL"
-      fi
-      echo "${status} {{ item }}" >> {{ remote_artifacts }}/test.log
-      mv ${logfile} {{ remote_artifacts }}/${status}_${log_file_name}
+    script: ../files/log-summary-artifact.sh {{ remote_artifacts }} {{ item }}
     with_items:
     - "{{ tests }}"
     - "{{ filter_tests }}"

