Bug 1285804 - Beakerlib loses content of $LOG_FILE variable when running Bash function with rlRun keyword.
Summary: Beakerlib loses content of $LOG_FILE variable when running Bash function with...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: beakerlib
Version: 24
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: ---
Assignee: Dalibor Pospíšil
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-11-26 14:03 UTC by Radovan Drazny
Modified: 2017-02-16 08:48 UTC (History)
6 users (show)

Fixed In Version: beakerlib-1.13-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-02-16 08:48:16 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Radovan Drazny 2015-11-26 14:03:02 UTC
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 11:12:18 UTC
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 15:48:44 UTC
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 19:40:25 UTC
Thank you Dalibor!

Comment 5 Dalibor Pospíšil 2016-09-30 07:43:24 UTC
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.