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 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 69 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', '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 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 106 | runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common) |
| 107 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 108 | |
| 109 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" |
| 110 | check = 'contrail-status' |
| 111 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 112 | runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common) |
| 113 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 114 | |
| 115 | try { |
| 116 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail') |
| 117 | } catch (Exception er) { |
| 118 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') |
| 119 | } |
| 120 | |
| 121 | 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] | 122 | salt.printSaltCommandResult(out) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 123 | |
Anton Samoylov | 0d642aa | 2018-11-08 15:22:27 +0400 | [diff] [blame] | 124 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs]) |
| 125 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server']) |
| 126 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 127 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) { |
| 132 | |
| 133 | stage('Ask for manual confirmation') { |
| 134 | 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] | 135 | } |
| 136 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 137 | stage('Opencontrail analytics upgrade') { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 138 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 139 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector:role:primary', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 140 | |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 141 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 142 | |
| 143 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 144 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 145 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) |
| 146 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 147 | } catch (Exception er) { |
| 148 | errorOccured = true |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 149 | 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] | 150 | return |
| 151 | } |
| 152 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 153 | args = 'apt install contrail-database -y;' |
| 154 | check = 'nodetool status' |
| 155 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 156 | runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common) |
| 157 | runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 158 | |
| 159 | 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] | 160 | check = 'contrail-status' |
| 161 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 162 | runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common) |
| 163 | runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 164 | |
| 165 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 166 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 167 | } catch (Exception er) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 168 | 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] | 169 | } |
| 170 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 171 | 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] | 172 | salt.printSaltCommandResult(out) |
| 173 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 174 | } |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 175 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 176 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) { |
| 177 | |
| 178 | try { |
| 179 | |
| 180 | stage('List targeted compute servers') { |
| 181 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
| 182 | |
| 183 | if (minions.isEmpty()) { |
| 184 | throw new Exception("No minion was targeted") |
| 185 | } |
| 186 | |
| 187 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 188 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 189 | |
| 190 | targetLiveAll = minions.join(' or ') |
| 191 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 192 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 193 | } |
| 194 | |
| 195 | stage('Confirm upgrade on sample nodes') { |
| 196 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" |
| 197 | } |
| 198 | |
| 199 | stage("Opencontrail compute upgrade on sample nodes") { |
| 200 | |
| 201 | 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) |
| 202 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 203 | |
| 204 | try { |
| 205 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 206 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 207 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 208 | } catch (Exception er) { |
| 209 | errorOccured = true |
| 210 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 211 | return |
| 212 | } |
| 213 | |
azvyagintsev | 93e05cc | 2018-12-26 13:53:02 +0200 | [diff] [blame] | 214 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 215 | check = 'contrail-status' |
| 216 | |
| 217 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 218 | salt.printSaltCommandResult(out) |
| 219 | |
| 220 | try { |
| 221 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 222 | } catch (Exception er) { |
| 223 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 224 | } |
| 225 | |
| 226 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 227 | |
| 228 | //sleep(10) |
| 229 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 230 | |
| 231 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 232 | salt.printSaltCommandResult(out) |
| 233 | } |
| 234 | |
| 235 | stage('Confirm upgrade on all targeted nodes') { |
| 236 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 237 | } |
| 238 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 239 | |
| 240 | 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) |
| 241 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 242 | |
| 243 | try { |
| 244 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 245 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 246 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 247 | } catch (Exception er) { |
| 248 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 249 | return |
| 250 | } |
| 251 | |
azvyagintsev | 93e05cc | 2018-12-26 13:53:02 +0200 | [diff] [blame] | 252 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 253 | check = 'contrail-status' |
| 254 | |
| 255 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 256 | salt.printSaltCommandResult(out) |
| 257 | |
| 258 | try { |
| 259 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') |
| 260 | } catch (Exception er) { |
| 261 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 262 | } |
| 263 | |
| 264 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 265 | //sleep(10) |
| 266 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 267 | |
| 268 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 269 | salt.printSaltCommandResult(out) |
| 270 | } |
| 271 | |
| 272 | } catch (Throwable e) { |
| 273 | // If there was an error or exception thrown, the build failed |
| 274 | currentBuild.result = "FAILURE" |
| 275 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 276 | throw e |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | |
| 281 | if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 282 | |
| 283 | stage('Ask for manual confirmation') { |
| 284 | 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] | 285 | } |
| 286 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 287 | stage('Opencontrail controllers rollback') { |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 288 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 289 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', '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] | 290 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 291 | |
| 292 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 293 | 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] | 294 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@neutron:server', 'saltutil.refresh_pillar', [], null, true) |
| 295 | 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] | 296 | } catch (Exception er) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 297 | errorOccured = true |
| 298 | 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] | 299 | return |
| 300 | } |
| 301 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 302 | args = 'apt install contrail-database -y --force-yes;' |
| 303 | check = 'nodetool status' |
| 304 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 305 | runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common) |
| 306 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 307 | |
| 308 | 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] | 309 | check = 'contrail-status' |
| 310 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 311 | runCommonCommands('I@opencontrail:control:role:primary', command, args, check, salt, pepperEnv, common) |
| 312 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 313 | |
| 314 | try { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 315 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail') |
Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 316 | } catch (Exception er) { |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 317 | 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] | 318 | } |
| 319 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 320 | 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] | 321 | salt.printSaltCommandResult(out) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 322 | |
Anton Samoylov | 0d642aa | 2018-11-08 15:22:27 +0400 | [diff] [blame] | 323 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server']) |
| 324 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.remove', [neutronServerPkgs]) |
| 325 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', [neutronServerPkgs]) |
| 326 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server']) |
| 327 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 328 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 333 | |
| 334 | stage('Ask for manual confirmation') { |
| 335 | 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] | 336 | } |
| 337 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 338 | stage('Opencontrail analytics rollback') { |
| 339 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 340 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector:role:primary', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 341 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 342 | |
| 343 | try { |
| 344 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 345 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) |
| 346 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo') |
| 347 | } catch (Exception er) { |
| 348 | errorOccured = true |
| 349 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 350 | return |
| 351 | } |
| 352 | |
| 353 | args = 'apt install contrail-database -y --force-yes;' |
| 354 | check = 'nodetool status' |
| 355 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 356 | runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common) |
| 357 | runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 358 | |
| 359 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" |
| 360 | check = 'contrail-status' |
| 361 | |
Denis Egorenko | e983d45 | 2019-08-23 14:29:34 +0400 | [diff] [blame] | 362 | runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common) |
| 363 | runCommonCommands('I@opencontrail:collector:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 364 | |
| 365 | try { |
| 366 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail') |
| 367 | } catch (Exception er) { |
| 368 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') |
| 369 | } |
| 370 | |
| 371 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) |
| 372 | salt.printSaltCommandResult(out) |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) { |
| 377 | |
| 378 | try { |
| 379 | |
| 380 | stage('List targeted compute servers') { |
| 381 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
| 382 | |
| 383 | if (minions.isEmpty()) { |
| 384 | throw new Exception("No minion was targeted") |
| 385 | } |
| 386 | |
| 387 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 388 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 389 | |
| 390 | targetLiveAll = minions.join(' or ') |
| 391 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 392 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 393 | } |
| 394 | |
| 395 | stage('Confirm rollback on sample nodes') { |
| 396 | input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}" |
| 397 | } |
| 398 | |
| 399 | stage("Opencontrail compute rollback on sample nodes") { |
| 400 | |
| 401 | 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) |
| 402 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 403 | |
| 404 | try { |
| 405 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 406 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 407 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 408 | } catch (Exception er) { |
| 409 | errorOccured = true |
| 410 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 411 | return |
| 412 | } |
| 413 | |
azvyagintsev | 93e05cc | 2018-12-26 13:53:02 +0200 | [diff] [blame] | 414 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 415 | check = 'contrail-status' |
| 416 | |
| 417 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 418 | salt.printSaltCommandResult(out) |
| 419 | |
| 420 | try { |
| 421 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 422 | } catch (Exception er) { |
| 423 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 424 | } |
| 425 | |
| 426 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 427 | //sleep(10) |
| 428 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 429 | |
| 430 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 431 | salt.printSaltCommandResult(out) |
| 432 | } |
| 433 | |
| 434 | stage('Confirm rollback on all targeted nodes') { |
| 435 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 436 | } |
| 437 | |
| 438 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 439 | |
| 440 | 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) |
| 441 | oc_component_repo = oc_component_repo['return'][0].values()[0] |
| 442 | |
| 443 | try { |
| 444 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) |
| 445 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 446 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 447 | } catch (Exception er) { |
| 448 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 449 | return |
| 450 | } |
| 451 | |
azvyagintsev | 93e05cc | 2018-12-26 13:53:02 +0200 | [diff] [blame] | 452 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" ${CMP_PKGS} -y;" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 453 | check = 'contrail-status' |
| 454 | |
| 455 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 456 | salt.printSaltCommandResult(out) |
| 457 | |
| 458 | try { |
| 459 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') |
| 460 | } catch (Exception er) { |
| 461 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 462 | } |
| 463 | |
| 464 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 465 | |
| 466 | //sleep(10) |
| 467 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 468 | |
| 469 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 470 | salt.printSaltCommandResult(out) |
| 471 | } |
| 472 | |
| 473 | } catch (Throwable e) { |
| 474 | // If there was an error or exception thrown, the build failed |
| 475 | currentBuild.result = "FAILURE" |
| 476 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 477 | throw e |
| 478 | } |
Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 479 | } |
| 480 | } |
azvyagintsev | 93e05cc | 2018-12-26 13:53:02 +0200 | [diff] [blame] | 481 | } |