Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Update packages on given nodes |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000]. |
| 7 | * TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian]. |
| 8 | * TARGET_SUBSET_TEST Number of nodes to list package updates, empty string means all targetted nodes. |
| 9 | * TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update. |
| 10 | * |
| 11 | **/ |
| 12 | |
| 13 | def common = new com.mirantis.mk.Common() |
| 14 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 15 | def python = new com.mirantis.mk.Python() |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 16 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 17 | def pepperEnv = "pepperEnv" |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 18 | def targetTestSubset |
| 19 | def targetLiveSubset |
| 20 | def targetLiveAll |
| 21 | def minions |
| 22 | def result |
| 23 | def args |
| 24 | def command |
| 25 | def commandKwargs |
| 26 | def probe = 1 |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | timeout(time: 12, unit: 'HOURS') { |
| 28 | node() { |
| 29 | try { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 30 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 31 | stage('Setup virtualenv for Pepper') { |
| 32 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 33 | } |
| 34 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 35 | stage('List target servers') { |
| 36 | minions = salt.getMinions(pepperEnv, TARGET_SERVERS) |
| 37 | |
| 38 | if (minions.isEmpty()) { |
| 39 | throw new Exception("No minion was targeted") |
| 40 | } |
| 41 | |
| 42 | if (TARGET_SUBSET_TEST != "") { |
| 43 | targetTestSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_TEST)).join(' or ') |
| 44 | } else { |
| 45 | targetTestSubset = minions.join(' or ') |
| 46 | } |
| 47 | targetLiveSubset = minions.subList(0, Integer.valueOf(TARGET_SUBSET_LIVE)).join(' or ') |
| 48 | targetTestSubsetProbe = minions.subList(0, probe).join(' or ') |
| 49 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 50 | |
| 51 | targetLiveAll = minions.join(' or ') |
| 52 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 53 | common.infoMsg("Selected test nodes: ${targetTestSubset}") |
| 54 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 55 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 56 | |
| 57 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 58 | stage("Add new repos on test nodes") { |
| 59 | salt.enforceState(pepperEnv, targetTestSubset, 'linux.system.repo') |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 60 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 61 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 62 | stage("List package upgrades") { |
| 63 | salt.runSaltProcessStep(pepperEnv, targetTestSubset, 'pkg.list_upgrades', [], null, true) |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 64 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 65 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 66 | stage('Confirm upgrade on sample nodes') { |
| 67 | input message: "Please verify the list of packages that you want to be upgraded. Do you want to continue with upgrade?" |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 68 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 69 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | stage("Add new repos on sample nodes") { |
| 71 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 72 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 73 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | args = "apt-get -y -s -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade" |
| 75 | |
| 76 | stage('Test upgrade on sample') { |
| 77 | try { |
| 78 | salt.cmdRun(pepperEnv, targetLiveSubset, args) |
| 79 | } catch (Exception er) { |
| 80 | print(er) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | stage('Confirm upgrade on sample') { |
| 85 | 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?" |
| 86 | } |
| 87 | |
| 88 | command = "cmd.run" |
| 89 | args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;' |
| 90 | |
| 91 | stage('Apply package upgrades on sample') { |
| 92 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs) |
| 93 | salt.printSaltCommandResult(out) |
| 94 | } |
| 95 | |
| 96 | args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start" |
| 97 | |
| 98 | stage('Start ovs on sample nodes') { |
| 99 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, commandKwargs) |
| 100 | salt.printSaltCommandResult(out) |
| 101 | } |
| 102 | stage("Run Neutron state on sample nodes") { |
| 103 | salt.enforceState(pepperEnv, targetLiveSubset, ['neutron']) |
| 104 | } |
| 105 | |
| 106 | stage("Run Highstate on sample nodes") { |
| 107 | try { |
| 108 | salt.enforceHighstate(pepperEnv, targetLiveSubset) |
| 109 | } catch (Exception er) { |
| 110 | common.errorMsg("Highstate was executed on ${targetLiveSubset} but something failed. Please check it and fix it accordingly.") |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | stage('Confirm upgrade on all targeted nodes') { |
| 115 | timeout(time: 2, unit: 'HOURS') { |
| 116 | input message: "Verify that the upgraded sample nodes are working correctly. If so, do you want to approve live upgrade on ${targetLiveAll} nodes?" |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | stage("Add new repos on all targeted nodes") { |
| 121 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 122 | } |
| 123 | |
| 124 | args = 'export DEBIAN_FRONTEND=noninteractive; apt-get -y -q --allow-downgrades -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade;' |
| 125 | |
| 126 | stage('Apply package upgrades on all targeted nodes') { |
| 127 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs) |
| 128 | salt.printSaltCommandResult(out) |
| 129 | } |
| 130 | |
| 131 | args = "sudo /usr/share/openvswitch/scripts/ovs-ctl start" |
| 132 | |
| 133 | stage('Start ovs on all targeted nodes') { |
| 134 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, commandKwargs) |
| 135 | salt.printSaltCommandResult(out) |
| 136 | } |
| 137 | stage("Run Neutron state on all targeted nodes") { |
| 138 | salt.enforceState(pepperEnv, targetLiveAll, ['neutron']) |
| 139 | } |
| 140 | |
| 141 | stage("Run Highstate on all targeted nodes") { |
| 142 | try { |
| 143 | salt.enforceHighstate(pepperEnv, targetLiveAll) |
| 144 | } catch (Exception er) { |
| 145 | common.errorMsg("Highstate was executed ${targetLiveAll} but something failed. Please check it and fix it accordingly.") |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | } catch (Throwable e) { |
| 150 | // If there was an error or exception thrown, the build failed |
| 151 | currentBuild.result = "FAILURE" |
| 152 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 153 | throw e |
| 154 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 155 | } |
| 156 | } |