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 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
chnyda | 625f4b4 | 2017-10-11 14:10:31 +0200 | [diff] [blame] | 12 | def 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" |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 15 | timeout(time: 12, unit: 'HOURS') { |
| 16 | node() { |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 17 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 18 | stage('Setup virtualenv for Pepper') { |
| 19 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame^] | 22 | stage('Opencontrail controllers health check') { |
| 23 | try { |
| 24 | salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true) |
| 25 | } catch (Exception er) { |
| 26 | common.errorMsg("Opencontrail controllers health check stage found issues with services. Please take a look at the logs above.") |
| 27 | throw er |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | stage('Backup') { |
| 32 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'bash /usr/local/bin/cassandra-backup-runner-call.sh') |
| 33 | } |
| 34 | |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 35 | stage('Restore') { |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 36 | // get opencontrail version |
| 37 | def _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", '_param:opencontrail_version') |
| 38 | def contrailVersion = _pillar['return'][0].values()[0] |
| 39 | common.infoMsg("Contrail version is ${contrailVersion}") |
| 40 | if (contrailVersion >= 4) { |
| 41 | common.infoMsg("There will be steps for OC4.0 restore") |
| 42 | try { |
| 43 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'doctrail controller systemctl stop contrail-database' ) |
| 44 | } catch (Exception err) { |
| 45 | common.warningMsg('contrail-database already stopped? ' + err.getMessage()) |
| 46 | } |
| 47 | try { |
| 48 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'doctrail controller bash -c "for f in $(ls /var/lib/cassandra/); do rm -r /var/lib/cassandra/$f; done"') |
| 49 | } catch (Exception err) { |
| 50 | common.warningMsg('cassandra data already removed? ' + err.getMessage()) |
| 51 | } |
| 52 | try { |
| 53 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'doctrail controller systemctl start contrail-database' ) |
| 54 | } catch (Exception err) { |
| 55 | common.warningMsg('contrail-database already started? ' + err.getMessage()) |
| 56 | } |
| 57 | // remove restore-already-happenned file if any is present |
| 58 | try { |
| 59 | salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored') |
| 60 | } catch (Exception err) { |
| 61 | common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage()) |
| 62 | } |
| 63 | // perform actual backup |
| 64 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra") |
| 65 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, [], true, 5) |
| 66 | sleep(5) |
| 67 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, [], true, 5) |
| 68 | // the lovely wait-60-seconds mantra before restarting supervisor-database service |
| 69 | sleep(60) |
| 70 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "doctrail controller systemctl restart contrail-database") |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame^] | 71 | // another mantra, wait till all services are up |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 72 | sleep(60) |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame^] | 73 | } else { |
Inessa Vasilevskaya | ea45439 | 2018-09-07 17:25:34 +0200 | [diff] [blame] | 74 | try { |
| 75 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true) |
| 76 | } catch (Exception er) { |
| 77 | common.warningMsg('neutron-server service already stopped') |
| 78 | } |
| 79 | try { |
| 80 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true) |
| 81 | } catch (Exception er) { |
| 82 | common.warningMsg('Supervisor-config service already stopped') |
| 83 | } |
| 84 | // Cassandra restore section |
| 85 | try { |
| 86 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true) |
| 87 | } catch (Exception er) { |
| 88 | common.warningMsg('Supervisor-database service already stopped') |
| 89 | } |
| 90 | try { |
| 91 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak") |
| 92 | } catch (Exception er) { |
| 93 | common.warningMsg('Directory already exists') |
| 94 | } |
| 95 | |
| 96 | try { |
| 97 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
| 98 | } catch (Exception er) { |
| 99 | common.warningMsg('Files were already moved') |
| 100 | } |
| 101 | try { |
| 102 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*") |
| 103 | } catch (Exception er) { |
| 104 | common.warningMsg('Directory already empty') |
| 105 | } |
| 106 | |
| 107 | _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir') |
| 108 | def backupDir = _pillar['return'][0].values()[0] ?: '/var/backups/cassandra' |
| 109 | common.infoMsg("Backup directory is ${backupDir}") |
| 110 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true) |
| 111 | |
| 112 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true) |
| 113 | |
| 114 | // wait until supervisor-database service is up |
| 115 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 116 | sleep(60) |
| 117 | |
| 118 | // performs restore |
| 119 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup") |
| 120 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 121 | sleep(5) |
| 122 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 123 | |
| 124 | // wait until supervisor-database service is up |
| 125 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 126 | salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 127 | sleep(5) |
| 128 | |
| 129 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
| 130 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true) |
| 131 | |
| 132 | // wait until contrail-status is up |
| 133 | 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) |
| 134 | |
| 135 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status") |
| 136 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 137 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 138 | } |
Inessa Vasilevskaya | b0d2503 | 2018-10-22 08:45:26 +0200 | [diff] [blame^] | 139 | |
| 140 | stage('Opencontrail controllers health check') { |
| 141 | common.retry(3, 20){ |
| 142 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "doctrail controller contrail-status") |
| 143 | salt.enforceState(pepperEnv, 'I@opencontrail:control or I@opencontrail:collector', 'opencontrail.upgrade.verify', true, true) |
| 144 | } |
| 145 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 146 | } |
| 147 | } |