Merge "Add INTERACTIVE flag to upgrade pipelines"
diff --git a/openstack-compute-upgrade.groovy b/openstack-compute-upgrade.groovy
index a59fc08..2984b55 100644
--- a/openstack-compute-upgrade.groovy
+++ b/openstack-compute-upgrade.groovy
@@ -7,6 +7,7 @@
  *   TARGET_SERVERS             Salt compound target to match nodes to be updated [*, G@osfamily:debian].
  *   TARGET_SUBSET_TEST         Number of nodes to list package updates, empty string means all targetted nodes.
  *   TARGET_SUBSET_LIVE         Number of selected nodes to live apply selected package update.
+ *   INTERACTIVE                Ask interactive questions during pipeline run (bool).
  *
 **/
 
@@ -96,8 +97,10 @@
                 salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
             }
 
-            stage('Confirm upgrade on sample nodes') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on sample nodes') {
                 input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?"
+              }
             }
 
             stage("Add new repos on sample nodes") {
@@ -136,8 +139,10 @@
                 }
             }
 
-            stage('Confirm upgrade on sample') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on sample') {
                 input message: "Please verify if there are packages that it wants to downgrade. If so, execute apt-cache policy on them and verify if everything is fine. Do you want to continue with upgrade?"
+              }
             }
 
             command = "cmd.run"
@@ -180,10 +185,12 @@
                 }
             }
 
-            stage('Confirm upgrade on all targeted nodes') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on all targeted nodes') {
                 timeout(time: 2, unit: 'HOURS') {
                    input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
                 }
+              }
             }
 
             stage("Add new repos on all targeted nodes") {
diff --git a/openstack-control-upgrade.groovy b/openstack-control-upgrade.groovy
index d306e34..89b5e77 100644
--- a/openstack-control-upgrade.groovy
+++ b/openstack-control-upgrade.groovy
@@ -9,6 +9,7 @@
  *   STAGE_ROLLBACK_UPGRADE             Run rollback upgrade stage (bool)
  *   SKIP_VM_RELAUNCH                   Set to true if vms should not be recreated (bool)
  *   OPERATING_SYSTEM_RELEASE_UPGRADE   Set to true if operating system of vms should be upgraded to newer release (bool)
+ *   INTERACTIVE                        Ask interactive questions during pipeline run (bool).
  *
 **/
 
@@ -195,10 +196,10 @@
 
     salt.cmdRun(pepperEnv, "${test_upgrade_node}*", '. /root/keystonercv3; openstack service list; openstack image list; openstack flavor list; openstack compute service list; openstack server list; openstack network list; openstack volume list; openstack orchestration service list')
 
-    if (STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
-        stage('Ask for manual confirmation') {
-            input message: "Do you want to continue with upgrade?"
-        }
+    if (INTERACTIVE.toBoolean() && STAGE_TEST_UPGRADE.toBoolean() == true && STAGE_REAL_UPGRADE.toBoolean() == true) {
+      stage('Ask for manual confirmation') {
+        input message: "Do you want to continue with upgrade?"
+      }
     }
 }
 
@@ -303,8 +304,12 @@
         stopServices(pepperEnv, proxy_node, proxy_general_target, 'prx')
         stopServices(pepperEnv, control_node, control_general_target, 'ctl')
         salt.printSaltCommandResult(out)
-        if (out.toString().contains("dpkg returned an error code")) {
-            input message: "Apt dist-upgrade failed, please fix it manually and then click on proceed. If unable to fix it, click on abort and run the rollback stage."
+        if (out.toString().contains("dpkg returned an error code")){
+            if (INTERACTIVE.toBoolean()) {
+              input message: "Apt dist-upgrade failed, please fix it manually and then click on proceed. If unable to fix it, click on abort and run the rollback stage."
+            } else {
+              error("Apt dist-upgrade failed. And interactive mode was disabled, failing...")
+            }
         }
         // run base states
         try {
@@ -355,10 +360,14 @@
         retryStateRun(pepperEnv, control_general_target, 'heat')
     } catch (Exception e) {
         errorOccured = true
-        if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
-            input message: "Some states that require syncdb failed. Please check the reason.Click proceed only if you want to restore database into it's pre-upgrade state. If you want restore production database and also the VMs into its pre-upgrade state please click on abort and run the rollback stage."
+        if (INTERACTIVE.toBoolean()){
+          if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
+              input message: "Some states that require syncdb failed. Please check the reason. Click proceed only if you want to restore database into it's pre-upgrade state. If you want restore production database and also the VMs into its pre-upgrade state please click on abort and run the rollback stage."
+          } else {
+              input message: "Some states that require syncdb failed. Please check the reason and click proceed only if you want to restore database into it's pre-upgrade state. Otherwise, click abort."
+          }
         } else {
-            input message: "Some states that require syncdb failed. Please check the reason and click proceed only if you want to restore database into it's pre-upgrade state. Otherwise, click abort."
+          error("Stage Real control upgrade failed. And interactive mode was disabled, failing...")
         }
         openstack.restoreGaleraDb(pepperEnv)
         common.errorMsg("Stage Real control upgrade failed")
@@ -420,7 +429,9 @@
 
         /*
         if (OPERATING_SYSTEM_RELEASE_UPGRADE.toBoolean() == false) {
-            input message: "Please verify if the control upgrade was successful! If so, by clicking proceed the original VMs disk images will be backed up and snapshot will be merged to the upgraded VMs which will finalize the upgrade procedure"
+            if (INTERACTIVE.toBoolean()){
+              input message: "Please verify if the control upgrade was successful! If so, by clicking proceed the original VMs disk images will be backed up and snapshot will be merged to the upgraded VMs which will finalize the upgrade procedure"
+            }
             node_count = 1
             for (t in proxy_target_hosts) {
                 def target = salt.stripDomainName(t)
@@ -445,8 +456,10 @@
                 virsh.liveSnapshotMerge(pepperEnv, nodeProvider, target, snapshotName)
                 node_count++
             }
-            input message: "Please scroll up and look for red highlighted messages containing 'virsh blockcommit' string.
-            If there are any fix it manually.  Otherwise click on proceed."
+            if (INTERACTIVE.toBoolean()){
+              input message: "Please scroll up and look for red highlighted messages containing 'virsh blockcommit' string.
+              If there are any fix it manually.  Otherwise click on proceed."
+            }
         }
         */
     }
@@ -548,7 +561,7 @@
                 vcpRealUpgrade(pepperEnv)
             }
 
-            if (STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
+            if (INTERACTIVE.toBoolean() && STAGE_REAL_UPGRADE.toBoolean() == true && STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
                 stage('Ask for manual confirmation') {
                     input message: "Please verify if the control upgrade was successful. If it did not succeed, in the worst scenario, you can click on proceed to continue with control-upgrade-rollback. Do you want to continue with the rollback?"
                 }
@@ -557,11 +570,13 @@
 
         if (STAGE_ROLLBACK_UPGRADE.toBoolean() == true) {
             stage('Rollback upgrade') {
-                stage('Ask for manual confirmation') {
+                if (INTERACTIVE.toBoolean()){
+                  stage('Ask for manual confirmation') {
                     input message: "Before rollback please check the documentation for reclass model changes. Do you really want to continue with the rollback?"
+                  }
                 }
                 vcpRollback(pepperEnv)
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/ovs-gateway-upgrade.groovy b/ovs-gateway-upgrade.groovy
index 8d131c8..87cf828 100644
--- a/ovs-gateway-upgrade.groovy
+++ b/ovs-gateway-upgrade.groovy
@@ -7,6 +7,7 @@
  *   TARGET_SERVERS             Salt compound target to match nodes to be updated [*, G@osfamily:debian].
  *   TARGET_SUBSET_TEST         Number of nodes to list package updates, empty string means all targetted nodes.
  *   TARGET_SUBSET_LIVE         Number of selected nodes to live apply selected package update.
+ *   INTERACTIVE                Ask interactive questions during pipeline run (bool).
  *
 **/
 
@@ -63,8 +64,10 @@
                 salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
             }
 
-            stage('Confirm upgrade on sample nodes') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on sample nodes') {
                 input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?"
+              }
             }
 
             stage("Add new repos on sample nodes") {
@@ -81,8 +84,10 @@
                 }
             }
 
-            stage('Confirm upgrade on sample') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on sample') {
                 input message: "Please verify if there are packages that it wants to downgrade. If so, execute apt-cache policy on them and verify if everything is fine. Do you want to continue with upgrade?"
+              }
             }
 
             command = "cmd.run"
@@ -111,10 +116,12 @@
                 }
             }
 
-            stage('Confirm upgrade on all targeted nodes') {
+            if (INTERACTIVE.toBoolean()){
+              stage('Confirm upgrade on all targeted nodes') {
                 timeout(time: 2, unit: 'HOURS') {
-                   input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
+                  input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?"
                 }
+              }
             }
 
             stage("Add new repos on all targeted nodes") {