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