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