Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [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 and analytics (bool) |
| 8 | * STAGE_COMPUTES_UPGRADE Run upgrade on Opencontrail compute nodes (bool) |
| 9 | * COMPUTE_TARGET_SERVERS Salt compound target to match nodes to be updated [*, G@osfamily:debian]. |
| 10 | * COMPUTE_TARGET_SUBSET_LIVE Number of selected nodes to live apply selected package update. |
| 11 | * STAGE_CONTROLLERS_ROLLBACK Run rollback on Opencontrail controllers (bool) |
| 12 | * STAGE_COMPUTES_ROLLBACK Run rollback on Opencontrail compute nodes (bool) |
| 13 | * |
| 14 | **/ |
| 15 | |
| 16 | def common = new com.mirantis.mk.Common() |
| 17 | def salt = new com.mirantis.mk.Salt() |
| 18 | def python = new com.mirantis.mk.Python() |
| 19 | |
| 20 | def pepperEnv = "pepperEnv" |
| 21 | def targetLiveSubset |
| 22 | def targetLiveAll |
| 23 | def minions |
| 24 | def args |
| 25 | def probe = 1 |
| 26 | def command = 'cmd.shell' |
| 27 | |
| 28 | def controlPkgs = '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,contrail-database' |
| 29 | def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,python-contrail,contrail-database' |
| 30 | //def cmpPkgs = ['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'] |
| 31 | 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' |
| 32 | def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;' |
| 33 | def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper'] |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 34 | def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper'] |
| 35 | def controlServices = ['ifmap-server', 'supervisor-control'] |
| 36 | def config4Services = ['zookeeper', 'contrail-webui-middleware', 'contrail-webui', 'contrail-api', 'contrail-schema', 'contrail-svc-monitor', 'contrail-device-manager', 'contrail-config-nodemgr', 'contrail-database'] |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 37 | |
| 38 | def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) { |
| 39 | |
| 40 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null) |
| 41 | salt.printSaltCommandResult(out) |
| 42 | // wait until $check is in correct state |
| 43 | if ( check == "nodetool status" ) { |
| 44 | salt.commandStatus(pepperEnv, target, check, 'Status=Up') |
| 45 | } else if ( check == "doctrail all contrail-status" ) { |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 46 | salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v FOR | grep -v \\* | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/", null, false, true, null, true, 500) |
| 47 | } else if ( check == "contrail-status" ) { |
| 48 | salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v FOR | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup | grep -v -F /var/crashes/", null, false, true, null, true, 500) |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 49 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 50 | //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null) |
| 51 | //salt.printSaltCommandResult(out) |
| 52 | //input message: "Please check the output of \'${check}\' and continue if it is correct." |
| 53 | } |
| 54 | |
| 55 | node() { |
| 56 | |
| 57 | stage('Setup virtualenv for Pepper') { |
| 58 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 59 | } |
| 60 | |
| 61 | if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) { |
| 62 | |
| 63 | stage('Opencontrail controllers upgrade') { |
| 64 | try { |
| 65 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.refresh_pillar', [], null, true) |
| 66 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.sync_all', [], null, true) |
| 67 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 68 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true) |
| 69 | salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'linux.system.repo') |
| 70 | |
| 71 | } catch (Exception er) { |
| 72 | common.errorMsg("Opencontrail component on I@opencontrail:control or I@opencontrail:collector or I@neutron:server probably failed to be replaced.") |
| 73 | throw er |
| 74 | } |
| 75 | |
| 76 | try { |
| 77 | controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control and *01*", "docker:client:compose:opencontrail_api:service:controller:image") |
| 78 | analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analytics:image") |
| 79 | analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector and *01*", "docker:client:compose:opencontrail_api:service:analyticsdb:image") |
| 80 | salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host') |
| 81 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
| 82 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage]) |
| 83 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage]) |
| 84 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage]) |
| 85 | |
| 86 | } catch (Exception er) { |
| 87 | common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.") |
| 88 | throw er |
| 89 | } |
| 90 | |
| 91 | salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup') |
| 92 | salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup') |
| 93 | |
| 94 | try { |
| 95 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'") |
| 96 | } catch (Exception er) { |
| 97 | common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.') |
| 98 | throw er |
| 99 | } |
| 100 | |
| 101 | salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup') |
| 102 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup') |
| 103 | |
| 104 | try { |
| 105 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'") |
| 106 | } catch (Exception er) { |
| 107 | common.errorMsg('Cassandra failed to backup. Please fix it before continuing.') |
| 108 | throw er |
| 109 | } |
| 110 | |
| 111 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server']) |
| 112 | |
| 113 | try { |
| 114 | for (service in analyticsServices) { |
| 115 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service]) |
| 116 | } |
| 117 | result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0] |
| 118 | if (result == false) { |
| 119 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb']) |
| 120 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True']) |
| 121 | } |
| 122 | check = 'doctrail all contrail-status' |
| 123 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client') |
| 124 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common) |
| 125 | } catch (Exception er) { |
| 126 | common.errorMsg("Opencontrail Analytics failed to be upgraded.") |
| 127 | throw er |
| 128 | } |
| 129 | try { |
| 130 | check = 'doctrail all contrail-status' |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 131 | |
| 132 | for (service in configServices) { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 133 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service]) |
| 134 | } |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 135 | |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 136 | result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0] |
| 137 | if (result == false) { |
| 138 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True']) |
| 139 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True']) |
| 140 | } |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 141 | |
| 142 | for (service in controlServices) { |
| 143 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'service.stop', [service]) |
| 144 | } |
| 145 | |
| 146 | salt.enforceState(pepperEnv, 'I@opencontrail:control and *0[23]*', 'docker.client') |
| 147 | |
| 148 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) |
| 149 | |
| 150 | sleep(120) |
| 151 | |
| 152 | for (service in controlServices) { |
| 153 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'service.stop', [service]) |
| 154 | } |
| 155 | |
| 156 | salt.enforceState(pepperEnv, 'I@opencontrail:control and *01*', 'docker.client') |
| 157 | |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 158 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', ['neutron-plugin-contrail,contrail-heat,python-contrail']) |
| 159 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server']) |
| 160 | } catch (Exception er) { |
| 161 | common.errorMsg("Opencontrail Controller failed to be upgraded.") |
| 162 | throw er |
| 163 | } |
| 164 | |
| 165 | } |
| 166 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra']) |
| 167 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker']) |
| 168 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra']) |
| 169 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper']) |
| 170 | //salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs]) |
| 171 | //salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs]) |
| 172 | for (service in controlServices) { |
| 173 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service]) |
| 174 | } |
| 175 | for (service in analyticsServices) { |
| 176 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service]) |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) { |
| 182 | |
| 183 | try { |
| 184 | |
| 185 | stage('List targeted compute servers') { |
| 186 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
| 187 | |
| 188 | if (minions.isEmpty()) { |
| 189 | throw new Exception("No minion was targeted") |
| 190 | } |
| 191 | |
| 192 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 193 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 194 | |
| 195 | targetLiveAll = minions.join(' or ') |
| 196 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 197 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 198 | } |
| 199 | |
| 200 | stage('Confirm upgrade on sample nodes') { |
| 201 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" |
| 202 | } |
| 203 | |
| 204 | stage("Opencontrail compute upgrade on sample nodes") { |
| 205 | |
| 206 | try { |
| 207 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 208 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true) |
| 209 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 210 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 211 | } catch (Exception er) { |
| 212 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 213 | throw er |
| 214 | } |
| 215 | |
| 216 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 217 | check = 'contrail-status' |
| 218 | |
| 219 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 220 | salt.printSaltCommandResult(out) |
| 221 | |
| 222 | try { |
| 223 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 224 | } catch (Exception er) { |
| 225 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 226 | } |
| 227 | |
| 228 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 229 | |
| 230 | //sleep(10) |
| 231 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 232 | |
| 233 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 234 | salt.printSaltCommandResult(out) |
| 235 | } |
| 236 | |
| 237 | stage('Confirm upgrade on all targeted nodes') { |
| 238 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 239 | } |
| 240 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 241 | |
| 242 | try { |
| 243 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 244 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true) |
| 245 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], 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 | throw er |
| 250 | } |
| 251 | |
| 252 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 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) { |
| 282 | |
| 283 | stage('Ask for manual confirmation') { |
| 284 | input message: "Do you want to continue with the Opencontrail nodes rollback?" |
| 285 | } |
| 286 | |
| 287 | stage('Opencontrail controllers rollback') { |
| 288 | |
| 289 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true) |
| 290 | salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo') |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 291 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 292 | |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 293 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame^] | 294 | |
| 295 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
| 296 | for (service in config4Services) { |
| 297 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true) |
| 298 | } |
| 299 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *0[23]*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
| 300 | |
| 301 | check = 'contrail-status' |
| 302 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) |
| 303 | |
| 304 | sleep(120) |
| 305 | |
| 306 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
| 307 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
| 311 | if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) { |
| 312 | |
| 313 | try { |
| 314 | |
| 315 | stage('List targeted compute servers') { |
| 316 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
| 317 | |
| 318 | if (minions.isEmpty()) { |
| 319 | throw new Exception("No minion was targeted") |
| 320 | } |
| 321 | |
| 322 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 323 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 324 | |
| 325 | targetLiveAll = minions.join(' or ') |
| 326 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 327 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 328 | } |
| 329 | |
| 330 | stage('Confirm rollback on sample nodes') { |
| 331 | input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}" |
| 332 | } |
| 333 | |
| 334 | stage("Opencontrail compute rollback on sample nodes") { |
| 335 | |
| 336 | try { |
| 337 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 338 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 339 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 340 | } catch (Exception er) { |
| 341 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 342 | throw er |
| 343 | } |
| 344 | |
| 345 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 346 | check = 'contrail-status' |
| 347 | |
| 348 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 349 | salt.printSaltCommandResult(out) |
| 350 | |
| 351 | try { |
| 352 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 353 | } catch (Exception er) { |
| 354 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 355 | } |
| 356 | |
| 357 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 358 | //sleep(10) |
| 359 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 360 | |
| 361 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 362 | salt.printSaltCommandResult(out) |
| 363 | } |
| 364 | |
| 365 | stage('Confirm rollback on all targeted nodes') { |
| 366 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 367 | } |
| 368 | |
| 369 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 370 | |
| 371 | try { |
| 372 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 373 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 374 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 375 | } catch (Exception er) { |
| 376 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 377 | throw er |
| 378 | } |
| 379 | |
| 380 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 381 | check = 'contrail-status' |
| 382 | |
| 383 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 384 | salt.printSaltCommandResult(out) |
| 385 | |
| 386 | try { |
| 387 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') |
| 388 | } catch (Exception er) { |
| 389 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 390 | } |
| 391 | |
| 392 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 393 | //sleep(10) |
| 394 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 395 | |
| 396 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 397 | salt.printSaltCommandResult(out) |
| 398 | } |
| 399 | |
| 400 | } catch (Throwable e) { |
| 401 | // If there was an error or exception thrown, the build failed |
| 402 | currentBuild.result = "FAILURE" |
| 403 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 404 | throw e |
| 405 | } |
| 406 | } |
| 407 | } |