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' |
Anton Samoylov | 23be5cd | 2018-10-18 14:55:31 +0400 | [diff] [blame] | 29 | def thirdPartyControlPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,redis-server,ifmap-server,supervisor' |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 30 | def analyticsPkgs = 'contrail-analytics,contrail-lib,contrail-nodemgr,contrail-utils,python-contrail,contrail-database' |
Anton Samoylov | 23be5cd | 2018-10-18 14:55:31 +0400 | [diff] [blame] | 31 | def thirdPartyAnalyticsPkgsToRemove = 'zookeeper,libzookeeper-java,kafka,cassandra,python-cassandra,cassandra-cpp-driver,redis-server,supervisor' |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 32 | //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'] |
| 33 | 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' |
Anton Samoylov | aaf1ff2 | 2018-09-27 10:46:43 +0400 | [diff] [blame] | 34 | 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 contrail-vrouter-agent start; service contrail-vrouter-nodemgr start' |
Anton Samoylov | f6b498d | 2018-09-19 13:10:34 +0400 | [diff] [blame] | 35 | def analyticsServices = ['supervisor-analytics', 'supervisor-database', 'zookeeper', 'redis-server'] |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 36 | def configServices = ['contrail-webui-jobserver', 'contrail-webui-webserver', 'supervisor-config', 'supervisor-database', 'zookeeper'] |
Anton Samoylov | f6b498d | 2018-09-19 13:10:34 +0400 | [diff] [blame] | 37 | def controlServices = ['ifmap-server', 'supervisor-control', 'redis-server'] |
| 38 | def thirdPartyServicesToDisable = ['kafka', 'zookeeper', 'cassandra'] |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 39 | 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] | 40 | |
| 41 | def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) { |
| 42 | |
| 43 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null) |
| 44 | salt.printSaltCommandResult(out) |
| 45 | // wait until $check is in correct state |
| 46 | if ( check == "nodetool status" ) { |
| 47 | salt.commandStatus(pepperEnv, target, check, 'Status=Up') |
| 48 | } else if ( check == "doctrail all contrail-status" ) { |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 49 | 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) |
| 50 | } else if ( check == "contrail-status" ) { |
| 51 | 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] | 52 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 53 | //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null) |
| 54 | //salt.printSaltCommandResult(out) |
| 55 | //input message: "Please check the output of \'${check}\' and continue if it is correct." |
| 56 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 57 | timeout(time: 12, unit: 'HOURS') { |
| 58 | node() { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 59 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 60 | stage('Setup virtualenv for Pepper') { |
| 61 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 62 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 63 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 64 | if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true) { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 65 | |
Anton Samoylov | 97ce9b8 | 2018-10-19 00:43:54 +0400 | [diff] [blame] | 66 | stage('Opencontrail controllers health check') { |
| 67 | try { |
| 68 | salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true) |
| 69 | } catch (Exception er) { |
| 70 | common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.") |
| 71 | throw er |
| 72 | } |
| 73 | } |
| 74 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 75 | stage('Opencontrail controllers upgrade') { |
| 76 | try { |
| 77 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.refresh_pillar', [], null, true) |
| 78 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'saltutil.sync_all', [], null, true) |
| 79 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 80 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'file.remove', ["/etc/apt/sources.list.d/cassandra.list"], null, true) |
| 81 | salt.enforceState(pepperEnv, 'I@opencontrail:database or I@neutron:server', 'linux.system.repo') |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 82 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 83 | } catch (Exception er) { |
| 84 | common.errorMsg("Opencontrail component on I@opencontrail:control or I@opencontrail:collector or I@neutron:server probably failed to be replaced.") |
| 85 | throw er |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 86 | } |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 87 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 88 | try { |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 89 | controllerImage = salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "docker:client:compose:opencontrail_api:service:controller:image") |
| 90 | analyticsImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analytics:image") |
| 91 | analyticsdbImage = salt.getPillar(pepperEnv, "I@opencontrail:collector:role:primary", "docker:client:compose:opencontrail_api:service:analyticsdb:image") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 92 | salt.enforceState(pepperEnv, 'I@opencontrail:database', 'docker.host') |
| 93 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
| 94 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'dockerng.pull', [controllerImage]) |
| 95 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsImage]) |
| 96 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'dockerng.pull', [analyticsdbImage]) |
| 97 | |
| 98 | } catch (Exception er) { |
| 99 | common.errorMsg("Docker images on I@opencontrail:control or I@opencontrail:collector probably failed to be downloaded.") |
| 100 | throw er |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 101 | } |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 102 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 103 | salt.enforceState(pepperEnv, 'I@zookeeper:backup:server', 'zookeeper.backup') |
| 104 | salt.enforceState(pepperEnv, 'I@zookeeper:backup:client', 'zookeeper.backup') |
| 105 | |
| 106 | try { |
| 107 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'") |
| 108 | } catch (Exception er) { |
| 109 | common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.') |
| 110 | throw er |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 113 | salt.enforceState(pepperEnv, 'I@cassandra:backup:server', 'cassandra.backup') |
| 114 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', 'cassandra.backup') |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 115 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 116 | try { |
| 117 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'") |
| 118 | } catch (Exception er) { |
| 119 | common.errorMsg('Cassandra failed to backup. Please fix it before continuing.') |
| 120 | throw er |
| 121 | } |
Anton Samoylov | f6b498d | 2018-09-19 13:10:34 +0400 | [diff] [blame] | 122 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 123 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server']) |
| 124 | |
| 125 | try { |
| 126 | for (service in analyticsServices) { |
| 127 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.stop', [service]) |
| 128 | } |
| 129 | result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.directory_exists', ['/var/lib/analyticsdb/data'])['return'][0].values()[0] |
| 130 | if (result == false) { |
| 131 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.move', ['/var/lib/cassandra', '/var/lib/analyticsdb']) |
| 132 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'file.copy', ['/var/lib/zookeeper', '/var/lib/analyticsdb_zookeeper_data','recurse=True']) |
| 133 | } |
| 134 | check = 'doctrail all contrail-status' |
| 135 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'docker.client') |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 136 | runCommonCommands('I@opencontrail:collector:role:primary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 137 | } catch (Exception er) { |
| 138 | common.errorMsg("Opencontrail Analytics failed to be upgraded.") |
| 139 | throw er |
| 140 | } |
| 141 | try { |
| 142 | check = 'doctrail all contrail-status' |
| 143 | |
| 144 | for (service in configServices) { |
| 145 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', [service]) |
| 146 | } |
| 147 | |
| 148 | result = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.directory_exists', ['/var/lib/configdb/data'])['return'][0].values()[0] |
| 149 | if (result == false) { |
| 150 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/cassandra', '/var/lib/configdb', 'recurse=True']) |
| 151 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.copy', ['/var/lib/zookeeper', '/var/lib/config_zookeeper_data', 'recurse=True']) |
| 152 | } |
| 153 | |
| 154 | for (service in controlServices) { |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 155 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'service.stop', [service]) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 158 | salt.enforceState(pepperEnv, 'I@opencontrail:control:role:secondary', 'docker.client') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 159 | |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 160 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 161 | |
| 162 | sleep(120) |
| 163 | |
| 164 | for (service in controlServices) { |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 165 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'service.stop', [service]) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 168 | salt.enforceState(pepperEnv, 'I@opencontrail:control:role:primary', 'docker.client') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 169 | |
| 170 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'pkg.install', ['neutron-plugin-contrail,contrail-heat,python-contrail']) |
| 171 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server']) |
| 172 | } catch (Exception er) { |
| 173 | common.errorMsg("Opencontrail Controller failed to be upgraded.") |
| 174 | throw er |
| 175 | } |
Anton Samoylov | 23be5cd | 2018-10-18 14:55:31 +0400 | [diff] [blame] | 176 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 177 | |
Anton Samoylov | 23be5cd | 2018-10-18 14:55:31 +0400 | [diff] [blame] | 178 | stage('Opencontrail controllers backup and cleanup') { |
| 179 | try { |
| 180 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-database.tgz', '/var/lib/cassandra']) |
| 181 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'archive.tar', ['zcvf', '/root/contrail-zookeeper.tgz', '/var/lib/zoopeeker']) |
| 182 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-database.tgz', '/var/lib/cassandra']) |
| 183 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'archive.tar', ['zcvf', '/root/contrail-analytics-zookeeper.tgz', '/var/lib/zookeeper']) |
| 184 | |
| 185 | for (service in (controlServices + thirdPartyServicesToDisable)) { |
| 186 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.disable', [service]) |
| 187 | } |
| 188 | for (service in (analyticsServices + thirdPartyServicesToDisable)) { |
| 189 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.disable', [service]) |
| 190 | } |
| 191 | |
| 192 | def tmpCfgBackupDir = '/tmp/cfg_backup' |
| 193 | def thirdPartyCfgFilesToBackup = ['/var/lib/zookeeper/myid', '/etc/zookeeper/conf/', '/usr/share/kafka/config/'] |
| 194 | |
| 195 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir]) |
| 196 | |
| 197 | for (cfgFilePath in thirdPartyCfgFilesToBackup) { |
| 198 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [tmpCfgBackupDir + cfgFilePath]) |
| 199 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [cfgFilePath, tmpCfgBackupDir + cfgFilePath, 'recurse=True']) |
| 200 | } |
| 201 | |
| 202 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'pkg.remove', [controlPkgs + ',' + thirdPartyControlPkgsToRemove]) |
| 203 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'pkg.remove', [analyticsPkgs + ',' + thirdPartyAnalyticsPkgsToRemove]) |
| 204 | |
| 205 | for (cfgFilePath in thirdPartyCfgFilesToBackup) { |
| 206 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.makedirs', [cfgFilePath]) |
| 207 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'file.copy', [tmpCfgBackupDir + cfgFilePath, cfgFilePath, 'recurse=True']) |
| 208 | } |
| 209 | } catch (Exception er) { |
| 210 | common.errorMsg("Opencontrail Controllers backup and cleanup stage has failed.") |
| 211 | throw er |
| 212 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 213 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true) { |
| 218 | |
| 219 | try { |
| 220 | |
| 221 | stage('List targeted compute servers') { |
| 222 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
| 223 | |
| 224 | if (minions.isEmpty()) { |
| 225 | throw new Exception("No minion was targeted") |
| 226 | } |
| 227 | |
| 228 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 229 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
| 230 | |
| 231 | targetLiveAll = minions.join(' or ') |
| 232 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 233 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
| 234 | } |
| 235 | |
Anton Samoylov | 97ce9b8 | 2018-10-19 00:43:54 +0400 | [diff] [blame] | 236 | stage('Compute nodes health check') { |
| 237 | try { |
| 238 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail.upgrade.verify', true, true) |
| 239 | } catch (Exception er) { |
| 240 | common.errorMsg("Opencontrail compute nodes health check stage found issues with services. Please take a look at the logs above.") |
| 241 | throw er |
| 242 | } |
| 243 | } |
| 244 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 245 | stage('Confirm upgrade on sample nodes') { |
| 246 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" |
| 247 | } |
| 248 | |
| 249 | stage("Opencontrail compute upgrade on sample nodes") { |
| 250 | |
| 251 | try { |
| 252 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 253 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.sync_all', [], null, true) |
| 254 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 255 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 256 | } catch (Exception er) { |
| 257 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 258 | throw er |
| 259 | } |
| 260 | |
| 261 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 262 | check = 'contrail-status' |
| 263 | |
| 264 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 265 | salt.printSaltCommandResult(out) |
| 266 | |
| 267 | try { |
| 268 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 269 | } catch (Exception er) { |
| 270 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 271 | } |
| 272 | |
| 273 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 274 | |
| 275 | //sleep(10) |
| 276 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 277 | |
| 278 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 279 | salt.printSaltCommandResult(out) |
| 280 | } |
| 281 | |
| 282 | stage('Confirm upgrade on all targeted nodes') { |
| 283 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
| 284 | } |
| 285 | stage("Opencontrail compute upgrade on all targeted nodes") { |
| 286 | |
| 287 | try { |
| 288 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 289 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.sync_all', [], null, true) |
| 290 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 291 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 292 | } catch (Exception er) { |
| 293 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 294 | throw er |
| 295 | } |
| 296 | |
| 297 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 298 | check = 'contrail-status' |
| 299 | |
| 300 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 301 | salt.printSaltCommandResult(out) |
| 302 | |
| 303 | try { |
| 304 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') |
| 305 | } catch (Exception er) { |
| 306 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 307 | } |
| 308 | |
| 309 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 310 | //sleep(10) |
| 311 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 312 | |
| 313 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 314 | salt.printSaltCommandResult(out) |
| 315 | } |
| 316 | |
| 317 | } catch (Throwable e) { |
| 318 | // If there was an error or exception thrown, the build failed |
| 319 | currentBuild.result = "FAILURE" |
| 320 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 321 | throw e |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | |
| 326 | if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true) { |
| 327 | |
| 328 | stage('Ask for manual confirmation') { |
| 329 | input message: "Do you want to continue with the Opencontrail nodes rollback?" |
| 330 | } |
| 331 | |
| 332 | stage('Opencontrail controllers rollback') { |
| 333 | |
| 334 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:database', 'saltutil.refresh_pillar', [], null, true) |
| 335 | salt.enforceState(pepperEnv, 'I@opencontrail:database', 'linux.system.repo') |
| 336 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
| 337 | |
| 338 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
| 339 | |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 340 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 341 | for (service in config4Services) { |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 342 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ["doctrail controller systemctl stop ${service}"], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 343 | } |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 344 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:secondary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 345 | |
| 346 | check = 'contrail-status' |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 347 | runCommonCommands('I@opencontrail:control:role:secondary', command, args, check, salt, pepperEnv, common) |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 348 | |
| 349 | sleep(120) |
| 350 | |
Anton Samoylov | a93106c | 2018-10-25 10:39:34 +0400 | [diff] [blame] | 351 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'cmd.shell', ['cd /etc/docker/compose/opencontrail/; docker-compose down'], null, true) |
| 352 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control:role:primary', 'state.sls', ['opencontrail', 'exclude=opencontrail.client']) |
Anton Samoylov | f6b498d | 2018-09-19 13:10:34 +0400 | [diff] [blame] | 353 | for (service in (controlServices + thirdPartyServicesToDisable)) { |
| 354 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.enable', [service]) |
| 355 | } |
| 356 | for (service in (analyticsServices + thirdPartyServicesToDisable)) { |
| 357 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'service.enable', [service]) |
| 358 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 359 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 362 | if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true) { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 363 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 364 | try { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 365 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 366 | stage('List targeted compute servers') { |
| 367 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 368 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 369 | if (minions.isEmpty()) { |
| 370 | throw new Exception("No minion was targeted") |
| 371 | } |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 372 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 373 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') |
| 374 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') |
Marek Celoud | 8d6ddd8 | 2018-01-03 17:56:05 +0100 | [diff] [blame] | 375 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 376 | targetLiveAll = minions.join(' or ') |
| 377 | common.infoMsg("Found nodes: ${targetLiveAll}") |
| 378 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 381 | stage('Confirm rollback on sample nodes') { |
| 382 | input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}" |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 385 | stage("Opencontrail compute rollback on sample nodes") { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 386 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 387 | try { |
| 388 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 389 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) |
| 390 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') |
| 391 | } catch (Exception er) { |
| 392 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 393 | throw er |
| 394 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 395 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 396 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 397 | check = 'contrail-status' |
| 398 | |
| 399 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) |
| 400 | salt.printSaltCommandResult(out) |
| 401 | |
| 402 | try { |
| 403 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') |
| 404 | } catch (Exception er) { |
| 405 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") |
| 406 | } |
| 407 | |
| 408 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 409 | //sleep(10) |
| 410 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 411 | |
| 412 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) |
| 413 | salt.printSaltCommandResult(out) |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 414 | } |
| 415 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 416 | stage('Confirm rollback on all targeted nodes') { |
| 417 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 420 | stage("Opencontrail compute upgrade on all targeted nodes") { |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 421 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 422 | try { |
| 423 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'file.remove', ["/etc/apt/sources.list.d/mcp_opencontrail.list"], null, true) |
| 424 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) |
| 425 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') |
| 426 | } catch (Exception er) { |
| 427 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") |
| 428 | throw er |
| 429 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 430 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 431 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" |
| 432 | check = 'contrail-status' |
| 433 | |
| 434 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) |
| 435 | salt.printSaltCommandResult(out) |
| 436 | |
| 437 | try { |
| 438 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') |
| 439 | } catch (Exception er) { |
| 440 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") |
| 441 | } |
| 442 | |
| 443 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) |
| 444 | //sleep(10) |
| 445 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active | grep -v -F /var/crashes/", null, false) |
| 446 | |
| 447 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) |
| 448 | salt.printSaltCommandResult(out) |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 449 | } |
| 450 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 451 | } catch (Throwable e) { |
| 452 | // If there was an error or exception thrown, the build failed |
| 453 | currentBuild.result = "FAILURE" |
| 454 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 455 | throw e |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 456 | } |
Marek Celoud | a54924d | 2017-12-28 16:28:42 +0100 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | } |