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