#297 standard-test-beakerlib: Move beakerlib bash scripts to own file
Closed 4 years ago by astepano. Opened 5 years ago by ssahani.
ssahani/standard-test-roles str-scripts  into  master

@@ -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

@@ -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}

@@ -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 }}

Is there a way to drop relative path? Does Ansible support it?

      with_items:

None I know of

      - "{{ 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 }}"

rebased onto 7a59ec2a8aed01fe8bddcaaf5232d390a6760d0b

5 years ago

rebased onto e8b08ada9da3e993abbc83ffd452af15f0703c1f

5 years ago

/usr/bin/beakerlib-test.sh

where this path comes from?

/usr/bin/beakerlib-test.sh

where this path comes from?

It's copied to
/usr/bin like others see main.yml

we shouldn't copy files from to /usr/bin/

These files are not packaged and it might cause conflicts, or unexpected behaviour of a test.

You can use script module instead, it does the same thing internally: copies the script from localhost to the target machine and runs it, but it uses ansible's temporary folders to perform this task, and doesn't interfere with system files.

rebased onto f0efc96f25191a5371dcdcb61d0a156aed8230ff

5 years ago

Why do use this form of shebang?
It make sense for python but, even now for python it is deprecated and not recommended form.

I would put here some information. Like: purpose of this script, where it is used. Input required/expected values. Output value. Exit code. Files that are produced.

Is there a way to drop relative path? Does Ansible support it?

It's nothing doing something new . Just separates from the embedded ansible code. Feel free to suggest.

rebased onto 162d9ae

5 years ago

Pull-Request has been closed by astepano

4 years ago