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" ) { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 43 | salt.commandStatus(saltMaster, target, check, 'Status=Up') |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 44 | } else if ( check == "contrail-status" ) { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 45 | salt.commandStatus(saltMaster, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 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 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 53 | node() { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 54 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 55 | stage('Connect to Salt API') { |
| 56 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 57 | } |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 58 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 59 | if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 60 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 61 | stage('Opencontrail controllers upgrade') { |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 62 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 63 | 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] | 64 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 65 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 66 | |
| 67 | try { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 68 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 69 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true) |
| 70 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'linux.system.repo') |
| 71 | } catch (Exception er) { |
| 72 | errorOccured = true |
| 73 | common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 74 | return |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 75 | } |
Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 76 | |
| 77 | try { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 78 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'") |
| 79 | } catch (Exception er) { |
| 80 | common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.') |
| 81 | return |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 82 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 83 | |
| 84 | try { |
| 85 | salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'") |
| 86 | } catch (Exception er) { |
| 87 | common.errorMsg('Cassandra failed to backup. Please fix it before continuing.') |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | args = 'apt install contrail-database -y;' |
| 92 | check = 'nodetool status' |
| 93 | |
| 94 | // ntw01 |
| 95 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
| 96 | // ntw02 |
| 97 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
| 98 | // ntw03 |
| 99 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
| 100 | |
| 101 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" |
| 102 | check = 'contrail-status' |
| 103 | |
| 104 | // ntw01 |
| 105 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, saltMaster, common) |
| 106 | // ntw02 |
| 107 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, saltMaster, common) |
| 108 | // ntw03 |
| 109 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, saltMaster, common) |
| 110 | |
| 111 | try { |
| 112 | salt.enforceState(saltMaster, 'I@opencontrail:control', 'opencontrail') |
| 113 | } catch (Exception er) { |
| 114 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') |
| 115 | } |
| 116 | |
| 117 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null) |
| 118 | salt.printSaltCommandResult(out) |
| 119 | |
| 120 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) { |
| 125 | |
| 126 | stage('Ask for manual confirmation') { |
| 127 | input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?" |
| 128 | } |
| 129 | |
| 130 | stage('Opencontrail analytics upgrade') { |
| 131 | |
| 132 | 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) |
| 133 | |
| 134 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 135 | |
| 136 | try { |
| 137 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 138 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) |
| 139 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'linux.system.repo') |
| 140 | } catch (Exception er) { |
| 141 | errorOccured = true |
| 142 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 143 | return |
| 144 | } |
| 145 | |
| 146 | args = 'apt install contrail-database -y;' |
| 147 | check = 'nodetool status' |
| 148 | |
| 149 | // nal01 |
| 150 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
| 151 | // nal02 |
| 152 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
| 153 | // nal03 |
| 154 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
| 155 | |
| 156 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" |
| 157 | check = 'contrail-status' |
| 158 | |
| 159 | // nal01 |
| 160 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
| 161 | // nal02 |
| 162 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
| 163 | // nal03 |
| 164 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, saltMaster, common) |
| 165 | |
| 166 | try { |
| 167 | salt.enforceState(saltMaster, 'I@opencontrail:collector', 'opencontrail') |
| 168 | } catch (Exception er) { |
| 169 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') |
| 170 | } |
| 171 | |
| 172 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) |
| 173 | salt.printSaltCommandResult(out) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) { |
| 178 | |
| 179 | try { |
| 180 | |
| 181 | stage('List targeted compute servers') { |
| 182 | minions = salt.getMinions(saltMaster, COMPUTE_TARGET_SERVERS) |
| 183 | |
| 184 | if (minions.isEmpty()) { |
| 185 | throw new Exception("No minion was targeted") |
| 186 | } |
| 187 | |
| 188 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 189 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 190 | |
| 191 | targetLiveAll = minions.join(' or ') |
| 192 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 193 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 194 | } |
| 195 | |
| 196 | stage('Confirm upgrade on sample nodes') { |
| 197 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" |
| 198 | } |
| 199 | |
| 200 | stage("Opencontrail compute upgrade on sample nodes") { |
| 201 | |
| 202 | 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) |
| 203 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 204 | |
| 205 | try { |
| 206 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 207 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 208 | salt.enforceState(saltMaster, targetLiveSubset, 'linux.system.repo') |
| 209 | } catch (Exception er) { |
| 210 | errorOccured = true |
| 211 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 212 | return |
| 213 | } |
| 214 | |
| 215 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 216 | check = 'contrail-status' |
| 217 | |
| 218 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 219 | salt.printSaltCommandResult(out) |
| 220 | |
| 221 | try { |
| 222 | salt.enforceState(saltMaster, targetLiveSubset, 'opencontrail') |
| 223 | } catch (Exception er) { |
| 224 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 225 | } |
| 226 | |
| 227 | salt.runSaltProcessStep(saltMaster, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 228 | |
| 229 | //sleep(10) |
| 230 | salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) |
| 231 | |
| 232 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 233 | salt.printSaltCommandResult(out) |
| 234 | } |
| 235 | |
| 236 | stage('Confirm upgrade on all targeted nodes') { |
| 237 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 238 | } |
| 239 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 240 | |
| 241 | 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) |
| 242 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 243 | |
| 244 | try { |
| 245 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 246 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 247 | salt.enforceState(saltMaster, targetLiveAll, 'linux.system.repo') |
| 248 | } catch (Exception er) { |
| 249 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 250 | return |
| 251 | } |
| 252 | |
| 253 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 254 | check = 'contrail-status' |
| 255 | |
| 256 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 257 | salt.printSaltCommandResult(out) |
| 258 | |
| 259 | try { |
| 260 | salt.enforceState(saltMaster, targetLiveAll, 'opencontrail') |
| 261 | } catch (Exception er) { |
| 262 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 263 | } |
| 264 | |
| 265 | salt.runSaltProcessStep(saltMaster, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 266 | //sleep(10) |
| 267 | salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) |
| 268 | |
| 269 | out = salt.runSaltCommand(saltMaster, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 270 | salt.printSaltCommandResult(out) |
| 271 | } |
| 272 | |
| 273 | } catch (Throwable e) { |
| 274 | // If there was an error or exception thrown, the build failed |
| 275 | currentBuild.result = "FAILURE" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 276 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 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 | |
| 360 | // nal01 |
| 361 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
| 362 | // nal02 |
| 363 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
| 364 | // nal03 |
| 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 | |
| 370 | // nal01 |
| 371 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, saltMaster, common) |
| 372 | // nal02 |
| 373 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, saltMaster, common) |
| 374 | // nal03 |
| 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) |
| 439 | //sleep(10) |
| 440 | salt.commandStatus(saltMaster, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) |
| 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) |
| 477 | |
| 478 | //sleep(10) |
| 479 | salt.commandStatus(saltMaster, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) |
| 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" |
Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 488 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 489 | throw e |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | } |