blob: c20c3a00495dd125f4b88997622b7b65aaa7140d [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
Jiri Broulik5d4dd2c2018-04-16 17:50:07 +020022 stage('Restore') {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020023 // get opencontrail version
24 def _pillar = salt.getPillar(pepperEnv, "I@opencontrail:control", '_param:opencontrail_version')
25 def contrailVersion = _pillar['return'][0].values()[0]
26 common.infoMsg("Contrail version is ${contrailVersion}")
27 if (contrailVersion >= 4) {
28 common.infoMsg("There will be steps for OC4.0 restore")
29 try {
30 salt.cmdRun(pepperEnv, 'I@opencontrail:control', 'doctrail controller systemctl stop contrail-database' )
31 } catch (Exception err) {
32 common.warningMsg('contrail-database already stopped? ' + err.getMessage())
33 }
34 try {
35 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"')
36 } catch (Exception err) {
37 common.warningMsg('cassandra data already removed? ' + err.getMessage())
38 }
39 try {
40 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'doctrail controller systemctl start contrail-database' )
41 } catch (Exception err) {
42 common.warningMsg('contrail-database already started? ' + err.getMessage())
43 }
44 // remove restore-already-happenned file if any is present
45 try {
46 salt.cmdRun(pepperEnv, 'I@cassandra:backup:client', 'rm /var/backups/cassandra/dbrestored')
47 } catch (Exception err) {
48 common.warningMsg('/var/backups/cassandra/dbrestored not present? ' + err.getMessage())
49 }
50 // perform actual backup
51 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra")
52 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, [], true, 5)
53 sleep(5)
54 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, [], true, 5)
55 // the lovely wait-60-seconds mantra before restarting supervisor-database service
56 sleep(60)
57 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "doctrail controller systemctl restart contrail-database")
58 // another mantra
59 sleep(60)
60 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "doctrail controller contrail-status")
Jiri Broulik60dcab32018-03-08 17:42:06 +010061 }
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020062 else {
63 try {
64 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true)
65 } catch (Exception er) {
66 common.warningMsg('neutron-server service already stopped')
67 }
68 try {
69 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
70 } catch (Exception er) {
71 common.warningMsg('Supervisor-config service already stopped')
72 }
73 // Cassandra restore section
74 try {
75 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true)
76 } catch (Exception er) {
77 common.warningMsg('Supervisor-database service already stopped')
78 }
79 try {
80 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
81 } catch (Exception er) {
82 common.warningMsg('Directory already exists')
83 }
84
85 try {
86 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak")
87 } catch (Exception er) {
88 common.warningMsg('Files were already moved')
89 }
90 try {
91 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*")
92 } catch (Exception er) {
93 common.warningMsg('Directory already empty')
94 }
95
96 _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir')
97 def backupDir = _pillar['return'][0].values()[0] ?: '/var/backups/cassandra'
98 common.infoMsg("Backup directory is ${backupDir}")
99 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backupDir}/dbrestored"], null, true)
100
101 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
102
103 // wait until supervisor-database service is up
104 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
105 sleep(60)
106
107 // performs restore
108 salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup")
109 salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
110 sleep(5)
111 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5)
112
113 // wait until supervisor-database service is up
114 salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
115 salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
116 sleep(5)
117
118 salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
119 salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true)
120
121 // wait until contrail-status is up
122 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)
123
124 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status")
125 salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status")
Jiri Broulik60dcab32018-03-08 17:42:06 +0100126 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200127 }
128 }
129}