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" |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 15 | |
| 16 | def oc3SupervisorServices = ["supervisor-config", "supervisor-control"] |
| 17 | def oc4ConfigServices = ["contrail-api", "contrail-schema", "contrail-svc-monitor", "contrail-device-manager", "contrail-config-nodemgr"] |
| 18 | def oc4ControlServices = ["contrail-control", "contrail-named", "contrail-dns", "contrail-control-nodemgr"] |
| 19 | def zkService = "zookeeper" |
| 20 | def contrailStatusCheckCmd = "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup" |
| 21 | def zkDbPath = "/var/lib/zookeeper/version-2" |
| 22 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 23 | timeout(time: 12, unit: 'HOURS') { |
| 24 | node() { |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 25 | |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 26 | stage('Setup virtualenv for Pepper') { |
| 27 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 30 | stage('Restore') { |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 31 | |
| 32 | def ocVersionPillarKey = salt.getReturnValues(salt.getPillar(pepperEnv, "I@opencontrail:control:role:primary", "_param:opencontrail_version")) |
| 33 | |
| 34 | if (ocVersionPillarKey == '') { |
| 35 | throw new Exception("Cannot get value for _param:opencontrail_version key on I@opencontrail:control:role:primary target") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 36 | } |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 37 | |
| 38 | def ocVersion = ocVersionPillarKey.toString() |
| 39 | |
| 40 | if (ocVersion >= "4.0") { |
| 41 | |
| 42 | contrailStatusCheckCmd = "doctrail controller ${contrailStatusCheckCmd}" |
| 43 | zkDbPath = "/var/lib/config_zookeeper_data/version-2" |
| 44 | |
| 45 | for (service in (oc4ConfigServices + oc4ControlServices + [zkService])) { |
| 46 | try { |
| 47 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.run', ["doctrail controller systemctl stop ${service}"]) |
| 48 | } catch (Exception er) { |
| 49 | common.warningMsg("${service} cannot be stopped inside controller container") |
| 50 | } |
| 51 | } |
| 52 | // wait until zookeeper service is down |
| 53 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', "doctrail controller service ${zkService} status", 'Active: inactive') |
| 54 | } else { |
| 55 | for (service in (oc3SupervisorServices + [zkService])) { |
| 56 | try { |
| 57 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.stop', ["${service}"]) |
| 58 | } catch (Exception er) { |
| 59 | common.warningMsg("${service} service cannot be stopped. It may be already stopped before.") |
| 60 | } |
| 61 | } |
| 62 | // wait until zookeeper service is down |
| 63 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', "service ${zkService} status", "stop") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 64 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 65 | |
| 66 | try { |
| 67 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak") |
| 68 | } catch (Exception er) { |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 69 | common.warningMsg('/root/zookeeper/zookeeper.bak directory already exists') |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | try { |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 73 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "mv ${zkDbPath}/* /root/zookeeper/zookeeper.bak") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 74 | } catch (Exception er) { |
| 75 | common.warningMsg('Files were already moved') |
| 76 | } |
| 77 | try { |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 78 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "rm -rf ${zkDbPath}/*") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 79 | } catch (Exception er) { |
| 80 | common.warningMsg('Directory already empty') |
| 81 | } |
| 82 | |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 83 | backupDirPillarKey = salt.getPillar(pepperEnv, "I@opencontrail:control", 'zookeeper:backup:backup_dir') |
| 84 | backupDir = backupDirPillarKey['return'][0].values()[0] |
| 85 | if (backupDir == null || backupDir.isEmpty()) { backupDir='/var/backups/zookeeper' } |
| 86 | print(backupDir) |
| 87 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'file.remove', ["${backupDir}/dbrestored"]) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 88 | |
| 89 | // performs restore |
Jiri Broulik | 5d4dd2c | 2018-04-16 17:50:07 +0200 | [diff] [blame] | 90 | salt.enforceState(pepperEnv, 'I@opencontrail:control', "zookeeper.backup") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 91 | |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 92 | if (ocVersion >= "4.0") { |
| 93 | for (service in ([zkService] + oc4ConfigServices + oc4ControlServices)) { |
| 94 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'cmd.run', ["doctrail controller systemctl start ${service}"]) |
| 95 | } |
| 96 | } else { |
| 97 | for (service in ([zkService] + oc3SupervisorServices)) { |
| 98 | salt.runSaltProcessStep(pepperEnv, 'I@opencontrail:control', 'service.start', ["${service}"]) |
| 99 | } |
| 100 | } |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 101 | |
| 102 | // wait until contrail-status is up |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 103 | salt.commandStatus(pepperEnv, 'I@opencontrail:control', contrailStatusCheckCmd, null, false) |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 104 | |
Anton Samoylov | 9c3f1ac | 2019-02-19 23:12:51 +0400 | [diff] [blame^] | 105 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "ls ${zkDbPath}") |
Jakub Josef | a63f986 | 2018-01-11 17:58:38 +0100 | [diff] [blame] | 106 | try { |
| 107 | salt.cmdRun(pepperEnv, 'I@opencontrail:control', "echo stat | nc localhost 2181") |
| 108 | } catch (Exception er) { |
| 109 | common.warningMsg('Check which node is zookeeper leader') |
| 110 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | } |