blob: b585e7e55e34230581cc9ac658eff5ff08b59374 [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
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020022 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 Broulik5d4dd2c2018-04-16 17:50:07 +020035 stage('Restore') {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020036 // 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 Vasilevskayab0d25032018-10-22 08:45:26 +020071 // another mantra, wait till all services are up
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020072 sleep(60)
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +020073 } else {
Inessa Vasilevskayaea454392018-09-07 17:25:34 +020074 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 Broulik60dcab32018-03-08 17:42:06 +0100137 }
Jiri Broulikf2abf422017-07-03 17:04:19 +0200138 }
Inessa Vasilevskayab0d25032018-10-22 08:45:26 +0200139
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 Broulikf2abf422017-07-03 17:04:19 +0200146 }
147}