blob: d3591b1e8a99203dfc8bc06485fc6973db8e292f [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 = []
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030017
18timeout(time: 12, unit: 'HOURS') {
19 node() {
20 try {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030021 def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon",
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040022 "mgr" : "ceph-mgr", "radosgw": "radosgw"]
Alena Kiselevaf99b1162019-06-12 13:16:33 +030023
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030024 stage('Setup virtualenv for Pepper') {
25 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
26 }
27
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030028 stage('Apply package upgrades on all nodes') {
29
Alena Kiselevaf99b1162019-06-12 13:16:33 +030030 targets.each { key, value ->
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040031 // 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 Kiseleva895bc7a2018-12-07 17:03:02 +030038 }
39 }
40
41 stage("Restart MONs and RGWs") {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030042 selMinions = salt.getMinions(pepperEnv, "I@ceph:mon")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030043 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030044 // runSaltProcessStep 'service.restart' don't work for this services
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040045 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target")
46 ceph.waitForHealthy(pepperEnv, tgt)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030047 }
48 selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw")
49 for (tgt in selMinions) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040050 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target")
51 ceph.waitForHealthy(pepperEnv, tgt)
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030052 }
53 }
54
55 stage('Restart OSDs') {
56
Alena Kiselevaf99b1162019-06-12 13:16:33 +030057 selMinions = salt.getMinions(pepperEnv, "I@ceph:osd")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030058 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030059 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 Kiseleva895bc7a2018-12-07 17:03:02 +030061
Alena Kiselevaf99b1162019-06-12 13:16:33 +030062 def osd_ids = []
63 for (i in ceph_disks) {
64 def osd_id = i.getKey().toString()
65 osd_ids.add('osd.' + osd_id)
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030066 }
Alena Kiselevaf99b1162019-06-12 13:16:33 +030067
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040068 salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout')
Alena Kiselevaf99b1162019-06-12 13:16:33 +030069
70 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040071 salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030072 // wait for healthy cluster
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040073 ceph.waitForHealthy(pepperEnv, tgt, ['noout'], 0, 100)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030074 }
75
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040076 salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout')
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030077 }
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}