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 | |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 22 | stage('Restore') { |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 23 | try { |
| 24 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.stop', ['neutron-server'], null, true) |
| 25 | } catch (Exception er) { |
| 26 | common.warningMsg('neutron-server service already stopped') |
| 27 | } |
| 28 | try { |
| 29 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true) |
| 30 | } catch (Exception er) { |
| 31 | common.warningMsg('Supervisor-config service already stopped') |
| 32 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 33 | // Cassandra restore section |
| 34 | try { |
| 35 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true) |
| 36 | } catch (Exception er) { |
| 37 | common.warningMsg('Supervisor-database service already stopped') |
| 38 | } |
| 39 | try { |
| 40 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak") |
| 41 | } catch (Exception er) { |
| 42 | common.warningMsg('Directory already exists') |
| 43 | } |
| 44 | |
| 45 | try { |
| 46 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
| 47 | } catch (Exception er) { |
| 48 | common.warningMsg('Files were already moved') |
| 49 | } |
| 50 | try { |
| 51 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*") |
| 52 | } catch (Exception er) { |
| 53 | common.warningMsg('Directory already empty') |
| 54 | } |
| 55 | |
| 56 | _pillar = salt.getPillar(pepperEnv, "I@cassandra:backup:client", 'cassandra:backup:backup_dir') |
| 57 | backup_dir = _pillar['return'][0].values()[0] |
| 58 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' } |
| 59 | print(backup_dir) |
| 60 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 61 | |
| 62 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true) |
| 63 | |
| 64 | // wait until supervisor-database service is up |
| 65 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 66 | sleep(60) |
| 67 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 68 | // performs restore |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 69 | salt.enforceState(pepperEnv, 'I@cassandra:backup:client', "cassandra.backup") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | salt.runSaltProcessStep(pepperEnv, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 71 | sleep(5) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 72 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 73 | |
| 74 | // wait until supervisor-database service is up |
| 75 | salt.commandStatus(pepperEnv, 'I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 76 | salt.commandStatus(pepperEnv, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running') |
| 77 | sleep(5) |
| 78 | |
| 79 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
Jiri Broulik | 60dcab3 | 2018-03-08 17:42:06 +0100 | [diff] [blame] | 80 | salt.runSaltProcessStep(pepperEnv, 'I@neutron:server', 'service.start', ['neutron-server'], null, true) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 81 | |
| 82 | // wait until contrail-status is up |
| 83 | 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) |
| 84 | |
| 85 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "nodetool status") |
| 86 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "contrail-status") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |