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" |
| 10 | salt = new com.mirantis.mk.Salt() |
| 11 | def common = new com.mirantis.mk.Common() |
| 12 | def python = new com.mirantis.mk.Python() |
| 13 | def targetLiveSubset |
| 14 | def targetLiveAll |
| 15 | def minions |
| 16 | def result |
| 17 | def packages |
| 18 | def command |
| 19 | def commandKwargs |
| 20 | def selMinions = [] |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 21 | def check_mon |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 22 | |
| 23 | def runCephCommand(master, target, cmd) { |
| 24 | return salt.cmdRun(master, target, cmd) |
| 25 | } |
| 26 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 27 | def waitForHealthy(master, tgt, count = 0, attempts=100) { |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 28 | // wait for healthy cluster |
| 29 | common = new com.mirantis.mk.Common() |
Alena Kiseleva | a6afc5a | 2019-05-16 16:00:14 +0300 | [diff] [blame] | 30 | while (count<attempts) { |
Martin Polreich | bf174c9 | 2019-06-17 11:02:07 +0200 | [diff] [blame] | 31 | def health = runCephCommand(master, tgt, 'ceph health')['return'][0].values()[0] |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 32 | if (health.contains('HEALTH_OK') || health.contains('HEALTH_WARN noout flag(s) set\n')) { |
| 33 | common.infoMsg('Cluster is healthy') |
Alena Kiseleva | a6afc5a | 2019-05-16 16:00:14 +0300 | [diff] [blame] | 34 | break; |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 35 | } |
Alena Kiseleva | a6afc5a | 2019-05-16 16:00:14 +0300 | [diff] [blame] | 36 | count++ |
| 37 | sleep(10) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
| 41 | timeout(time: 12, unit: 'HOURS') { |
| 42 | node() { |
| 43 | try { |
| 44 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 45 | def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon", |
| 46 | "mgr":"ceph-mgr", "radosgw": "radosgw"] |
| 47 | |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 48 | stage('Setup virtualenv for Pepper') { |
| 49 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 50 | } |
| 51 | |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 52 | stage('Apply package upgrades on all nodes') { |
| 53 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 54 | targets.each { key, value -> |
| 55 | // try { |
| 56 | command = "pkg.install" |
| 57 | packages = value |
| 58 | commandKwargs = ['only_upgrade': 'true','force_yes': 'true'] |
| 59 | target = "I@ceph:${key}" |
| 60 | out = salt.runSaltCommand(pepperEnv, 'local', ['expression': target, 'type': 'compound'], command, true, packages, commandKwargs) |
| 61 | salt.printSaltCommandResult(out) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | stage("Restart MONs and RGWs") { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 66 | selMinions = salt.getMinions(pepperEnv, "I@ceph:mon") |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 67 | for (tgt in selMinions) { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 68 | // runSaltProcessStep 'service.restart' don't work for this services |
| 69 | runCephCommand(pepperEnv, tgt, "systemctl restart ceph-mon.target") |
| 70 | waitForHealthy(pepperEnv, tgt) |
| 71 | } |
| 72 | selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw") |
| 73 | for (tgt in selMinions) { |
| 74 | runCephCommand(pepperEnv, tgt, "systemctl restart ceph-radosgw.target") |
| 75 | waitForHealthy(pepperEnv, tgt) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 76 | } |
| 77 | } |
| 78 | |
| 79 | stage('Restart OSDs') { |
| 80 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 81 | selMinions = salt.getMinions(pepperEnv, "I@ceph:osd") |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 82 | for (tgt in selMinions) { |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 83 | salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5) |
| 84 | 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] | 85 | |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 86 | def osd_ids = [] |
| 87 | for (i in ceph_disks) { |
| 88 | def osd_id = i.getKey().toString() |
| 89 | osd_ids.add('osd.' + osd_id) |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 90 | } |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 91 | |
| 92 | runCephCommand(pepperEnv, tgt, 'ceph osd set noout') |
| 93 | |
| 94 | for (i in osd_ids) { |
| 95 | salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true) |
| 96 | // wait for healthy cluster |
| 97 | waitForHealthy(pepperEnv, tgt) |
| 98 | } |
| 99 | |
| 100 | runCephCommand(pepperEnv, tgt, 'ceph osd unset noout') |
Alena Kiseleva | 3a49b80 | 2018-12-07 17:03:02 +0300 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | } catch (Throwable e) { |
| 106 | // If there was an error or exception thrown, the build failed |
| 107 | currentBuild.result = "FAILURE" |
| 108 | currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message |
| 109 | throw e |
| 110 | } |
| 111 | } |
Alena Kiseleva | 7f3c386 | 2019-06-12 13:16:33 +0300 | [diff] [blame] | 112 | } |