From 52c97ccb8c4380f4890e8f71c511603197e81457 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 22 Jun 2015 15:00:34 -0400 Subject: [PATCH] Fix the setup_workspace to handle missing ZUUL_BRANCH This commit adds logic to the setup_workspace function to be able to handle the case where the var ZUUL_BRANCH isn't set. This is what apparently happens during periodic jobs and causes those to fail. If ZUUL_BRANCH isn't set we just use the fallback zuul ref which is what the expected behavior would be if the function didn't explode. Change-Id: I77b98b8a8d8602da0092a5250cc0ce49de9215db --- functions.sh | 7 ++++++- test-functions.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 9fdaa7a3..fb94c63e 100644 --- a/functions.sh +++ b/functions.sh @@ -345,7 +345,12 @@ function setup_project { fi # Try the specified branch before the ZUUL_BRANCH. - OVERRIDE_ZUUL_REF=$(echo $ZUUL_REF | sed -e "s,$ZUUL_BRANCH,$branch,") + if [[ ! -z $ZUUL_BRANCH ]]; then + OVERRIDE_ZUUL_REF=$(echo $ZUUL_REF | sed -e "s,$ZUUL_BRANCH,$branch,") + else + OVERRIDE_ZUUL_REF="" + fi + # Update git remotes git_remote_update diff --git a/test-functions.sh b/test-functions.sh index 92dd60c1..3f181c47 100755 --- a/test-functions.sh +++ b/test-functions.sh @@ -398,6 +398,19 @@ function test_periodic { assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'stable/havana' } +# Run setup_project without setting a ZUUL_BRANCH which is how a subset of +# periodic jobs operate +function test_periodic_no_branch { + + declare -A TEST_GIT_CHECKOUTS + declare -A TEST_ZUUL_REF + local ZUUL_PROJECT='openstack/glance' + + setup_project openstack/glance 'master' + + assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'master' +} + # setup_workspace fails without argument function test_workspace_branch_arg { assert_raises setup_workspace @@ -466,6 +479,7 @@ test_multi_branch_on_stable test_multi_branch_project_override test_one_on_master test_periodic +test_periodic_no_branch test_two_on_master test_workspace_branch_arg test_call_hook_if_defined