blob: 7cf92424b79aac68ab6e307e47d3304f89ff9f41 [file] [log] [blame]
Alena Kiseleva895bc7a2018-12-07 17:03:02 +03001/**
Alena Kiselevaf99b1162019-06-12 13:16:33 +03002 * Update packages
Alena Kiseleva895bc7a2018-12-07 17:03:02 +03003 *
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 Kiseleva895bc7a2018-12-07 17:03:02 +03007 */
8
9pepperEnv = "pepperEnv"
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040010def salt = new com.mirantis.mk.Salt()
11def ceph = new com.mirantis.mk.Ceph()
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030012def python = new com.mirantis.mk.Python()
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030013def packages
14def command
15def commandKwargs
16def selMinions = []
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040017def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : []
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030018
19timeout(time: 12, unit: 'HOURS') {
20 node() {
21 try {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030022 def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon",
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040023 "mgr" : "ceph-mgr", "radosgw": "radosgw"]
Alena Kiselevaf99b1162019-06-12 13:16:33 +030024
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030025 stage('Setup virtualenv for Pepper') {
26 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
27 }
28
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030029 stage('Apply package upgrades on all nodes') {
30
Alena Kiselevaf99b1162019-06-12 13:16:33 +030031 targets.each { key, value ->
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040032 // 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 Kiseleva895bc7a2018-12-07 17:03:02 +030039 }
40 }
41
42 stage("Restart MONs and RGWs") {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030043 selMinions = salt.getMinions(pepperEnv, "I@ceph:mon")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030044 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030045 // runSaltProcessStep 'service.restart' don't work for this services
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040046 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target")
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040047 ceph.waitForHealthy(pepperEnv, tgt, flags)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030048 }
49 selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw")
50 for (tgt in selMinions) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040051 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target")
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040052 ceph.waitForHealthy(pepperEnv, tgt, flags)
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030053 }
54 }
55
56 stage('Restart OSDs') {
57
Alena Kiselevaf99b1162019-06-12 13:16:33 +030058 selMinions = salt.getMinions(pepperEnv, "I@ceph:osd")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030059 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030060 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 Kiseleva895bc7a2018-12-07 17:03:02 +030062
Alena Kiselevaf99b1162019-06-12 13:16:33 +030063 def osd_ids = []
64 for (i in ceph_disks) {
65 def osd_id = i.getKey().toString()
66 osd_ids.add('osd.' + osd_id)
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030067 }
Alena Kiselevaf99b1162019-06-12 13:16:33 +030068
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040069 salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout')
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040070 flags = 'noout' in flags ? flags : flags + ['noout']
Alena Kiselevaf99b1162019-06-12 13:16:33 +030071
72 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040073 salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030074 // wait for healthy cluster
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040075 ceph.waitForHealthy(pepperEnv, tgt, flags, 0, 100)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030076 }
77
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040078 salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout')
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030079 }
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}