blob: 5fff159dfeee2d39f0fcd4952c85f4ba9bd46476 [file] [log] [blame]
Jiri Broulikf2abf422017-07-03 17:04:19 +02001/**
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
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
chnyda625f4b42017-10-11 14:10:31 +020012def python = new com.mirantis.mk.Python()
Jiri Broulikf2abf422017-07-03 17:04:19 +020013
chnyda625f4b42017-10-11 14:10:31 +020014def pepperEnv = "pepperEnv"
Jiri Broulikf2abf422017-07-03 17:04:19 +020015
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040016node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020017
chnyda625f4b42017-10-11 14:10:31 +020018 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040020 }
21
22 stage('Start restore') {
23 // # actual upgrade
24
25 stage('Ask for manual confirmation') {
26 input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Cassandra?"
27 }
28 // Cassandra restore section
29 try {
chnyda625f4b42017-10-11 14:10:31 +020030 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040031 } catch (Exception er) {
32 common.warningMsg('Supervisor-database service already stopped')
33 }
34 try {
chnyda625f4b42017-10-11 14:10:31 +020035 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040036 } catch (Exception er) {
37 common.warningMsg('Directory already exists')
Jiri Broulikf2abf422017-07-03 17:04:19 +020038 }
39
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040040 try {
chnyda625f4b42017-10-11 14:10:31 +020041 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040042 } catch (Exception er) {
43 common.warningMsg('Files were already moved')
Jiri Broulikf2abf422017-07-03 17:04:19 +020044 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040045 try {
chnyda625f4b42017-10-11 14:10:31 +020046 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040047 } catch (Exception er) {
48 common.warningMsg('Directory already empty')
49 }
50
chnyda625f4b42017-10-11 14:10:31 +020051 _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040052 backup_dir = _pillar['return'][0].values()[0]
53 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' }
54 print(backup_dir)
chnyda625f4b42017-10-11 14:10:31 +020055 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040056
chnyda625f4b42017-10-11 14:10:31 +020057 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040058
59 // wait until supervisor-database service is up
chnyda625f4b42017-10-11 14:10:31 +020060 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020061 sleep(5)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040062 // performs restore
chnyda625f4b42017-10-11 14:10:31 +020063 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c 'salt-call state.sls cassandra'")
64 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
65 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040066
67 // wait until supervisor-database service is up
chnyda625f4b42017-10-11 14:10:31 +020068 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
69 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040070 sleep(5)
71
chnyda625f4b42017-10-11 14:10:31 +020072 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040073
74 // wait until contrail-status is up
chnyda625f4b42017-10-11 14:10:31 +020075 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)
Jiri Broulik3bf1d5c2017-08-11 12:31:37 +020076
chnyda625f4b42017-10-11 14:10:31 +020077 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
78 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulikf2abf422017-07-03 17:04:19 +020079 }
80}