Bug 1131934 - [RFE] add debug information on environment changes done in rlImport
Summary: [RFE] add debug information on environment changes done in rlImport
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: beakerlib
Version: 20
Hardware: Unspecified
OS: Unspecified
medium
unspecified
Target Milestone: ---
Assignee: Dalibor Pospíšil
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: Fedora-beakerlib-1.10 1136362
TreeView+ depends on / blocked
 
Reported: 2014-08-20 10:59 UTC by Martin Kyral
Modified: 2014-12-12 14:51 UTC (History)
4 users (show)

Fixed In Version: beakerlib-1.10-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-12-12 14:48:00 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
proposed patch (645 bytes, patch)
2014-08-20 10:59 UTC, Martin Kyral
no flags Details | Diff

Description Martin Kyral 2014-08-20 10:59:09 UTC
Created attachment 928760 [details]
proposed patch

Description of problem:
A request was raised for a rlImport feature allowing the beaker library developer or user to see what actual changes to the environment are done within the rlImport function (added functions, variables, value changes...).
I suppose such an information has its value when running in debug mode (DEBUG=1).


Version-Release number of selected component (if applicable):
1.9-3.fc20

Additional info:
Patch attached.

Comment 1 Martin Kyral 2014-08-20 11:01:32 UTC
$ DEBUG=1 make run
test -x runtest.sh || chmod a+x runtest.sh                                                                                                                                                                            
./runtest.sh                                                                                                                                                                                                          
ln: cannot remove ‘/mnt/testarea/current.log’: Operation not permitted                                                                                                                                                
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlJournalStart: Journal successfully initilized in /var/tmp/beakerlib-SwdrXO2                                                                                                       
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlJournalStart: Basic cleanup infrastructure successfully initialized                                                                                                               
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlJournalStart: Not running in test watcher or setup failed.                                                                                                                        
:: [ 11:38:52 ] :: [ DEBUG   ] :: rljAddPhase: Phase Setup started                                                                                                                                                    
                                                                                                                                                                                                                      
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::                                                                                                                                      
:: [   LOG    ] :: Setup                                                                                                                                                                                              
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::                                                                                                                                      
                                                                                                                                                                                                                      
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlRun: Running command: rlImport perl/subpackage                                                                                                                                    
:: [  BEGIN   ] :: Running 'rlImport perl/subpackage'                                                                                                                                                                 
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: WORKLIST [perl/subpackage]                                                                                                                                                
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: Searching for library perl/subpackage                                                                                                                                     
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: Looking if we got BEAKERLIB_LIBRARY_PATH                                                                                                                                  
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: No BEAKERLIB_LIBRARY_PATH set: trying default                                                                                                                             
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: Trying root: [/mnt/tests]                                                                                                                                                 
:: [ 11:38:52 ] :: [ INFO    ] :: rlImport: Found 'perl/subpackage' in /mnt/tests                                                                                                                                     
:: [ 11:38:52 ] :: [ INFO    ] :: rlImport: Will try to import perl/subpackage from /mnt/tests/CoreOS/perl/Library/subpackage/lib.sh
:: [ 11:38:52 ] :: [ DEBUG   ] :: rlImport: Collecting dependencies for library perl/subpackage
:: [ 11:38:53 ] :: [ DEBUG   ] :: rlImport: WORKLIST [ ]
:: [ 11:38:53 ] :: [ DEBUG   ] :: rlImport: LIBS_TO_LOAD='perl/subpackage '
:: [ 11:38:53 ] :: [ DEBUG   ] :: rlImport: Constructed verifier function: perlsubLibraryLoaded
:: [ 11:38:53 ] :: [ DEBUG   ] :: Library perl/subpackage available
19a20,21
> COMPONENT=perl
> COMPONENT_hash=7065726c
48a51
> IMPORTS_varname=__INTERNAL_LIBRARY_IMPORTS_C7065726c_L7375627061636b616765
62a66,71
> LIBDIR=/mnt/tests/CoreOS/perl/Library/subpackage
> LIBFILE=/mnt/tests/CoreOS/perl/Library/subpackage/lib.sh
> LIBRARY=subpackage
> LIBRARY_hash=7375627061636b616765
> LIBS_TO_LOAD='perl/subpackage '
> LOCATIONS_varname=__INTERNAL_LIBRARY_LOCATIONS_C7065726c_L7375627061636b616765
70a80
> NEWSET=/tmp/tmp.FIcklEj75V
80a91,92
> PREFIX=perlsub
> PROCESSING=
90a103
> RESULT=0
106a120
> VERIFIER=perlsubLibraryLoaded
108a123
> WORKLIST=
122c137
< _=OLDSET=/tmp/tmp.1QzTrEJ5Xf
---
> _=NEWSET=/tmp/tmp.FIcklEj75V
128a144,145
> __INTERNAL_LIBRARY_IMPORTS_C7065726c_L7375627061636b616765=PASS
> __INTERNAL_LIBRARY_LOCATIONS_C7065726c_L7375627061636b616765=/mnt/tests/CoreOS/perl/Library/subpackage
145a163
> library=perl/subpackage
790a809,915
> }
> perlsubAssertModuleOrigin () 
> { 
>     local perlbin=${PERL_BIN:-perl};
>     local module=$1;
>     shift;
>     local modfile=$(perlsubGetModulePath $module);
>     local PKGS=$@;
>     [ $# -eq 0 ] && PKGS="$PACKAGES $REQUIRES $COLLECTIONS";
>     local status=1;
>     local pkg="";
>     local modpackage=$(rpm -qf $modfile);
>     local pkg;
>     for pkg in $PKGS;
>     do
>         local TESTED_RPM=$(rpm -q $pkg) &>/dev/null && if [ "$TESTED_RPM" = "$modpackage" ]; then
>             status=0;
>             echo $TESTED_RPM;
>             break;
>         fi;
>     done;
>     rlAssert0 "Module $module should belong to one rpm of: $PKGS" $status;
>     return $?
> }
> perlsubGetCommonPrefix () 
> { 
>     local PKGS=$PACKAGES;
>     [ $# -gt 0 ] && PKGS="$@";
>     rpm -qf --queryformat %{name} $(which perl)
> }
> perlsubGetModulePath () 
> { 
>     if [ $# -ne 1 ]; then
>         echo "Usage: perlsubGetModulePath Module" 1>&2;
>         return 1;
>     fi;
>     local perlbin=${PERL_BIN:-perl};
>     local module=$1;
>     shift;
>     perlsub_update_special_params $module;
>     local modpath="$( echo $module | sed 's/::/\//g').pm";
>     local printscript="$perlsub_use_module; print \$INC{\"$modpath\"}";
>     local script=$(mktemp);
>     echo $printscript > $script;
>     local modfile=$($perlbin -M$module $script);
>     local RC=$?;
>     rm $script;
>     [ $RC -ne 0 ] && return 1;
>     echo $modfile;
>     return 0
> }
> perlsubLibraryLoaded () 
> { 
>     local perlbin=${PERL_BIN:-perl};
>     if which $perlbin &>/dev/null; then
>         rlLogDebug "Library perl/subpackage available";
>         return 0;
>     else
>         rlLogError "$perlbin not found";
>         return 1;
>     fi
> }
> perlsub_update_special_params () 
> { 
>     local module="$1";
>     case "$1" in 
>         'CPANPLUS::Dist::MM')
>             perlsub_use_module='use CPANPLUS; use CPANPLUS::Dist::MM'
>         ;;
>         'CPANPLUS::Internals::Constants::Report')
>             perlsub_use_module='use CPANPLUS; use CPANPLUS::Internals::Constants::Report'
>         ;;
>         'Math::BigInt::CalcEmu')
>             perlsub_use_module='use Math::BigInt; use Math::BigInt::CalcEmu'
>         ;;
>         'O')
>             perlsub_use_module='use O (Deparse)'
>         ;;
>         'Pod::Simple::Debug')
>             perlsub_use_module='use Pod::Simple::Debug (0)'
>         ;;
>         'autouse')
>             perlsub_use_module='use autouse (Carp => qw(carp))'
>         ;;
>         'encoding')
>             perlsub_use_module='use encoding q{utf8}'
>         ;;
>         'feature')
>             perlsub_use_module='use feature q{say}'
>         ;;
>         'filetest')
>             perlsub_use_module='use filetest q{access}'
>         ;;
>         'if')
>             perlsub_use_module='use if 0, q{strict}'
>         ;;
>         'open')
>             perlsub_use_module='use open q{:locale}'
>         ;;
>         'sort')
>             perlsub_use_module='use sort q{stable}'
>         ;;
>         *)
>             perlsub_use_module="use $module"
>         ;;
>     esac;
>     export perlsub_use_module
:: [ 11:38:53 ] :: [ DEBUG   ] :: rlRun: command = 'rlImport perl/subpackage'; exitcode = 0; expected = 0
:: [ 11:38:53 ] :: [ DEBUG   ] :: rlRun: Command finished with exit code: 0, expected: 0
:: [   PASS   ] :: Command 'rlImport perl/subpackage' (Expected 0, got 0)

Comment 2 David Kutálek 2014-08-20 13:58:05 UTC
Thanks for initial patch. That will be really useful for debugging cases when library touches some variables it shouldn't, really affecting library user (test).

Do you think we could possibly go even further, asserting that all added parameters (minus exceptions) are prefixed with prefix of given library?

The idea was to be warned when library author touches/creates variables not prefixed (eg. by mistake), possibly affecting library consumer (a test). That would be very user-friendly for library consumers.

Comment 3 Dalibor Pospíšil 2014-08-27 12:16:23 UTC
I like the idea of diff of set output. I would include just name of functions in DEBUG=1. May be we would like to see also functions body wich I would print for DEBUG=2 and higher. I know that there is no support for multilevel debugging but we could also consider this feature.

Comment 4 Dalibor Pospíšil 2014-08-27 12:22:30 UTC
(In reply to David Kutálek from comment #2)
> Do you think we could possibly go even further, asserting that all added
> parameters (minus exceptions) are prefixed with prefix of given library?
As prefix is only recommendation and its enforcing is nearly impossible I would not implement this.

More over sometimes it is useful to misuse other prefix like for workaround or so.

Comment 5 David Kutálek 2014-08-27 12:51:09 UTC
(In reply to Dalibor Pospíšil from comment #4)
> (In reply to David Kutálek from comment #2)
> > Do you think we could possibly go even further, asserting that all added
> > parameters (minus exceptions) are prefixed with prefix of given library?
> As prefix is only recommendation and its enforcing is nearly impossible I
> would not implement this.

Though we cannot enforce, monitor and raise warning still makes sense to me so we can see and possibly act upon non-standard behaviour.

> More over sometimes it is useful to misuse other prefix like for workaround
> or so.

If workaround, it would be nice to get warnings so you know you should fix and remove workaround. If something permanent, mark it in library as needed/expected, so that warning mechanism leave this out.

Comment 6 Dalibor Pospíšil 2014-08-27 13:05:07 UTC
(In reply to David Kutálek from comment #5)
> Though we cannot enforce, monitor and raise warning still makes sense to me
> so we can see and possibly act upon non-standard behaviour.

Please file separate bug for this as it is a bit different topic which can be solved with different prio.

Comment 7 Dalibor Pospíšil 2014-09-19 22:52:26 UTC
I have made the behaviour different for DEBUG=1, DEBUG=2, and DEBUG=3.
Changed variables are printed the same way in all DEBUG levels. There is a difference for functions. First level means that only removed, added and changed function names are printed. Second level adds body of changed functions. Third level adds also body of removed and added functions.

fixed by https://git.fedorahosted.org/cgit/beakerlib.git/commit/?id=792b4cdaee6b7daa12b1ac5319c4ad05f56fa639


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