| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [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  (bool) | 
|  | 8 | *   STAGE_ANALYTICS_UPGRADE        Run upgrade on Opencontrail analytics  (bool) | 
|  | 9 | *   STAGE_COMPUTES_UPGRADE         Run upgrade on Opencontrail compute nodes  (bool) | 
|  | 10 | *   COMPUTE_TARGET_SERVERS         Salt compound target to match nodes to be updated [*, G@osfamily:debian]. | 
|  | 11 | *   COMPUTE_TARGET_SUBSET_LIVE     Number of selected nodes to live apply selected package update. | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 12 | *   STAGE_CONTROLLERS_ROLLBACK     Run rollback on Opencontrail controllers  (bool) | 
|  | 13 | *   STAGE_ANALYTICS_ROLLBACK       Run rollback on Opencontrail analytics  (bool) | 
|  | 14 | *   STAGE_COMPUTES_ROLLBACK        Run rollback on Opencontrail compute nodes  (bool) | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 15 | * | 
|  | 16 | **/ | 
|  | 17 |  | 
|  | 18 | def common = new com.mirantis.mk.Common() | 
|  | 19 | def salt = new com.mirantis.mk.Salt() | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 20 | def python = new com.mirantis.mk.Python() | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 21 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 22 | def pepperEnv = "pepperEnv" | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 23 | def targetLiveSubset | 
|  | 24 | def targetLiveAll | 
|  | 25 | def minions | 
|  | 26 | def result | 
|  | 27 | def args | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 28 | def commandKwargs | 
|  | 29 | def probe = 1 | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 30 | def errorOccured = false | 
|  | 31 | def command = 'cmd.shell' | 
|  | 32 |  | 
|  | 33 | def CONTROL_PKGS = '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' | 
|  | 34 | def ANALYTIC_PKGS = 'contrail-analytics contrail-lib contrail-nodemgr contrail-utils python-contrail' | 
|  | 35 | 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' | 
|  | 36 | def KERNEL_MODULE_RELOAD = 'service supervisor-vrouter stop;ifdown vhost0;rmmod vrouter;modprobe vrouter;ifup vhost0;service supervisor-vrouter start;' | 
|  | 37 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 38 | def void runCommonCommands(target, command, args, check, salt, pepperEnv, common) { | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 39 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 40 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, args, null) | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 41 | salt.printSaltCommandResult(out) | 
| Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 42 | // wait until $check is in correct state | 
|  | 43 | if ( check == "nodetool status" ) { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 44 | salt.commandStatus(pepperEnv, target, check, 'Status=Up') | 
| Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 45 | } else if ( check == "contrail-status" ) { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 46 | salt.commandStatus(pepperEnv, target, "${check} | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) | 
| Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 49 | //out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, null, check, null) | 
| Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 50 | //salt.printSaltCommandResult(out) | 
|  | 51 | //input message: "Please check the output of \'${check}\' and continue if it is correct." | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 52 | } | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 53 |  | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 54 | node() { | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 55 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 56 | stage('Setup virtualenv for Pepper') { | 
|  | 57 | python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 58 | } | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 59 |  | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 60 | if (STAGE_CONTROLLERS_UPGRADE.toBoolean() == true && !errorOccured) { | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 61 |  | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 62 | stage('Opencontrail controllers upgrade') { | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 63 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 64 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 65 |  | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 66 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 67 |  | 
|  | 68 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 69 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 70 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true) | 
|  | 71 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 72 | } catch (Exception er) { | 
|  | 73 | errorOccured = true | 
|  | 74 | common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 75 | return | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 76 | } | 
| Jiri Broulik | bdfa2fb | 2017-07-17 16:26:12 +0200 | [diff] [blame] | 77 |  | 
|  | 78 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 79 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "su root -c '/usr/local/bin/zookeeper-backup-runner.sh'") | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 80 | } catch (Exception er) { | 
|  | 81 | common.errorMsg('Zookeeper failed to backup. Please fix it before continuing.') | 
|  | 82 | return | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 83 | } | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 84 |  | 
|  | 85 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 86 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c '/usr/local/bin/cassandra-backup-runner-call.sh'") | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 87 | } catch (Exception er) { | 
|  | 88 | common.errorMsg('Cassandra failed to backup. Please fix it before continuing.') | 
|  | 89 | return | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | args = 'apt install contrail-database -y;' | 
|  | 93 | check = 'nodetool status' | 
|  | 94 |  | 
|  | 95 | // ntw01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 96 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 97 | // ntw02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 98 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 99 | // ntw03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 100 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 101 |  | 
|  | 102 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" | 
|  | 103 | check = 'contrail-status' | 
|  | 104 |  | 
|  | 105 | // ntw01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 106 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 107 | // ntw02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 108 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 109 | // ntw03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 110 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 111 |  | 
|  | 112 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 113 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 114 | } catch (Exception er) { | 
|  | 115 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') | 
|  | 116 | } | 
|  | 117 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 118 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 119 | salt.printSaltCommandResult(out) | 
|  | 120 |  | 
|  | 121 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') | 
|  | 122 | } | 
|  | 123 | } | 
|  | 124 |  | 
|  | 125 | if (STAGE_ANALYTICS_UPGRADE.toBoolean() == true && !errorOccured) { | 
|  | 126 |  | 
|  | 127 | stage('Ask for manual confirmation') { | 
|  | 128 | input message: "Do you want to continue with the Opencontrail analytic nodes upgrade?" | 
|  | 129 | } | 
|  | 130 |  | 
|  | 131 | stage('Opencontrail analytics upgrade') { | 
|  | 132 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 133 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 134 |  | 
|  | 135 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 136 |  | 
|  | 137 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 138 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 139 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) | 
|  | 140 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 141 | } catch (Exception er) { | 
|  | 142 | errorOccured = true | 
|  | 143 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 144 | return | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | args = 'apt install contrail-database -y;' | 
|  | 148 | check = 'nodetool status' | 
|  | 149 |  | 
|  | 150 | // nal01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 151 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 152 | // nal02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 153 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 154 | // nal03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 155 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 156 |  | 
|  | 157 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" | 
|  | 158 | check = 'contrail-status' | 
|  | 159 |  | 
|  | 160 | // nal01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 161 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 162 | // nal02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 163 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 164 | // nal03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 165 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 166 |  | 
|  | 167 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 168 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 169 | } catch (Exception er) { | 
|  | 170 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') | 
|  | 171 | } | 
|  | 172 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 173 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 174 | salt.printSaltCommandResult(out) | 
|  | 175 | } | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | if (STAGE_COMPUTES_UPGRADE.toBoolean() == true && !errorOccured) { | 
|  | 179 |  | 
|  | 180 | try { | 
|  | 181 |  | 
|  | 182 | stage('List targeted compute servers') { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 183 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 184 |  | 
|  | 185 | if (minions.isEmpty()) { | 
|  | 186 | throw new Exception("No minion was targeted") | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') | 
|  | 190 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') | 
|  | 191 |  | 
|  | 192 | targetLiveAll = minions.join(' or ') | 
|  | 193 | common.infoMsg("Found nodes: ${targetLiveAll}") | 
|  | 194 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") | 
|  | 195 | } | 
|  | 196 |  | 
|  | 197 | stage('Confirm upgrade on sample nodes') { | 
|  | 198 | input message: "Do you want to continue with the Opencontrail compute upgrade on the following sample nodes? ${targetLiveSubset}" | 
|  | 199 | } | 
|  | 200 |  | 
|  | 201 | stage("Opencontrail compute upgrade on sample nodes") { | 
|  | 202 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 203 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 204 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 205 |  | 
|  | 206 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 207 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 208 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) | 
|  | 209 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 210 | } catch (Exception er) { | 
|  | 211 | errorOccured = true | 
|  | 212 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 213 | return | 
|  | 214 | } | 
|  | 215 |  | 
|  | 216 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS}  -y;" | 
|  | 217 | check = 'contrail-status' | 
|  | 218 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 219 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 220 | salt.printSaltCommandResult(out) | 
|  | 221 |  | 
|  | 222 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 223 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 224 | } catch (Exception er) { | 
|  | 225 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") | 
|  | 226 | } | 
|  | 227 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 228 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 229 |  | 
|  | 230 | //sleep(10) | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 231 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 232 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 233 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 234 | salt.printSaltCommandResult(out) | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | stage('Confirm upgrade on all targeted nodes') { | 
|  | 238 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" | 
|  | 239 | } | 
|  | 240 | stage("Opencontrail compute upgrade on all targeted nodes") { | 
|  | 241 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 242 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 243 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 244 |  | 
|  | 245 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 246 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 247 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) | 
|  | 248 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 249 | } catch (Exception er) { | 
|  | 250 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 251 | return | 
|  | 252 | } | 
|  | 253 |  | 
|  | 254 | args = "export DEBIAN_FRONTEND=noninteractive; apt install -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS}  -y;" | 
|  | 255 | check = 'contrail-status' | 
|  | 256 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 257 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 258 | salt.printSaltCommandResult(out) | 
|  | 259 |  | 
|  | 260 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 261 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 262 | } catch (Exception er) { | 
|  | 263 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") | 
|  | 264 | } | 
|  | 265 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 266 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 267 | //sleep(10) | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 268 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 269 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 270 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 271 | salt.printSaltCommandResult(out) | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | } catch (Throwable e) { | 
|  | 275 | // If there was an error or exception thrown, the build failed | 
|  | 276 | currentBuild.result = "FAILURE" | 
| Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 277 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 278 | throw e | 
|  | 279 | } | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 |  | 
|  | 283 | if (STAGE_CONTROLLERS_ROLLBACK.toBoolean() == true && !errorOccured) { | 
|  | 284 |  | 
|  | 285 | stage('Ask for manual confirmation') { | 
|  | 286 | input message: "Do you want to continue with the Opencontrail control nodes rollback?" | 
|  | 287 | } | 
|  | 288 |  | 
|  | 289 | stage('Opencontrail controllers rollback') { | 
|  | 290 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 291 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 292 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 293 |  | 
|  | 294 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 295 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 296 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'saltutil.refresh_pillar', [], null, true) | 
|  | 297 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 298 | } catch (Exception er) { | 
|  | 299 | errorOccured = true | 
|  | 300 | common.errorMsg("Opencontrail component on I@opencontrail:control probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 301 | return | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | args = 'apt install contrail-database -y --force-yes;' | 
|  | 305 | check = 'nodetool status' | 
|  | 306 |  | 
|  | 307 | // ntw01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 308 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 309 | // ntw02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 310 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 311 | // ntw03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 312 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 313 |  | 
|  | 314 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${CONTROL_PKGS} -y --force-yes;" | 
|  | 315 | check = 'contrail-status' | 
|  | 316 |  | 
|  | 317 | // ntw01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 318 | runCommonCommands('I@opencontrail:control and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 319 | // ntw02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 320 | runCommonCommands('I@opencontrail:control and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 321 | // ntw03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 322 | runCommonCommands('I@opencontrail:control and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 323 |  | 
|  | 324 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 325 | salt.enforceState(pepperEnv, 'I@opencontrail:control', 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 326 | } catch (Exception er) { | 
|  | 327 | common.errorMsg('Opencontrail state was executed on I@opencontrail:control and failed please fix it manually.') | 
|  | 328 | } | 
|  | 329 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 330 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:control', 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 331 | salt.printSaltCommandResult(out) | 
|  | 332 |  | 
|  | 333 | common.warningMsg('Please check \'show bgp summary\' on your bgp router if all bgp peers are in healthy state.') | 
|  | 334 | } | 
|  | 335 | } | 
|  | 336 |  | 
|  | 337 | if (STAGE_ANALYTICS_ROLLBACK.toBoolean() == true && !errorOccured) { | 
|  | 338 |  | 
|  | 339 | stage('Ask for manual confirmation') { | 
|  | 340 | input message: "Do you want to continue with the Opencontrail analytic nodes rollback?" | 
|  | 341 | } | 
|  | 342 |  | 
|  | 343 | stage('Opencontrail analytics rollback') { | 
|  | 344 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 345 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector and *01*', 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 346 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 347 |  | 
|  | 348 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 349 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 350 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:collector', 'saltutil.refresh_pillar', [], null, true) | 
|  | 351 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 352 | } catch (Exception er) { | 
|  | 353 | errorOccured = true | 
|  | 354 | common.errorMsg("Opencontrail component on I@opencontrail:collector probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 355 | return | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | args = 'apt install contrail-database -y --force-yes;' | 
|  | 359 | check = 'nodetool status' | 
|  | 360 |  | 
|  | 361 | // nal01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 362 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 363 | // nal02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 364 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 365 | // nal03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 366 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 367 |  | 
|  | 368 | args = "apt install -o Dpkg::Options::=\"--force-confold\" ${ANALYTIC_PKGS} -y --force-yes;" | 
|  | 369 | check = 'contrail-status' | 
|  | 370 |  | 
|  | 371 | // nal01 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 372 | runCommonCommands('I@opencontrail:collector and *01*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 373 | // nal02 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 374 | runCommonCommands('I@opencontrail:collector and *02*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 375 | // nal03 | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 376 | runCommonCommands('I@opencontrail:collector and *03*', command, args, check, salt, pepperEnv, common) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 377 |  | 
|  | 378 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 379 | salt.enforceState(pepperEnv, 'I@opencontrail:collector', 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 380 | } catch (Exception er) { | 
|  | 381 | common.errorMsg('Opencontrail state was executed on I@opencontrail:collector and failed please fix it manually.') | 
|  | 382 | } | 
|  | 383 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 384 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': 'I@opencontrail:collector', 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 385 | salt.printSaltCommandResult(out) | 
|  | 386 | } | 
|  | 387 | } | 
|  | 388 |  | 
|  | 389 | if (STAGE_COMPUTES_ROLLBACK.toBoolean() == true && !errorOccured) { | 
|  | 390 |  | 
|  | 391 | try { | 
|  | 392 |  | 
|  | 393 | stage('List targeted compute servers') { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 394 | minions = salt.getMinions(pepperEnv, COMPUTE_TARGET_SERVERS) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 395 |  | 
|  | 396 | if (minions.isEmpty()) { | 
|  | 397 | throw new Exception("No minion was targeted") | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | targetLiveSubset = minions.subList(0, Integer.valueOf(COMPUTE_TARGET_SUBSET_LIVE)).join(' or ') | 
|  | 401 | targetLiveSubsetProbe = minions.subList(0, probe).join(' or ') | 
|  | 402 |  | 
|  | 403 | targetLiveAll = minions.join(' or ') | 
|  | 404 | common.infoMsg("Found nodes: ${targetLiveAll}") | 
|  | 405 | common.infoMsg("Selected sample nodes: ${targetLiveSubset}") | 
|  | 406 | } | 
|  | 407 |  | 
|  | 408 | stage('Confirm rollback on sample nodes') { | 
|  | 409 | input message: "Do you want to continue with the Opencontrail compute rollback on the following sample nodes? ${targetLiveSubset}" | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | stage("Opencontrail compute rollback on sample nodes") { | 
|  | 413 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 414 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 415 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 416 |  | 
|  | 417 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 418 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 419 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'saltutil.refresh_pillar', [], null, true) | 
|  | 420 | salt.enforceState(pepperEnv, targetLiveSubset, 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 421 | } catch (Exception er) { | 
|  | 422 | errorOccured = true | 
|  | 423 | common.errorMsg("Opencontrail component on ${targetLiveSubset} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 424 | return | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS}  -y;" | 
|  | 428 | check = 'contrail-status' | 
|  | 429 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 430 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, args, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 431 | salt.printSaltCommandResult(out) | 
|  | 432 |  | 
|  | 433 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 434 | salt.enforceState(pepperEnv, targetLiveSubset, 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 435 | } catch (Exception er) { | 
|  | 436 | common.errorMsg("Opencontrail state was executed on ${targetLiveSubset} and failed please fix it manually.") | 
|  | 437 | } | 
|  | 438 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 439 | salt.runSaltProcessStep(pepperEnv, targetLiveSubset, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 440 | //sleep(10) | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 441 | salt.commandStatus(pepperEnv, targetLiveSubset, "${check} | grep -v == | grep -v active", null, false) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 442 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 443 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveSubset, 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 444 | salt.printSaltCommandResult(out) | 
|  | 445 | } | 
|  | 446 |  | 
|  | 447 | stage('Confirm rollback on all targeted nodes') { | 
|  | 448 | input message: "Do you want to continue with the Opencontrail compute upgrade on all the targeted nodes? ${targetLiveAll} nodes?" | 
|  | 449 | } | 
|  | 450 |  | 
|  | 451 | stage("Opencontrail compute upgrade on all targeted nodes") { | 
|  | 452 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 453 | oc_component_repo = salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ['grep -RE \'oc[0-9]{2,3}\' /etc/apt/sources.list* | awk \'{print $1}\' | sed \'s/ *:.*//\''], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 454 | oc_component_repo = oc_component_repo['return'][0].values()[0] | 
|  | 455 |  | 
|  | 456 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 457 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["rm ${oc_component_repo}"], null, true) | 
|  | 458 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'saltutil.refresh_pillar', [], null, true) | 
|  | 459 | salt.enforceState(pepperEnv, targetLiveAll, 'linux.system.repo') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 460 | } catch (Exception er) { | 
|  | 461 | common.errorMsg("Opencontrail component on ${targetLiveAll} probably failed to be replaced. Please check it in ${oc_component_repo} before continuing.") | 
|  | 462 | return | 
|  | 463 | } | 
|  | 464 |  | 
|  | 465 | args = "export DEBIAN_FRONTEND=noninteractive; apt install --allow-downgrades -o Dpkg::Options::=\"--force-confold\" -o Dpkg::Options::=\"--force-confdef\" ${CMP_PKGS} -y;" | 
|  | 466 | check = 'contrail-status' | 
|  | 467 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 468 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, args, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 469 | salt.printSaltCommandResult(out) | 
|  | 470 |  | 
|  | 471 | try { | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 472 | salt.enforceState(pepperEnv, targetLiveAll, 'opencontrail') | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 473 | } catch (Exception er) { | 
|  | 474 | common.errorMsg("Opencontrail state was executed on ${targetLiveAll} and failed please fix it manually.") | 
|  | 475 | } | 
|  | 476 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 477 | salt.runSaltProcessStep(pepperEnv, targetLiveAll, 'cmd.shell', ["${KERNEL_MODULE_RELOAD}"], null, true) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 478 |  | 
|  | 479 | //sleep(10) | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 480 | salt.commandStatus(pepperEnv, targetLiveAll, "${check} | grep -v == | grep -v active", null, false) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 481 |  | 
| chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame^] | 482 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': targetLiveAll, 'type': 'compound'], command, null, check, null) | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 483 | salt.printSaltCommandResult(out) | 
|  | 484 | } | 
|  | 485 |  | 
|  | 486 | } catch (Throwable e) { | 
|  | 487 | // If there was an error or exception thrown, the build failed | 
|  | 488 | currentBuild.result = "FAILURE" | 
| Jakub Josef | d2efd7d | 2017-08-22 17:49:57 +0200 | [diff] [blame] | 489 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message | 
| Ruslan Kamaldinov | 6feef40 | 2017-08-02 16:55:58 +0400 | [diff] [blame] | 490 | throw e | 
| Jiri Broulik | 641e410 | 2017-07-13 12:26:18 +0200 | [diff] [blame] | 491 | } | 
|  | 492 | } | 
|  | 493 | } |