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