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