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(',') : [] |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 18 | |
| 19 | timeout(time: 12, unit: 'HOURS') { |
| 20 | node() { |
| 21 | try { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 22 | def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon", |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 23 | "mgr" : "ceph-mgr", "radosgw": "radosgw"] |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 24 | |
Alena Kiseleva | 895bc7a | 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 | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 29 | stage('Apply package upgrades on all nodes') { |
| 30 | |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 31 | targets.each { key, value -> |
Ivan Berezovskiy | 19c685a | 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 | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | stage("Restart MONs and RGWs") { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 43 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mon") |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 44 | for (tgt in selMinions) { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 45 | // runSaltProcessStep 'service.restart' don't work for this services |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 46 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target") |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame^] | 47 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 48 | } |
| 49 | selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw") |
| 50 | for (tgt in selMinions) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 51 | salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target") |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame^] | 52 | ceph.waitForHealthy(pepperEnv, tgt, flags) |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | stage('Restart OSDs') { |
| 57 | |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 58 | selMinions = salt.getMinions(pepperEnv, "I@ceph:osd") |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 59 | for (tgt in selMinions) { |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 60 | salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5) |
| 61 | def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0]['ceph_disk'] |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 62 | |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 63 | def osd_ids = [] |
| 64 | for (i in ceph_disks) { |
| 65 | def osd_id = i.getKey().toString() |
| 66 | osd_ids.add('osd.' + osd_id) |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 67 | } |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 68 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 69 | salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout') |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame^] | 70 | flags = 'noout' in flags ? flags : flags + ['noout'] |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 71 | |
| 72 | for (i in osd_ids) { |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 73 | 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] | 74 | // wait for healthy cluster |
Ivan Berezovskiy | 4c39c7d | 2019-11-19 20:04:12 +0400 | [diff] [blame^] | 75 | ceph.waitForHealthy(pepperEnv, tgt, flags, 0, 100) |
Alena Kiseleva | f99b116 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 76 | } |
| 77 | |
Ivan Berezovskiy | 19c685a | 2019-11-05 17:42:57 +0400 | [diff] [blame] | 78 | salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout') |
Alena Kiseleva | 895bc7a | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | } catch (Throwable e) { |
| 84 | // If there was an error or exception thrown, the build failed |
| 85 | currentBuild.result = "FAILURE" |
| 86 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 87 | throw e |
| 88 | } |
| 89 | } |
| 90 | } |