Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 1 | /** |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 2 | * Update packages |
Alena Kiseleva | 3a49b80 | 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 | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | pepperEnv = "pepperEnv" |
Ivan Berezovskiy | 2325dcb | 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 | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 12 | def python = new com.mirantis.mk.Python() |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 13 | def packages |
| 14 | def command |
| 15 | def commandKwargs |
| 16 | def selMinions = [] |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 17 | def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : [] |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 18 | |
| 19 | timeout(time: 12, unit: 'HOURS') { |
| 20 | node() { |
| 21 | try { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 22 | def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon", |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 23 | "mgr" : "ceph-mgr", "radosgw": "radosgw"] |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 24 | |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 25 | stage('Setup virtualenv for Pepper') { |
| 26 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 27 | } |
| 28 | |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 29 | stage('Apply package upgrades on all nodes') { |
| 30 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 31 | targets.each { key, value -> |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 32 | // try { |
| 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 | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | stage("Restart MONs and RGWs") { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 43 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mon") |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 44 | for (tgt in selMinions) { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 45 | // runSaltProcessStep 'service.restart' don't work for this services |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 46 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target") |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 47 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 48 | } |
Mateusz Los | 0493d5a | 2020-01-31 13:11:55 +0100 | [diff] [blame^] | 49 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mgr") |
| 50 | for (tgt in selMinions) { |
| 51 | // runSaltProcessStep 'service.restart' don't work for this services |
| 52 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mgr.target") |
| 53 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
| 54 | } |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 55 | selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw") |
| 56 | for (tgt in selMinions) { |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 57 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target") |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 58 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | stage('Restart OSDs') { |
| 63 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 64 | selMinions = salt.getMinions(pepperEnv, "I@ceph:osd") |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 65 | for (tgt in selMinions) { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 66 | salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5) |
| 67 | def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk'] |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 68 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 69 | def osd_ids = [] |
| 70 | for (i in ceph_disks) { |
| 71 | def osd_id = i.getKey().toString() |
| 72 | osd_ids.add('osd.' + osd_id) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 73 | } |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 74 | |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 75 | salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout') |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 76 | flags = 'noout' in flags ? flags : flags + ['noout'] |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 77 | |
| 78 | for (i in osd_ids) { |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 79 | salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 80 | // wait for healthy cluster |
Ivan Berezovskiy | 373e8a3 | 2019-11-19 20:04:12 +0400 | [diff] [blame] | 81 | ceph.waitForHealthy(pepperEnv, tgt, flags, 0, 100) |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 82 | } |
| 83 | |
Ivan Berezovskiy | 2325dcb | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 84 | salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout') |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | } catch (Throwable e) { |
| 90 | // If there was an error or exception thrown, the build failed |
| 91 | currentBuild.result = "FAILURE" |
| 92 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 93 | throw e |
| 94 | } |
| 95 | } |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 96 | } |