Bug 1285804 - Beakerlib loses content of $LOG_FILE variable when running Bash function with rlRun keyword.
Beakerlib loses content of $LOG_FILE variable when running Bash function with...
Status: CLOSED CURRENTRELEASE
Product: Fedora
Classification: Fedora
Component: beakerlib (Show other bugs)
24
Unspecified Unspecified
medium Severity unspecified
: ---
: ---
Assigned To: Dalibor Pospíšil
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-11-26 09:03 EST by Radovan Drazny
Modified: 2017-02-16 03:48 EST (History)
6 users (show)

See Also:
Fixed In Version: beakerlib-1.13-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-02-16 03:48:16 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Radovan Drazny 2015-11-26 09:03:02 EST
Description of problem:
When running a test which uses $LOG_FILE variable, if rlRun is used to call a Bash function, $LOG_FILE variable is deleted/not available inside this function. See the reproducer script.

Version-Release number of selected component (if applicable):
beakerlib-1.10-2.el7eso
beakerlib-1.11-1.el7

How reproducible:
Always

Steps to Reproduce:
Use following test script to reproduce the problem:
=================================
. /usr/bin/rhts-environment.sh
echo "rhts-env sourced, status = $?"
. /usr/lib/beakerlib/beakerlib.sh
echo "beakerlib sourced, status = $?"
set -o pipefail
echo "set -o pipefail, status = $?"


function some_func() {
    echo "Doing echo \$LOG_FILE"
    echo $LOG_FILE
    echo "Doing echo \$SOME_VAR"
    echo $SOME_VAR
}

rlJournalStart
rlPhaseStartTest
SOME_VAR="Some var string"
LOG_FILE="Test string"
echo "Running 'echo \$LOG_FILE' and 'echo \$SOME_VAR' outside the some_func()"
echo $LOG_FILE
echo $SOME_VAR
echo "Running some_func() with rlRun"
rlRun "some_func"
echo "Running some_func() without rlRun"
some_func
rlPhaseEnd
rlJournalEnd
rlJournalPrintText
=================================

Actual results:
Running provided script with beakerlib-1.10-2.el7eso gives following output (only relevant lines pasted):

<...>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Running 'echo $LOG_FILE' and 'echo $SOME_VAR' outside the some_func()
Test string
Some var string
Running some_func() with rlRun
:: [  BEGIN   ] :: Running 'some_func'
Doing echo $LOG_FILE
/dev/null
Doing echo $SOME_VAR
Some var string
:: [   PASS   ] :: Command 'some_func' (Expected 0, got 0)
Running some_func() without rlRun
Doing echo $LOG_FILE
Test string
Doing echo $SOME_VAR
Some var string
:: [ 08:50:08 ] :: JOURNAL XML: /var/tmp/beakerlib-TB2WcSz/journal.xml
:: [ 08:50:08 ] :: JOURNAL TXT: /var/tmp/beakerlib-TB2WcSz/journal.txt

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: TEST PROTOCOL
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   LOG    ] :: Package       : unknown
:: [   LOG    ] :: beakerlib RPM : beakerlib-1.10-2.el7eso
:: [   LOG    ] :: bl-redhat RPM : beakerlib-redhat-1-18.el7eso
:: [   LOG    ] :: Test started  : 2015-11-26 08:50:08 EST
:: [   LOG    ] :: Test finished : 2015-11-26 08:50:08 EST
:: [   LOG    ] :: Test name     : unknown
:: [   LOG    ] :: Distro:       : Red Hat Enterprise Linux Server release 7.2 (Maipo)
:: [   LOG    ] :: Hostname      : hp-dl360egen8-01.rhts.eng.bos.redhat.com
:: [   LOG    ] :: Architecture  : x86_64
<...>

Running provided script with beakerlib-1.10-2.el7eso gives following output (only relevant lines pasted):

<...>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Running 'echo $LOG_FILE' and 'echo $SOME_VAR' outside the some_func()
Test string
Some var string
Running some_func() with rlRun
:: [  BEGIN   ] :: Running 'some_func'
Doing echo $LOG_FILE

Doing echo $SOME_VAR
Some var string
:: [   PASS   ] :: Command 'some_func' (Expected 0, got 0)
Running some_func() without rlRun
Doing echo $LOG_FILE
Test string
Doing echo $SOME_VAR
Some var string
:: [ 08:54:01 ] :: JOURNAL XML: /var/tmp/beakerlib-uOqtv8b/journal.xml
:: [ 08:54:01 ] :: JOURNAL TXT: /var/tmp/beakerlib-uOqtv8b/journal.txt

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: [   LOG    ] :: TEST PROTOCOL
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [   LOG    ] :: Package       : unknown
:: [   LOG    ] :: beakerlib RPM : beakerlib-1.11-1.el7
:: [   LOG    ] :: bl-redhat RPM : beakerlib-redhat-1-18.el7eso
:: [   LOG    ] :: Test started  : 2015-11-26 08:54:01 EST
:: [   LOG    ] :: Test finished : 2015-11-26 08:54:01 EST
:: [   LOG    ] :: Test name     : unknown
:: [   LOG    ] :: Distro:       : Red Hat Enterprise Linux Server release 7.2 (Maipo)
:: [   LOG    ] :: Hostname      : hp-dl360egen8-01.rhts.eng.bos.redhat.com
:: [   LOG    ] :: Architecture  : x86_64
<...>

Expected results:
Script should keep content of $LOG_FILE variable in Bash function called by rlRun.
Comment 1 Dalibor Pospíšil 2015-11-30 06:12:18 EST
We have recently changed all the function variables to local ones but in this particular case the variables still collide with user's code.

I will prefix all the internal variables a put it into the documentation do future.

Until that please workaround this by using another variable name, e.g. 'LOG_FILE2' or 'log_file'.
Comment 2 Jan Kurik 2016-02-24 10:48:44 EST
This bug appears to have been reported against 'rawhide' during the Fedora 24 development cycle.
Changing version to '24'.

More information and reason for this action is here:
https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora24#Rawhide_Rebase
Comment 4 Jan Hutař 2016-09-25 15:40:25 EDT
Thank you Dalibor!
Comment 5 Dalibor Pospíšil 2016-09-30 03:43:24 EDT
yet another commit with documentation improvement https://git.fedorahosted.org/cgit/beakerlib.git/commit/?id=8cf7fb638e3f32325b8349941b18dc5e36e78923

Note You need to log in before you can comment on or make changes to this bug.