#370 add support to archive logs using beakerlib functions
Merged 4 years ago by astepano. Opened 4 years ago by bgoncalv.
bgoncalv/standard-test-roles beakerlib-role  into  master

@@ -44,7 +44,7 @@ 

  while [[ $# -gt 0 ]]; do

      case "$1" in

          -t|--test)

-             STR_BKR_TEST="$2"

+             export STR_BKR_TEST="$2"

              shift 2

              ;;

          -w|--workdir)
@@ -52,7 +52,7 @@ 

              shift 2

              ;;

          -a|--artifactsdir)

-             STR_ARTIFACTS_DIR="$2"

+             export STR_ARTIFACTS_DIR="$2"

              shift 2

              ;;

          --timeout)

@@ -0,0 +1,23 @@ 

+ #!/usr/bin/bash -e

+ 

+ # Purpose: Script used by beakerlib role to save a file to standard-test-roles artifacts

+ # the file is saved under test case name

+ #

+ # The script expects $STR_BKR_TEST and $STR_ARTIFACTS_DIR variables to be set

+ # This script should be called passing the file as parameter: str-beakerlib-submit-log <$file>

+ # File path could be full path or relative path to where beakerlib functions (rlFileSubmit and rlBundleLogs) are called

+ 

+ source /usr/share/beakerlib/beakerlib.sh

+ 

+ if [ -z "$STR_BKR_TEST" ] || [ -z "$STR_ARTIFACTS_DIR" ]; then

+     rlLogError "STR_BKR_TEST and STR_ARTIFACTS_DIR are required by $0"

+     exit 1

+ fi

+ 

+ rlLogInfo "Copying $2 to ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}"

+ 

+ if [[ ! -d ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST} ]];then

+     mkdir -p ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}

+ fi

+ 

+ cp -f "${2}" ${STR_ARTIFACTS_DIR}/${STR_BKR_TEST}/

@@ -49,6 +49,7 @@ 

    with_fileglob:

      - "rhts-environment.sh"

      - "rhts-run-simple-test"

+     - "str-beakerlib-submit-log"

  

  - block:

    - name: Run beakerlib tests
@@ -60,7 +61,10 @@ 

      - "{{ tests }}"

      - "{{ filter_tests }}"

      environment:

-       BEAKERLIB_LIBRARY_PATH: "{{ beakerlib_libraries_path }}"

+       - BEAKERLIB_LIBRARY_PATH: "{{ beakerlib_libraries_path }}"

+       # BEAKERLIB_COMMAND_SUBMIT_LOG is a variable used to redefine the script used to store files

+       # when rlFileSubmit or rlBundleLogs are called

+       - BEAKERLIB_COMMAND_SUBMIT_LOG: str-beakerlib-submit-log

  

    always:

    # Can't go in block. See

file modified
+20
@@ -66,3 +66,23 @@ 

    - import_tasks: shared-tasks/verify_error_test.yml

    - import_tasks: shared-tasks/artifacts_test_env.yml

    - import_tasks: shared-tasks/artifacts_test_runner.yml

+ 

+ # Make sure the beakerlib functions to save logs work well

+ - hosts: localhost

+   tags:

+   - atomic

+   - classic

+   - container

+   roles:

+   - role: standard-test-beakerlib

+     tests:

+     - test-beakerlib-submit-log

+   tasks:

+   - name: "Check if {{artifacts}}/test-beakerlib-submit-log/test1.log was created properly on test runner"

+     shell: "ls {{artifacts}}/test-beakerlib-submit-log/test1.log"

+     delegate_to: localhost

+   - name: "Check if {{artifacts}}/test-beakerlib-submit-log/tmp-tests.tar.gz was created properly on test runner"

+     shell: "ls {{artifacts}}/test-beakerlib-submit-log/tmp-tests.tar.gz"

+     delegate_to: localhost

+   - import_tasks: shared-tasks/artifacts_test_env.yml

+   - import_tasks: shared-tasks/artifacts_test_runner.yml

@@ -0,0 +1,17 @@ 

+ #!/bin/bash

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="beakerlib"

+ 

+ rlJournalStart

+     rlPhaseStartTest "beakerlbi submit logs test"

+         # Create some files and then store them on artifacts

+         rlRun "echo test1 > test1.log"

+         rlRun "echo test2 > test2.log"

+         rlFileSubmit test1.log

+         rlBundleLogs tests test1.log test2.log

Test doesn't check whether these submits actually submit the file(s). Nothing checks return codes (you could wrap the commands with rlRun) nor whether the files are actually present at the backup location.

for the test it is transparent where STR artifacts are stored, that's why we make sure the logs are actually saved on test runner.

https://pagure.io/standard-test-roles/pull-request/370#_4__17 :)

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

beakerlib provides rlBundleLogs and rlFileSubmit functions to store files

Add support so the usage of this function will save the files to artifacts

Related to https://pagure.io/standard-test-roles/issue/35

https://github.com/beakerlib/beakerlib/wiki/man

I would add some header with info:
Purpos: store any file at path.....
This scripts expects 2 env vars: <names of these vars>
This script should be called in form: str-beakerlib-submit-log <SOMETHING>
Where <Something> - is path to ? What kind of path full or relative according to?

BEAKERLIB_COMMAND_SUBMIT_LOG - is absent in current master, who will use this VAR ? Maybe add this explanation to this file?

Plus add a note that <SOMETHING> must be file. (not directory).

rebased onto ccf4f02

4 years ago

@bgoncalv thank you! looks much better! Let's merge when CI passes.

Test doesn't check whether these submits actually submit the file(s). Nothing checks return codes (you could wrap the commands with rlRun) nor whether the files are actually present at the backup location.

for the test it is transparent where STR artifacts are stored, that's why we make sure the logs are actually saved on test runner.

https://pagure.io/standard-test-roles/pull-request/370#_4__17 :)

for the test it is transparent where STR artifacts are stored, that's why we make sure the logs are actually saved on test runner.
https://pagure.io/standard-test-roles/pull-request/370#_4__17 :)

I see. In that case just the wrapping in rlRun to make sure commands returned 0.

After discussion with @bgoncalv it seems that integrated test will fail anyway, on the previous step. @bgoncalv right? @jheger if you insist on rewriting test case please let me know.

Commit 6a39c53 fixes this pull-request

Pull-Request has been merged by astepano

4 years ago

Pull-Request has been merged by astepano

4 years ago