Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Fix bug in populating multiline env vars on reproduce
Browse files Browse the repository at this point in the history
The script to populate reproduce.sh is failing when populating
multi-line env vars. That is the case of the enable_plugin lines,
when more than one plugin is enabled.
Add this workaround to properly populate all needed settings.

Also add a test to ensure that reproduce method is working
as expected.

Change-Id: I5287098a47162321efadbde7d069fa2a4e7eabf7
  • Loading branch information
Yolanda Robla committed Mar 16, 2016
1 parent 15767df commit 589ca4f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ exec 0</dev/null
EOF

export | grep '\(DEVSTACK\|ZUUL\)' >> $WORKSPACE/logs/reproduce.sh
# first get all keys that match our filter and then output the whole line
# that will ensure that multi-line env vars are set properly
for KEY in $(printenv | grep '\(DEVSTACK\|ZUUL\)' | sed 's/\(.*\)=.*/\1/'); do
echo "declare -x ${KEY}=\"${!KEY}\"" >> $WORKSPACE/logs/reproduce.sh
done

cat >> $WORKSPACE/logs/reproduce.sh <<EOF
Expand Down
46 changes: 46 additions & 0 deletions test-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,51 @@ function test_call_hook_if_defined {
rm -rf $save_dir
}

# test that reproduce file is populated correctly
function test_reproduce {
# expected result
read -d '' EXPECTED_VARS << EOF
declare -x ZUUL_VAR="zuul-var"
declare -x DEVSTACK_VAR="devstack-var"
declare -x ZUUL_VAR_MULTILINE="zuul-var-setting1
zuul-var-setting2"
declare -x DEVSTACK_VAR_MULTILINE="devstack-var-setting1
devstack-var-setting2"
EOF

# prepare environment for test
WORKSPACE=.
export DEVSTACK_VAR=devstack-var
export DEVSTACK_VAR_MULTILINE="devstack-var-setting1
devstack-var-setting2"
export ZUUL_VAR=zuul-var
export ZUUL_VAR_MULTILINE="zuul-var-setting1
zuul-var-setting2"
JOB_NAME=test-job
mkdir $WORKSPACE/logs

# execute call and assert
reproduce

[[ -e $WORKSPACE/logs/reproduce.sh ]]
file_exists=$?
assert_equal $file_exists 0

result_expected=`cat $WORKSPACE/logs/reproduce.sh | grep "$EXPECTED_VARS"`
[[ ${#result_expected} -eq "0" ]]
assert_equal $? 1

# clean up environment
rm -rf $WORKSPACE/logs
rm -rf $WORKSPACE/workspace
unset WORKSPACE
unset DEVSTACK_VAR
unset DEVSTACK_VAR_MULTILINE
unset ZUUL_VAR
unset ZUUL_VAR_MULTILINE
unset JOB_NAME
}

# Run tests:
#set -o xtrace
test_branch_override
Expand All @@ -530,6 +575,7 @@ test_periodic_no_branch
test_two_on_master
test_workspace_branch_arg
test_call_hook_if_defined
test_reproduce

if [[ ! -z "$ERROR" ]]; then
echo
Expand Down

0 comments on commit 589ca4f

Please sign in to comment.