Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +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 | * |
| 8 | **/ |
| 9 | |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 10 | common = new com.mirantis.mk.Common() |
| 11 | salt = new com.mirantis.mk.Salt() |
| 12 | python = new com.mirantis.mk.Python() |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 13 | |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 14 | def pepperEnv = "pepperEnv" |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 15 | |
| 16 | def getValueForPillarKey(pepperEnv, target, pillarKey) { |
| 17 | def out = salt.getReturnValues(salt.getPillar(pepperEnv, target, pillarKey)) |
| 18 | if (out == '') { |
| 19 | throw new Exception("Cannot get value for ${pillarKey} key on ${target} target") |
| 20 | } |
| 21 | return out.toString() |
| 22 | } |
| 23 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 24 | timeout(time: 12, unit: 'HOURS') { |
| 25 | node() { |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 26 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 27 | stage('Setup virtualenv for Pepper') { |
| 28 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 29 | } |
| 30 | |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame] | 31 | stage('Opencontrail controllers health check') { |
| 32 | try { |
| 33 | salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true) |
| 34 | } catch (Exception er) { |
Anton Samoylov | 0d17e52 | 2019-08-07 17:30:25 +0400 | [diff] [blame] | 35 | common.errorMsg("Opencontrail controllers health check stage found issues with currently running services.") |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 39 | stage('Restore') { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 40 | // stop neutron-server to prevent CRUD api calls to contrail-api service |
| 41 | try { |
| 42 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true) |
| 43 | } catch (Exception er) { |
| 44 | common.warningMsg('neutron-server service already stopped') |
| 45 | } |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 46 | // get opencontrail version |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 47 | def contrailVersion = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version") |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 48 | def configDbIp = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:host") |
| 49 | def configDbPort = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", "opencontrail:database:bind:port_configdb") |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 50 | common.infoMsg("OpenContrail version is ${contrailVersion}") |
| 51 | if (contrailVersion.startsWith('4')) { |
| 52 | controllerImage = getValueForPillarKey(pepperEnv, "I@opencontrail:control:role:primary", |
| 53 | "docker:client:compose:opencontrail:service:controller:container_name") |
| 54 | common.infoMsg("Applying db restore procedure for OpenContrail 4.X version") |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 55 | try { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 56 | common.infoMsg("Stop contrail control plane containers") |
| 57 | salt.cmdRun(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'cd /etc/docker/compose/opencontrail/; docker-compose down') |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 58 | } catch (Exception err) { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 59 | common.errorMsg('An error has been occurred during contrail containers shutdown: ' + err.getMessage()) |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 60 | throw err |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 61 | } |
| 62 | try { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 63 | common.infoMsg("Cleanup cassandra data") |
| 64 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'for f in $(ls /var/lib/configdb/); do rm -r /var/lib/configdb/$f; done') |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 65 | } catch (Exception err) { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 66 | common.errorMsg('Cannot cleanup cassandra data on control nodes: ' + err.getMessage()) |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 67 | throw err |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 68 | } |
| 69 | try { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 70 | common.infoMsg("Start cassandra db on I@cassandra:backup:client node") |
| 71 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d') |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 72 | } catch (Exception err) { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 73 | common.errorMsg('An error has been occurred during cassandra db startup on I@cassandra:backup:client node: ' + err.getMessage()) |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 74 | throw err |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 75 | } |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 76 | // wait for cassandra to be online |
| 77 | common.retry(6, 20){ |
| 78 | common.infoMsg("Trying to connect to casandra db on I@cassandra:backup:client node ...") |
| 79 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "nc -v -z -w2 ${configDbIp} ${configDbPort}") |
| 80 | } |
Anton Samoylov | b3d6b55 | 2019-06-24 12:02:51 +0400 | [diff] [blame] | 81 | // remove restore-already-happened file if any is present |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 82 | try { |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 83 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored') |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 84 | } catch (Exception err) { |
| 85 | common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage()) |
| 86 | } |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 87 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra") |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 88 | try { |
| 89 | salt.cmdRun(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d') |
| 90 | } catch (Exception err) { |
| 91 | common.errorMsg('An error has been occurred during cassandra db startup on I@opencontrail:control and not I@cassandra:backup:client nodes: ' + err.getMessage()) |
| 92 | throw err |
| 93 | } |
Anton Samoylov | a119bb9 | 2019-09-16 15:37:07 +0400 | [diff] [blame] | 94 | // wait till outstanding cassandra dbs are up |
| 95 | common.retry(6, 20){ |
| 96 | common.infoMsg("Trying to connect to casandra db on I@opencontrail:control and not I@cassandra:backup:client nodes ...") |
| 97 | salt.cmdRun(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', "nc -v -z -w2 ${configDbIp} ${configDbPort}") |
| 98 | } |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 99 | try { |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 100 | common.infoMsg("Start analytics containers node") |
| 101 | salt.cmdRun(pepperEnv, 'I@opencontrail:collector', 'cd /etc/docker/compose/opencontrail/; docker-compose up -d') |
| 102 | } catch (Exception err) { |
| 103 | common.errorMsg('An error has been occurred during analytics containers startup: ' + err.getMessage()) |
| 104 | throw err |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 105 | } |
Anton Samoylov | 596371a | 2019-08-07 17:02:03 +0400 | [diff] [blame] | 106 | // contrail-control service needs to be restart after db sync to re-initialize with recovered data |
Oleksii Molchanov | dd807af | 2022-04-19 16:16:31 +0300 | [diff] [blame] | 107 | common.retry(6,20) { |
Anton Samoylov | 596371a | 2019-08-07 17:02:03 +0400 | [diff] [blame] | 108 | common.infoMsg("Restart contrail-control services on control nodes") |
| 109 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'doctrail controller service contrail-control restart') |
Anton Samoylov | 596371a | 2019-08-07 17:02:03 +0400 | [diff] [blame] | 110 | } |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 111 | } else { |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 112 | try { |
| 113 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true) |
| 114 | } catch (Exception er) { |
| 115 | common.warningMsg('Supervisor-config service already stopped') |
| 116 | } |
| 117 | // Cassandra restore section |
| 118 | try { |
| 119 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true) |
| 120 | } catch (Exception er) { |
| 121 | common.warningMsg('Supervisor-database service already stopped') |
| 122 | } |
| 123 | try { |
| 124 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak") |
| 125 | } catch (Exception er) { |
| 126 | common.warningMsg('Directory already exists') |
| 127 | } |
| 128 | |
| 129 | try { |
| 130 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
| 131 | } catch (Exception er) { |
| 132 | common.warningMsg('Files were already moved') |
| 133 | } |
| 134 | try { |
| 135 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*") |
| 136 | } catch (Exception er) { |
| 137 | common.warningMsg('Directory already empty') |
| 138 | } |
| 139 | |
Anton Samoylov | f3b0ca2 | 2019-06-21 19:53:26 +0400 | [diff] [blame] | 140 | def backupDir = getValueForPillarKey(pepperEnv, "I@cassandra:backup:client", "cassandra:backup:backup_dir") |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 141 | common.infoMsg("Backup directory is ${backupDir}") |
| 142 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true) |
| 143 | |
| 144 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true) |
| 145 | |
| 146 | // wait until supervisor-database service is up |
| 147 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 148 | sleep(60) |
| 149 | |
| 150 | // performs restore |
| 151 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup") |
| 152 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 153 | sleep(5) |
| 154 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 155 | |
| 156 | // wait until supervisor-database service is up |
| 157 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 158 | salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 159 | sleep(5) |
| 160 | |
| 161 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 162 | |
| 163 | // wait until contrail-status is up |
| 164 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
| 165 | |
| 166 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status") |
| 167 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 168 | } |
Anton Samoylov | 4e366c4 | 2019-06-26 17:20:58 +0400 | [diff] [blame] | 169 | |
| 170 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 171 | } |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame] | 172 | |
| 173 | stage('Opencontrail controllers health check') { |
Oleksii Molchanov | dd807af | 2022-04-19 16:16:31 +0300 | [diff] [blame] | 174 | common.retry(9, 60){ |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame] | 175 | salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true) |
| 176 | } |
| 177 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 178 | } |
| 179 | } |