Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +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 [http://10.10.10.1:8000]. |
| 7 | * STAGE_CONTROLLERS_UPGRADE Run upgrade on Opencontrail controllers (bool) |
| 8 | * STAGE_ANALYTICS_UPGRADE Run upgrade on Opencontrail analytics (bool) |
| 9 | * STAGE_COMPUTES_UPGRADE Run upgrade on Opencontrail compute nodes (bool) |
| 10 | * COMPUTE_TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian]. |
| 11 | * COMPUTE_TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update. |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 12 | * STAGE_CONTROLLERS_ROLLBACK Run rollback on Opencontrail controllers (bool) |
| 13 | * STAGE_ANALYTICS_ROLLBACK Run rollback on Opencontrail analytics (bool) |
| 14 | * STAGE_COMPUTES_ROLLBACK Run rollback on Opencontrail compute nodes (bool) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 15 | * |
| 16 | **/ |
| 17 | |
| 18 | def common = new com.mirantis.mk.Common() |
| 19 | def salt = new com.mirantis.mk.Salt() |
| 20 | |
| 21 | def saltMaster |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 22 | def targetLiveSubset |
| 23 | def targetLiveAll |
| 24 | def minions |
| 25 | def result |
| 26 | def args |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 27 | def commandKwargs |
| 28 | def probe = 1 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 29 | def errorOccured = false |
| 30 | def command = 'cmd.shell' |
| 31 | |
| 32 | def CONTROL_PKGS = 'contrail-config contrail-config-openstack contrail-control contrail-dns contrail-lib contrail-nodemgr contrail-utils contrail-web-controller contrail-web-core neutron-plugin-contrail python-contrail' |
| 33 | def ANALYTIC_PKGS = 'contrail-analytics contrail-lib contrail-nodemgr contrail-utils python-contrail' |
| 34 | def CMP_PKGS = 'contrail-lib contrail-nodemgr contrail-utils contrail-vrouter-agent contrail-vrouter-utils python-contrail python-contrail-vrouter-api python-opencontrail-vrouter-netns contrail-vrouter-dkms' |
| 35 | def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;' |
| 36 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 37 | def void runCommonCommands(target, command, args, check, salt, saltMaster, common) { |
| 38 | |
| 39 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, args, null) |
| 40 | salt.printSaltCommandResult(out) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 41 | // wait until $check is in correct state |
| 42 | if ( check == "nodetool status" ) { |
| 43 | salt.commandStatus(saltMaster, target, check, 'Status=Up') |
| 44 | } else if ( check == "contrail-status" ) { |
| 45 | salt.commandStatus(saltMaster, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
| 46 | } |
| 47 | |
| 48 | //out = salt.runSaltCommand(saltMaster, 'local', ['expression': target, 'type': 'compound'], command, null, check, null) |
| 49 | //salt.printSaltCommandResult(out) |
| 50 | //input message: "Please check the output of \'${check}\' and continue if it is correct." |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 51 | } |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 52 | |
| 53 | timestamps { |
| 54 | node() { |
| 55 | |
| 56 | stage('Connect to Salt API') { |
| 57 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 58 | } |
| 59 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 60 | if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 61 | |
| 62 | stage('Opencontrail controllers upgrade') { |
| 63 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 64 | oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 65 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 66 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 67 | |
| 68 | try { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 69 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 70 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true) |
| 71 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo') |
| 72 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 73 | errorOccured = true |
| 74 | common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 75 | return |
| 76 | } |
| 77 | |
| 78 | try { |
| 79 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'") |
| 80 | } catch (Exception er) { |
| 81 | common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.') |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | try { |
| 86 | salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'") |
| 87 | } catch (Exception er) { |
| 88 | common.errorMsg('Cassandra failed to backup. Please fix it before continuing.') |
| 89 | return |
| 90 | } |
| 91 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 92 | args = 'apt install contrail-database -y;' |
| 93 | check = 'nodetool status' |
| 94 | |
| 95 | // ntw01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 96 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 97 | // ntw02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 98 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 99 | // ntw03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 100 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 101 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 102 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 103 | check = 'contrail-status' |
| 104 | |
| 105 | // ntw01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 106 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 107 | // ntw02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 108 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 109 | // ntw03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 110 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 111 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 112 | try { |
| 113 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail') |
| 114 | } catch (Exception er) { |
| 115 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') |
| 116 | } |
| 117 | |
| 118 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null) |
| 119 | salt.printSaltCommandResult(out) |
| 120 | |
| 121 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') |
| 122 | } |
| 123 | } |
| 124 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 125 | if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 126 | |
| 127 | stage('Ask for manual confirmation') { |
| 128 | input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?" |
| 129 | } |
| 130 | |
| 131 | stage('Opencontrail analytics upgrade') { |
| 132 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 133 | oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 134 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 135 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 136 | |
| 137 | try { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 138 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 139 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) |
| 140 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo') |
| 141 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 142 | errorOccured = true |
| 143 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 144 | return |
| 145 | } |
| 146 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 147 | args = 'apt install contrail-database -y;' |
| 148 | check = 'nodetool status' |
| 149 | |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 150 | // nal01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 151 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 152 | // nal02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 153 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 154 | // nal03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 155 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 156 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 157 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 158 | check = 'contrail-status' |
| 159 | |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 160 | // nal01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 161 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 162 | // nal02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 163 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 164 | // nal03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 165 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 166 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 167 | try { |
| 168 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail') |
| 169 | } catch (Exception er) { |
| 170 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') |
| 171 | } |
| 172 | |
| 173 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) |
| 174 | salt.printSaltCommandResult(out) |
| 175 | } |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 178 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 179 | |
| 180 | try { |
| 181 | |
| 182 | stage('List targeted compute servers') { |
| 183 | minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS) |
| 184 | |
| 185 | if (minions.isEmpty()) { |
| 186 | throw new Exception("No minion was targeted") |
| 187 | } |
| 188 | |
| 189 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 190 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 191 | |
| 192 | targetLiveAll = minions.join(' or ') |
| 193 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 194 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 195 | } |
| 196 | |
| 197 | stage('Confirm upgrade on sample nodes') { |
| 198 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" |
| 199 | } |
| 200 | |
| 201 | stage("Opencontrail compute upgrade on sample nodes") { |
| 202 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 203 | oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 204 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 205 | |
| 206 | try { |
| 207 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 208 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 209 | salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo') |
| 210 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 211 | errorOccured = true |
| 212 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 213 | return |
| 214 | } |
| 215 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 216 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 217 | check = 'contrail-status' |
| 218 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 219 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 220 | salt.printSaltCommandResult(out) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 221 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 222 | try { |
| 223 | salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail') |
| 224 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 225 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 228 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 229 | |
| 230 | //sleep(10) |
| 231 | salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 232 | |
| 233 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 234 | salt.printSaltCommandResult(out) |
| 235 | } |
| 236 | |
| 237 | stage('Confirm upgrade on all targeted nodes') { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 238 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 239 | } |
| 240 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 241 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 242 | oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 243 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 244 | |
| 245 | try { |
| 246 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 247 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 248 | salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo') |
| 249 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 250 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 251 | return |
| 252 | } |
| 253 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 254 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 255 | check = 'contrail-status' |
| 256 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 257 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 258 | salt.printSaltCommandResult(out) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 259 | |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 260 | try { |
| 261 | salt.enforceState(saltMaster, targetLiveAll, 'opencontrail') |
| 262 | } catch (Exception er) { |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 263 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 266 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 267 | //sleep(10) |
| 268 | salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 269 | |
| 270 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 271 | salt.printSaltCommandResult(out) |
| 272 | } |
| 273 | |
| 274 | } catch (Throwable e) { |
| 275 | // If there was an error or exception thrown, the build failed |
| 276 | currentBuild.result = "FAILURE" |
| 277 | throw e |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | |
| 282 | if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 283 | |
| 284 | stage('Ask for manual confirmation') { |
| 285 | input message: "Do you want to continue with the Opencontrail control nodes rollback?" |
| 286 | } |
| 287 | |
| 288 | stage('Opencontrail controllers rollback') { |
| 289 | |
| 290 | oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
| 291 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 292 | |
| 293 | try { |
| 294 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 295 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true) |
| 296 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo') |
| 297 | } catch (Exception er) { |
| 298 | errorOccured = true |
| 299 | common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 300 | return |
| 301 | } |
| 302 | |
| 303 | args = 'apt install contrail-database -y --force-yes;' |
| 304 | check = 'nodetool status' |
| 305 | |
| 306 | // ntw01 |
| 307 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
| 308 | // ntw02 |
| 309 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
| 310 | // ntw03 |
| 311 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
| 312 | |
| 313 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" |
| 314 | check = 'contrail-status' |
| 315 | |
| 316 | // ntw01 |
| 317 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
| 318 | // ntw02 |
| 319 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
| 320 | // ntw03 |
| 321 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
| 322 | |
| 323 | try { |
| 324 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail') |
| 325 | } catch (Exception er) { |
| 326 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') |
| 327 | } |
| 328 | |
| 329 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null) |
| 330 | salt.printSaltCommandResult(out) |
| 331 | |
| 332 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 337 | |
| 338 | stage('Ask for manual confirmation') { |
| 339 | input message: "Do you want to continue with the Opencontrail analytic nodes rollback?" |
| 340 | } |
| 341 | |
| 342 | stage('Opencontrail analytics rollback') { |
| 343 | |
| 344 | oc_component_repo = salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
| 345 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 346 | |
| 347 | try { |
| 348 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 349 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) |
| 350 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo') |
| 351 | } catch (Exception er) { |
| 352 | errorOccured = true |
| 353 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 354 | return |
| 355 | } |
| 356 | |
| 357 | args = 'apt install contrail-database -y --force-yes;' |
| 358 | check = 'nodetool status' |
| 359 | |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 360 | // nal01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 361 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 362 | // nal02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 363 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 364 | // nal03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 365 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
| 366 | |
| 367 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" |
| 368 | check = 'contrail-status' |
| 369 | |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 370 | // nal01 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 371 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 372 | // nal02 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 373 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 374 | // nal03 |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 375 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
| 376 | |
| 377 | try { |
| 378 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail') |
| 379 | } catch (Exception er) { |
| 380 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') |
| 381 | } |
| 382 | |
| 383 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) |
| 384 | salt.printSaltCommandResult(out) |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 389 | |
| 390 | try { |
| 391 | |
| 392 | stage('List targeted compute servers') { |
| 393 | minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS) |
| 394 | |
| 395 | if (minions.isEmpty()) { |
| 396 | throw new Exception("No minion was targeted") |
| 397 | } |
| 398 | |
| 399 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 400 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 401 | |
| 402 | targetLiveAll = minions.join(' or ') |
| 403 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 404 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 405 | } |
| 406 | |
| 407 | stage('Confirm rollback on sample nodes') { |
| 408 | input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}" |
| 409 | } |
| 410 | |
| 411 | stage("Opencontrail compute rollback on sample nodes") { |
| 412 | |
| 413 | oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
| 414 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 415 | |
| 416 | try { |
| 417 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 418 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 419 | salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo') |
| 420 | } catch (Exception er) { |
| 421 | errorOccured = true |
| 422 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 423 | return |
| 424 | } |
| 425 | |
| 426 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 427 | check = 'contrail-status' |
| 428 | |
| 429 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 430 | salt.printSaltCommandResult(out) |
| 431 | |
| 432 | try { |
| 433 | salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail') |
| 434 | } catch (Exception er) { |
| 435 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 436 | } |
| 437 | |
| 438 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 439 | //sleep(10) |
| 440 | salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 441 | |
| 442 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 443 | salt.printSaltCommandResult(out) |
| 444 | } |
| 445 | |
| 446 | stage('Confirm rollback on all targeted nodes') { |
| 447 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 448 | } |
| 449 | |
| 450 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 451 | |
| 452 | oc_component_repo = salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
| 453 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 454 | |
| 455 | try { |
| 456 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 457 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 458 | salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo') |
| 459 | } catch (Exception er) { |
| 460 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 461 | return |
| 462 | } |
| 463 | |
| 464 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 465 | check = 'contrail-status' |
| 466 | |
| 467 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 468 | salt.printSaltCommandResult(out) |
| 469 | |
| 470 | try { |
| 471 | salt.enforceState(saltMaster, targetLiveAll, 'opencontrail') |
| 472 | } catch (Exception er) { |
| 473 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 474 | } |
| 475 | |
| 476 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 477 | |
| 478 | //sleep(10) |
| 479 | salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 480 | |
| 481 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 482 | salt.printSaltCommandResult(out) |
| 483 | } |
| 484 | |
| 485 | } catch (Throwable e) { |
| 486 | // If there was an error or exception thrown, the build failed |
| 487 | currentBuild.result = "FAILURE" |
| 488 | throw e |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } |