Enable scenario input for engine verify jobs

There will be cases where we need to specify the scenario to
verify the engine with. Most obvious example to this is while
adding newly implemented scenarios into sdf.yml.

Change-Id: Ia60ac75a9f65f9c29efd9804095f15e2338f9be9
diff --git a/jjb/cloud-infra/cloud-infra-deploy.sh b/jjb/cloud-infra/cloud-infra-deploy.sh
index 51ae5a3..1a3ebdd 100644
--- a/jjb/cloud-infra/cloud-infra-deploy.sh
+++ b/jjb/cloud-infra/cloud-infra-deploy.sh
@@ -47,6 +47,6 @@
 
 # execute cloud engine deploy.sh script
 cd $WORKSPACE
-./engine/deploy.sh -d kubespray -s $DEPLOY_SCENARIO -p $PDF -i $IDF -c
+./engine/deploy.sh -d $INSTALLER_TYPE -s $DEPLOY_SCENARIO -p $PDF -i $IDF -c
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/cloud-infra-verify-engine.yaml b/jjb/cloud-infra/cloud-infra-verify-engine.yaml
index 61a6eac..25e55dd 100644
--- a/jjb/cloud-infra/cloud-infra-verify-engine.yaml
+++ b/jjb/cloud-infra/cloud-infra-verify-engine.yaml
@@ -120,10 +120,6 @@
           default: '{dib_os_element}'
           description: 'DIB OS Element to use for building the deployment image to provision target nodes with'
       - string:
-          name: DEPLOY_SCENARIO
-          default: 'k8-calico-nofeature'
-          description: 'Scenario to deploy and test'
-      - string:
           name: TEST_SUITE
           default: 'healthcheck'
           description: 'Test suite to run'
@@ -166,6 +162,7 @@
           files: '**'
 
     builders:
+      - 'cloud-infra-determine-scenario-macro'
       - multijob:
           name: deploy
           condition: SUCCESSFUL
@@ -179,7 +176,6 @@
                 IPA_DIB_OS_ELEMENT=$IPA_DIB_OS_ELEMENT
                 DIB_OS_RELEASE=$DIB_OS_RELEASE
                 DIB_OS_ELEMENT=$DIB_OS_ELEMENT
-                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
                 CLEANUP=$CLEANUP
                 GERRIT_PROJECT=$GERRIT_PROJECT
                 GERRIT_BRANCH=$GERRIT_BRANCH
@@ -202,7 +198,6 @@
                 IPA_DIB_OS_ELEMENT=$IPA_DIB_OS_ELEMENT
                 DIB_OS_RELEASE=$DIB_OS_RELEASE
                 DIB_OS_ELEMENT=$DIB_OS_ELEMENT
-                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
                 TEST_SUITE=$TEST_SUITE
                 CLEANUP=$CLEANUP
                 GERRIT_PROJECT=$GERRIT_PROJECT
@@ -253,10 +248,6 @@
           default: 'ubuntu-minimal'
           description: 'DIB OS Element to use for building the deployment image to provision target nodes with. Overriden by upstream job.'
       - string:
-          name: DEPLOY_SCENARIO
-          default: 'k8-calico-nofeature'
-          description: 'Scenario to deploy and test'
-      - string:
           name: TEST_FW
           default: '{phase}'
           description: 'Test framework to use'
@@ -284,6 +275,7 @@
           refspec: $GERRIT_REFSPEC
 
     builders:
+      - 'cloud-infra-determine-scenario-macro'
       - 'cloud-infra-{phase}-macro'
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/determine-scenario.sh b/jjb/cloud-infra/determine-scenario.sh
index 8207a1e..fffe5c9 100644
--- a/jjb/cloud-infra/determine-scenario.sh
+++ b/jjb/cloud-infra/determine-scenario.sh
@@ -43,10 +43,10 @@
   if [[ "$COMMIT_MESSAGE" =~ "deploy-scenario:" && "$COMMIT_MESSAGE" =~ "installer-type:" ]]; then
     export INSTALLER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^installer-type:' | cut -d":" -f2 | sed 's/\s*//g')
     export DEPLOY_SCENARIO=$(echo "$COMMIT_MESSAGE" | grep '^deploy-scenario:' | cut -d":" -f2 | sed 's/\s*//g')
+    write_change_metadata
   else
     echo "Info: Installer type or deploy scenario is not specified."
     echo "Info: Falling back to programmatically determining them."
-    determine_scenario
   fi
 }
 
@@ -55,33 +55,46 @@
 # touched.
 # TODO: this is not implented yet.
 function determine_scenario() {
+  # for infra/engine repo, we set INSTALLER_TYPE and DEPLOY_SCENARIO to their defaults
   echo "Info: Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
-  cd $WORKSPACE
-  COMMIT_MESSAGE=$(git show -s --format=%B)
-  echo "Info: Not implemented!"
-  exit 1
+  if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then
+    echo "Info: Setting INSTALLER_TYPE and DEPLOY_SCENARIO to defaults for project $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
+    export INSTALLER_TYPE=kubespray
+    export DEPLOY_SCENARIO=k8-calico-nofeature
+    write_change_metadata
+  else
+    cd $WORKSPACE
+    COMMIT_MESSAGE=$(git show -s --format=%B)
+    echo "Info: Not implemented!"
+    exit 1
+  fi
 }
 
-echo "Info: Determining the impacted scenario and used installer"
-
-declare -a DEPLOY_SCENARIO
-declare -a INSTALLER_TYPE
-export PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT
-
-override_installer_scenario
-
-echo "Info: Writing change metadata to $WORKSPACE/change.properties"
-cat << EOF > $WORKSPACE/change.properties
+function write_change_metadata() {
+  echo "Info: Writing change metadata to $WORKSPACE/change.properties"
+  cat << EOF > $WORKSPACE/change.properties
 PROJECT_GIT_URL=$GIT_BASE_HTTPS/$GERRIT_PROJECT
-DEPLOY_SCENARIO=$DEPLOY_SCENARIO
 INSTALLER_TYPE=$INSTALLER_TYPE
+DEPLOY_SCENARIO=$DEPLOY_SCENARIO
 GERRIT_PATCHSET_REVISION=$GERRIT_PATCHSET_REVISION
 GERRIT_REFSPEC=$GERRIT_REFSPEC
 EOF
 
-echo "Info: Content of change.properties"
-echo "-------------------------------------------------------------------------"
-cat $WORKSPACE/change.properties
-echo "-------------------------------------------------------------------------"
+  echo "Info: Content of change.properties"
+  echo "-------------------------------------------------------------------------"
+  cat $WORKSPACE/change.properties
+  echo "-------------------------------------------------------------------------"
+
+  # need to exit here to ensure we don't go further while determining scenario
+  exit 0
+}
+
+echo "Info: Determining the impacted scenario and used installer"
+
+declare -a INSTALLER_TYPE
+declare -a DEPLOY_SCENARIO
+
+override_installer_scenario
+determine_scenario
 
 # vim: set ts=2 sw=2 expandtab: