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