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