From 0a87ef43de688919d726d30c9b997c3196054900 Mon Sep 17 00:00:00 2001 From: Attila Fazekas Date: Tue, 22 Jul 2014 11:35:46 +0200 Subject: [PATCH] Sanity check in setup_workspace setup_workspace called with unquoted variables, which could lead to wrong argument moved into wrong variable, when one of the variables was empty string or contained space. This change quotas the parameters for setup_workspace, and also validates the OVERRIDE_ZUUL_BRANCH, GRENADE_OLD_BRANCH, GRENADE_NEW_BRANCH are not empty strings when they are used. Change-Id: I13d1458c9cebd83b0ca700b3153f6645b2931c0d --- devstack-vm-gate-wrap.sh | 6 +++--- functions.sh | 5 +++++ test-functions.sh | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/devstack-vm-gate-wrap.sh b/devstack-vm-gate-wrap.sh index d266c962..b8efdf86 100755 --- a/devstack-vm-gate-wrap.sh +++ b/devstack-vm-gate-wrap.sh @@ -343,16 +343,16 @@ tsfilter setup_host &> $WORKSPACE/logs/devstack-gate-setup-host.txt if [ -n "$DEVSTACK_GATE_GRENADE" ]; then echo "Setting up the new (migrate to) workspace" echo "... this takes 3 - 5 minutes (logs at logs/devstack-gate-setup-workspace-new.txt.gz)" - tsfilter setup_workspace $GRENADE_NEW_BRANCH $BASE/new copycache &> \ + tsfilter setup_workspace "$GRENADE_NEW_BRANCH" "$BASE/new" copycache &> \ $WORKSPACE/logs/devstack-gate-setup-workspace-new.txt echo "Setting up the old (migrate from) workspace ..." echo "... this takes 3 - 5 minutes (logs at logs/devstack-gate-setup-workspace-old.txt.gz)" - tsfilter setup_workspace $GRENADE_OLD_BRANCH $BASE/old &> \ + tsfilter setup_workspace "$GRENADE_OLD_BRANCH" "$BASE/old" &> \ $WORKSPACE/logs/devstack-gate-setup-workspace-old.txt else echo "Setting up the workspace" echo "... this takes 3 - 5 minutes (logs at logs/devstack-gate-setup-workspace-new.txt.gz)" - tsfilter setup_workspace $OVERRIDE_ZUUL_BRANCH $BASE/new &> \ + tsfilter setup_workspace "$OVERRIDE_ZUUL_BRANCH" "$BASE/new" &> \ $WORKSPACE/logs/devstack-gate-setup-workspace-new.txt fi diff --git a/functions.sh b/functions.sh index 70e766eb..9c39e97e 100644 --- a/functions.sh +++ b/functions.sh @@ -331,6 +331,11 @@ function setup_workspace { # Enabled detailed logging, since output of this function is redirected set -o xtrace + if [ -z "$base_branch" ]; then + echo "ERROR: setup_workspace: base_branch is an empty string!" >&2 + return 1 + fi + fix_disk_layout sudo mkdir -p $DEST diff --git a/test-functions.sh b/test-functions.sh index 1188e3fb..8dbf6ade 100755 --- a/test-functions.sh +++ b/test-functions.sh @@ -99,6 +99,16 @@ function assert_equal { fi } +function assert_raises { + local lineno=`caller 0 | awk '{print $1}'` + local function=`caller 0 | awk '{print $2}'` + eval "$@" &>/dev/null + if [[ $? -eq 0 ]]; then + ERROR=1 + echo "ERROR: \`\`$@\`\` returned OK instead of error in $function:L$lineno!" + fi +} + # Tests follow: function test_one_on_master { # devstack-gate master ZA @@ -386,6 +396,11 @@ function test_periodic { assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'stable/havana' } +# setup_workspace fails without argument +function test_workspace_branch_arg { + assert_raises setup_workspace +} + # Run tests: #set -o xtrace test_branch_override @@ -397,6 +412,7 @@ test_multi_branch_project_override test_one_on_master test_periodic test_two_on_master +test_workspace_branch_arg if [[ ! -z "$ERROR" ]]; then echo