blob: 10ec3786c39bdf2595c8e4cc78335a8b5a06acf5 [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"
Jakub Josefa63f9862018-01-11 17:58:38 +010015timeout(time: 12, unit: 'HOURS') {
16 node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020017
Jakub Josefa63f9862018-01-11 17:58:38 +010018 stage('Setup virtualenv for Pepper') {
19 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
Jiri Broulikf2abf422017-07-03 17:04:19 +020020 }
21
Jakub Josefa63f9862018-01-11 17:58:38 +010022 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 }
Jiri Broulik60dcab32018-03-08 17:42:06 +010028 try {
29 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true)
30 } catch (Exception er) {
31 common.warningMsg('neutron-server service already stopped')
32 }
33 try {
34 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
35 } catch (Exception er) {
36 common.warningMsg('Supervisor-config service already stopped')
37 }
Jakub Josefa63f9862018-01-11 17:58:38 +010038 // Cassandra restore section
39 try {
40 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
41 } catch (Exception er) {
42 common.warningMsg('Supervisor-database service already stopped')
43 }
44 try {
45 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
46 } catch (Exception er) {
47 common.warningMsg('Directory already exists')
48 }
49
50 try {
51 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
52 } catch (Exception er) {
53 common.warningMsg('Files were already moved')
54 }
55 try {
56 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
57 } catch (Exception er) {
58 common.warningMsg('Directory already empty')
59 }
60
61 _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir')
62 backup_dir = _pillar['return'][0].values()[0]
63 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' }
64 print(backup_dir)
65 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
66
67 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
68
69 // wait until supervisor-database service is up
70 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
71 sleep(5)
72 // performs restore
73 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', "su root -c 'salt-call state.sls cassandra'")
74 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
75 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
76
77 // wait until supervisor-database service is up
78 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
79 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
80 sleep(5)
81
82 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
Jiri Broulik60dcab32018-03-08 17:42:06 +010083 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true)
Jakub Josefa63f9862018-01-11 17:58:38 +010084
85 // wait until contrail-status is up
86 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)
87
88 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
89 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulikf2abf422017-07-03 17:04:19 +020090 }
91 }
92}