Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 1 | /** |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 2 | * Update packages |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [https://10.10.10.1:8000]. |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | pepperEnv = "pepperEnv" |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 10 | def salt = new com.mirantis.mk.Salt() |
| 11 | def ceph = new com.mirantis.mk.Ceph() |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 12 | def python = new com.mirantis.mk.Python() |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 13 | def packages |
| 14 | def command |
| 15 | def commandKwargs |
| 16 | def selMinions = [] |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 17 | def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : [] |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 18 | def runHighState = RUNHIGHSTATE |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 19 | |
| 20 | timeout(time: 12, unit: 'HOURS') { |
| 21 | node() { |
| 22 | try { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 23 | def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon", |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 24 | "mgr" : "ceph-mgr", "radosgw": "radosgw"] |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 25 | |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 26 | stage('Setup virtualenv for Pepper') { |
| 27 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 28 | } |
| 29 | |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 30 | stage('Apply package upgrades on all nodes') { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 31 | targets.each { key, value -> |
Mateusz Los | 66e4390 | 2020-05-11 10:22:53 +0200 | [diff] [blame] | 32 | salt.enforceState(pepperEnv, "I@ceph:${key}", 'linux.system.repo', true) |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 33 | command = "pkg.install" |
| 34 | packages = value |
| 35 | commandKwargs = ['only_upgrade': 'true', 'force_yes': 'true'] |
| 36 | target = "I@ceph:${key}" |
| 37 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, true, packages, commandKwargs) |
| 38 | salt.printSaltCommandResult(out) |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 42 | stage('Set cluster flags') { |
| 43 | if (flags.size() > 0) { |
| 44 | stage('Set cluster flags') { |
| 45 | for (flag in flags) { |
| 46 | salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", 'ceph osd set ' + flag) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | stage("Restart MONs") { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 53 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mon") |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 54 | for (tgt in selMinions) { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 55 | // runSaltProcessStep 'service.restart' don't work for this services |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 56 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target") |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 57 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 58 | if (runHighState) { |
| 59 | salt.enforceHighstate(pepperEnv, tgt) |
| 60 | } |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 61 | } |
Mateusz Los | 0d09819 | 2020-01-31 13:11:55 +0100 | [diff] [blame] | 62 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mgr") |
| 63 | for (tgt in selMinions) { |
| 64 | // runSaltProcessStep 'service.restart' don't work for this services |
| 65 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mgr.target") |
| 66 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 67 | if (runHighState) { |
| 68 | salt.enforceHighstate(pepperEnv, tgt) |
| 69 | } |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | stage('Restart OSDs') { |
Mateusz Los | 2ae66db | 2020-04-28 16:36:11 +0200 | [diff] [blame] | 74 | def device_grain_name = "ceph_disk" |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 75 | selMinions = salt.getMinions(pepperEnv, "I@ceph:osd") |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 76 | for (tgt in selMinions) { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 77 | salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5) |
mjedynski | 12955c7 | 2019-12-09 15:17:58 +0100 | [diff] [blame] | 78 | def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0][device_grain_name] |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 79 | |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 80 | def osd_ids = [] |
| 81 | for (i in ceph_disks) { |
| 82 | def osd_id = i.getKey().toString() |
| 83 | osd_ids.add('osd.' + osd_id) |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 84 | } |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 85 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 86 | salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout') |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 87 | flags = 'noout' in flags ? flags : flags + ['noout'] |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 88 | |
| 89 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 90 | salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 91 | // wait for healthy cluster |
Tomek Jaroszyk | 08ad67e | 2020-11-09 13:58:02 +0100 | [diff] [blame] | 92 | ceph.waitForHealthy(pepperEnv, tgt, flags, 100) |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 93 | } |
| 94 | |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 95 | if (runHighState) { |
| 96 | salt.enforceHighstate(pepperEnv, tgt) |
| 97 | } |
| 98 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 99 | salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout') |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Mateusz Los | c5de5c8 | 2020-05-11 10:37:23 +0200 | [diff] [blame] | 103 | stage('Restart RGWs') { |
| 104 | selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw") |
| 105 | for (tgt in selMinions) { |
| 106 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target") |
| 107 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
| 108 | if (runHighState) { |
| 109 | salt.enforceHighstate(pepperEnv, tgt) |
| 110 | } |
| 111 | } |
| 112 | } |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 113 | } catch (Throwable e) { |
| 114 | // If there was an error or exception thrown, the build failed |
Mateusz Los | 0584976 | 2020-05-11 09:59:32 +0200 | [diff] [blame] | 115 | if (flags.size() > 0) { |
| 116 | stage('Unset cluster flags') { |
| 117 | for (flag in flags) { |
| 118 | salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", 'ceph osd unset ' + flag) |
| 119 | } |
| 120 | } |
| 121 | } |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 122 | currentBuild.result = "FAILURE" |
| 123 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 124 | throw e |
| 125 | } |
| 126 | } |
Tomek Jaroszyk | 6d8a3aa | 2020-07-07 12:07:40 +0200 | [diff] [blame] | 127 | } |