diff --git a/openstack-compute-upgrade.groovy b/openstack-compute-upgrade.groovy
index 6c8ffdf..a59fc08 100644
--- a/openstack-compute-upgrade.groovy
+++ b/openstack-compute-upgrade.groovy
@@ -25,228 +25,230 @@
 def commandKwargs
 def probe = 1
 
-node() {
-    try {
-
-        stage('Setup virtualenv for Pepper') {
-            python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
-        }
-
-        stage('List target servers') {
-            minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
-
-            if (minions.isEmpty()) {
-                throw new Exception("No minion was targeted")
-            }
-
-            if (TARGET_SUBSET_TEST != "") {
-                targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
-            } else {
-                targetTestSubset = minions.join(' or ')
-            }
-            targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
-            targetTestSubsetProbe = minions.subList(0, probe).join(' or ')
-            targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
-
-            targetLiveAll = minions.join(' or ')
-            common.infoMsg("Found nodes: ${targetLiveAll}")
-            common.infoMsg("Selected test nodes: ${targetTestSubset}")
-            common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
-        }
-
-
-        stage("Add new repos on test nodes") {
-            salt.enforceState(pepperEnv, targetTestSubset, 'linux.system.repo')
-        }
-
-
-        opencontrail = null
-
+timeout(time: 12, unit: 'HOURS') {
+    node() {
         try {
-            opencontrail = salt.cmdRun(pepperEnv, targetTestSubsetProbe, "salt-call grains.item roles | grep opencontrail.compute")
-            print(opencontrail)
-        } catch (Exception er) {
-            common.infoMsg("opencontrail is not used")
-        }
 
-        if(opencontrail != null) {
-            stage('Remove OC component from repos on test nodes') {
-                def contrail_repo_file1 = ''
-                def contrail_repo_file2 = ''
-                try {
-                    contrail_repo_file1 = salt.cmdRun(pepperEnv, targetTestSubset, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                    contrail_repo_file2 = salt.cmdRun(pepperEnv, targetTestSubset, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                } catch (Exception er) {
-                    common.warningMsg(er)
-                }
-                salt.cmdRun(pepperEnv, targetTestSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
-                try {
-                    salt.cmdRun(pepperEnv, targetTestSubset, "salt-call pkg.refresh_db")
-                } catch (Exception er) {
-                    common.warningMsg(er)
-                    // remove the malformed repo entry
-                    salt.cmdRun(pepperEnv, targetTestSubset, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
-                    salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.refresh_db', [], null, true)
-                }
+            stage('Setup virtualenv for Pepper') {
+                python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
             }
-        }
 
-        stage("List package upgrades") {
-            salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
-        }
+            stage('List target servers') {
+                minions = salt.getMinions(pepperEnv, TARGET_SERVERS)
 
-        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") {
-            salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
-        }
-
-        if(opencontrail != null) {
-            stage('Remove OC component from repos on sample nodes') {
-                def contrail_repo_file1 = ''
-                def contrail_repo_file2 = ''
-                try {
-                    contrail_repo_file1 = salt.cmdRun(pepperEnv, targetLiveSubset, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                    contrail_repo_file2 = salt.cmdRun(pepperEnv, targetLiveSubset, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                } catch (Exception er) {
-                    common.warningMsg(er)
+                if (minions.isEmpty()) {
+                    throw new Exception("No minion was targeted")
                 }
-                salt.cmdRun(pepperEnv, targetLiveSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
-                try {
-                    salt.cmdRun(pepperEnv, targetLiveSubset, "salt-call pkg.refresh_db")
-                } catch (Exception er) {
-                    common.warningMsg(er)
-                    // remove the malformed repo entry
-                    salt.cmdRun(pepperEnv, targetLiveSubset, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
-                    salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'pkg.refresh_db', [], null, true)
+
+                if (TARGET_SUBSET_TEST != "") {
+                    targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ')
+                } else {
+                    targetTestSubset = minions.join(' or ')
                 }
+                targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ')
+                targetTestSubsetProbe = minions.subList(0, probe).join(' or ')
+                targetLiveSubsetProbe = minions.subList(0, probe).join(' or ')
+
+                targetLiveAll = minions.join(' or ')
+                common.infoMsg("Found nodes: ${targetLiveAll}")
+                common.infoMsg("Selected test nodes: ${targetTestSubset}")
+                common.infoMsg("Selected sample nodes: ${targetLiveSubset}")
             }
-        }
 
-        args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade"
 
-        stage('Test upgrade on sample') {
+            stage("Add new repos on test nodes") {
+                salt.enforceState(pepperEnv, targetTestSubset, 'linux.system.repo')
+            }
+
+
+            opencontrail = null
+
             try {
-                salt.cmdRun(pepperEnv, targetLiveSubset, args)
+                opencontrail = salt.cmdRun(pepperEnv, targetTestSubsetProbe, "salt-call grains.item roles | grep opencontrail.compute")
+                print(opencontrail)
             } catch (Exception er) {
-                print(er)
+                common.infoMsg("opencontrail is not used")
             }
-        }
 
-        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?"
-        }
+            if(opencontrail != null) {
+                stage('Remove OC component from repos on test nodes') {
+                    def contrail_repo_file1 = ''
+                    def contrail_repo_file2 = ''
+                    try {
+                        contrail_repo_file1 = salt.cmdRun(pepperEnv, targetTestSubset, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                        contrail_repo_file2 = salt.cmdRun(pepperEnv, targetTestSubset, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                    }
+                    salt.cmdRun(pepperEnv, targetTestSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
+                    try {
+                        salt.cmdRun(pepperEnv, targetTestSubset, "salt-call pkg.refresh_db")
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                        // remove the malformed repo entry
+                        salt.cmdRun(pepperEnv, targetTestSubset, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
+                        salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.refresh_db', [], null, true)
+                    }
+                }
+            }
 
-        command = "cmd.run"
-        args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
+            stage("List package upgrades") {
+                salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true)
+            }
 
-        stage('Apply package upgrades on sample') {
-            out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
-            salt.printSaltCommandResult(out)
-        }
+            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?"
+            }
 
-        openvswitch = null
+            stage("Add new repos on sample nodes") {
+                salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo')
+            }
 
-        try {
-            openvswitch = salt.cmdRun(pepperEnv, targetLiveSubsetProbe, "salt-call grains.item roles | grep neutron.compute")
-        } catch (Exception er) {
-            common.infoMsg("openvswitch is not used")
-        }
+            if(opencontrail != null) {
+                stage('Remove OC component from repos on sample nodes') {
+                    def contrail_repo_file1 = ''
+                    def contrail_repo_file2 = ''
+                    try {
+                        contrail_repo_file1 = salt.cmdRun(pepperEnv, targetLiveSubset, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                        contrail_repo_file2 = salt.cmdRun(pepperEnv, targetLiveSubset, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                    }
+                    salt.cmdRun(pepperEnv, targetLiveSubset, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
+                    try {
+                        salt.cmdRun(pepperEnv, targetLiveSubset, "salt-call pkg.refresh_db")
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                        // remove the malformed repo entry
+                        salt.cmdRun(pepperEnv, targetLiveSubset, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
+                        salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'pkg.refresh_db', [], null, true)
+                    }
+                }
+            }
 
-        if(openvswitch != null) {
-            args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
+            args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade"
 
-            stage('Start ovs on sample nodes') {
+            stage('Test upgrade on sample') {
+                try {
+                    salt.cmdRun(pepperEnv, targetLiveSubset, args)
+                } catch (Exception er) {
+                    print(er)
+                }
+            }
+
+            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"
+            args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
+
+            stage('Apply package upgrades on sample') {
                 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
                 salt.printSaltCommandResult(out)
             }
-            stage("Run salt states on sample nodes") {
-                salt.enforceState(pepperEnv, targetLiveSubset, ['nova', 'neutron'])
-            }
-        } else {
-            stage("Run salt states on sample nodes") {
-                salt.enforceState(pepperEnv, targetLiveSubset, ['nova', 'linux.system.repo'])
-            }
-        }
 
-        stage("Run Highstate on sample nodes") {
+            openvswitch = null
+
             try {
-                salt.enforceHighstate(pepperEnv, targetLiveSubset)
+                openvswitch = salt.cmdRun(pepperEnv, targetLiveSubsetProbe, "salt-call grains.item roles | grep neutron.compute")
             } catch (Exception er) {
-                common.errorMsg("Highstate was executed on ${targetLiveSubset} but something failed. Please check it and fix it accordingly.")
+                common.infoMsg("openvswitch is not used")
             }
-        }
 
-        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?"
-            }
-        }
+            if(openvswitch != null) {
+                args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
 
-        stage("Add new repos on all targeted nodes") {
-            salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
-        }
-
-        if(opencontrail != null) { 
-            stage('Remove OC component from repos on all targeted nodes') {
-                def contrail_repo_file1 = ''
-                def contrail_repo_file2 = ''
-                try {
-                    contrail_repo_file1 = salt.cmdRun(pepperEnv, targetLiveAll, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                    contrail_repo_file2 = salt.cmdRun(pepperEnv, targetLiveAll, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
-                } catch (Exception er) {
-                    common.warningMsg(er)
+                stage('Start ovs on sample nodes') {
+                    out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs)
+                    salt.printSaltCommandResult(out)
                 }
-                salt.cmdRun(pepperEnv, targetLiveAll, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
-                try {
-                    salt.cmdRun(pepperEnv, targetLiveAll, "salt-call pkg.refresh_db")
-                } catch (Exception er) {
-                    common.warningMsg(er)
-                    // remove the malformed repo entry
-                    salt.cmdRun(pepperEnv, targetLiveAll, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
-                    salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.refresh_db', [], null, true)
+                stage("Run salt states on sample nodes") {
+                    salt.enforceState(pepperEnv, targetLiveSubset, ['nova', 'neutron'])
+                }
+            } else {
+                stage("Run salt states on sample nodes") {
+                    salt.enforceState(pepperEnv, targetLiveSubset, ['nova', 'linux.system.repo'])
                 }
             }
-        }
 
-        args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
+            stage("Run Highstate on sample nodes") {
+                try {
+                    salt.enforceHighstate(pepperEnv, targetLiveSubset)
+                } catch (Exception er) {
+                    common.errorMsg("Highstate was executed on ${targetLiveSubset} but something failed. Please check it and fix it accordingly.")
+                }
+            }
 
-        stage('Apply package upgrades on all targeted nodes') {
-            out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
-            salt.printSaltCommandResult(out)
-        }
+            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?"
+                }
+            }
 
-        if(openvswitch != null) {
-            args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
+            stage("Add new repos on all targeted nodes") {
+                salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo')
+            }
 
-            stage('Start ovs on all targeted nodes') {
+            if(opencontrail != null) { 
+                stage('Remove OC component from repos on all targeted nodes') {
+                    def contrail_repo_file1 = ''
+                    def contrail_repo_file2 = ''
+                    try {
+                        contrail_repo_file1 = salt.cmdRun(pepperEnv, targetLiveAll, "grep -Eorl \\ oc\\([0-9]*\$\\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                        contrail_repo_file2 = salt.cmdRun(pepperEnv, targetLiveAll, "grep -Eorl \\ oc\\([0-9]*\\ \\) /etc/apt/sources.list*")['return'][0].values()[0].split("\n")[0]
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                    }
+                    salt.cmdRun(pepperEnv, targetLiveAll, "find /etc/apt/sources.list* -type f -print0 | xargs -0 sed -i -r -e 's/ oc([0-9]*) / /g;s/ oc([0-9]*\$)//g'")
+                    try {
+                        salt.cmdRun(pepperEnv, targetLiveAll, "salt-call pkg.refresh_db")
+                    } catch (Exception er) {
+                        common.warningMsg(er)
+                        // remove the malformed repo entry
+                        salt.cmdRun(pepperEnv, targetLiveAll, "rm ${contrail_repo_file1} ${contrail_repo_file2}")
+                        salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'pkg.refresh_db', [], null, true)
+                    }
+                }
+            }
+
+            args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;'
+
+            stage('Apply package upgrades on all targeted nodes') {
                 out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
                 salt.printSaltCommandResult(out)
             }
-            stage("Run salt states on all targeted nodes") {
-                salt.enforceState(pepperEnv, targetLiveAll, ['nova', 'neutron'])
-            }
-        } else {
-            stage("Run salt states on all targeted nodes") {
-                salt.enforceState(pepperEnv, targetLiveAll, ['nova', 'linux.system.repo'])
-            }
-        }
 
-        stage("Run Highstate on all targeted nodes") {
-            try {
-                salt.enforceHighstate(pepperEnv, targetLiveAll)
-            } catch (Exception er) {
-                common.errorMsg("Highstate was executed ${targetLiveAll} but something failed. Please check it and fix it accordingly.")
-            }
-        }
+            if(openvswitch != null) {
+                args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start"
 
-    } catch (Throwable e) {
-        // If there was an error or exception thrown, the build failed
-        currentBuild.result = "FAILURE"
-        currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
-        throw e
+                stage('Start ovs on all targeted nodes') {
+                    out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs)
+                    salt.printSaltCommandResult(out)
+                }
+                stage("Run salt states on all targeted nodes") {
+                    salt.enforceState(pepperEnv, targetLiveAll, ['nova', 'neutron'])
+                }
+            } else {
+                stage("Run salt states on all targeted nodes") {
+                    salt.enforceState(pepperEnv, targetLiveAll, ['nova', 'linux.system.repo'])
+                }
+            }
+
+            stage("Run Highstate on all targeted nodes") {
+                try {
+                    salt.enforceHighstate(pepperEnv, targetLiveAll)
+                } catch (Exception er) {
+                    common.errorMsg("Highstate was executed ${targetLiveAll} but something failed. Please check it and fix it accordingly.")
+                }
+            }
+
+        } catch (Throwable e) {
+            // If there was an error or exception thrown, the build failed
+            currentBuild.result = "FAILURE"
+            currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
+            throw e
+        }
     }
 }
 
