blob: 00c16b36a8bcfdcf8a409cd2b46d4b331ac5e361 [file] [log] [blame]
Alena Kiseleva3a49b802018-12-07 17:03:02 +03001/**
Alena Kiseleva7f3c3862019-06-12 13:16:33 +03002 * Update packages
Alena Kiseleva3a49b802018-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 Kiseleva3a49b802018-12-07 17:03:02 +03007 */
8
9pepperEnv = "pepperEnv"
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040010def salt = new com.mirantis.mk.Salt()
11def ceph = new com.mirantis.mk.Ceph()
Alena Kiseleva3a49b802018-12-07 17:03:02 +030012def python = new com.mirantis.mk.Python()
Alena Kiseleva3a49b802018-12-07 17:03:02 +030013def packages
14def command
15def commandKwargs
16def selMinions = []
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040017def flags = CLUSTER_FLAGS ? CLUSTER_FLAGS.tokenize(',') : []
Alena Kiseleva3a49b802018-12-07 17:03:02 +030018
19timeout(time: 12, unit: 'HOURS') {
20 node() {
21 try {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030022 def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon",
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040023 "mgr" : "ceph-mgr", "radosgw": "radosgw"]
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030024
Alena Kiseleva3a49b802018-12-07 17:03:02 +030025 stage('Setup virtualenv for Pepper') {
26 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
27 }
28
Alena Kiseleva3a49b802018-12-07 17:03:02 +030029 stage('Apply package upgrades on all nodes') {
30
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030031 targets.each { key, value ->
Ivan Berezovskiy2325dcb2019-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 Kiseleva3a49b802018-12-07 17:03:02 +030039 }
40 }
41
42 stage("Restart MONs and RGWs") {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030043 selMinions = salt.getMinions(pepperEnv, "I@ceph:mon")
Alena Kiseleva3a49b802018-12-07 17:03:02 +030044 for (tgt in selMinions) {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030045 // runSaltProcessStep 'service.restart' don't work for this services
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040046 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target")
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040047 ceph.waitForHealthy(pepperEnv, tgt, flags)
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030048 }
Mateusz Los0493d5a2020-01-31 13:11:55 +010049 selMinions = salt.getMinions(pepperEnv, "I@ceph:mgr")
50 for (tgt in selMinions) {
51 // runSaltProcessStep 'service.restart' don't work for this services
52 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mgr.target")
53 ceph.waitForHealthy(pepperEnv, tgt, flags)
54 }
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030055 selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw")
56 for (tgt in selMinions) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040057 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target")
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040058 ceph.waitForHealthy(pepperEnv, tgt, flags)
Alena Kiseleva3a49b802018-12-07 17:03:02 +030059 }
60 }
61
62 stage('Restart OSDs') {
mjedynskiaf258b02019-12-09 15:17:58 +010063 def device_grain_name = salt.getPillar(pepperEnv,"I@ceph:osd","ceph:osd:lvm_enabled")['return'].first().containsValue(true) ? "ceph_volume" : "ceph_disk"
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030064 selMinions = salt.getMinions(pepperEnv, "I@ceph:osd")
Alena Kiseleva3a49b802018-12-07 17:03:02 +030065 for (tgt in selMinions) {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030066 salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5)
mjedynskiaf258b02019-12-09 15:17:58 +010067 def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0][device_grain_name]
Alena Kiseleva3a49b802018-12-07 17:03:02 +030068
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030069 def osd_ids = []
70 for (i in ceph_disks) {
71 def osd_id = i.getKey().toString()
72 osd_ids.add('osd.' + osd_id)
Alena Kiseleva3a49b802018-12-07 17:03:02 +030073 }
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030074
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040075 salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout')
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040076 flags = 'noout' in flags ? flags : flags + ['noout']
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030077
78 for (i in osd_ids) {
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040079 salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030080 // wait for healthy cluster
Ivan Berezovskiy373e8a32019-11-19 20:04:12 +040081 ceph.waitForHealthy(pepperEnv, tgt, flags, 0, 100)
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030082 }
83
Ivan Berezovskiy2325dcb2019-11-05 17:42:57 +040084 salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout')
Alena Kiseleva3a49b802018-12-07 17:03:02 +030085 }
86 }
87
88
89 } catch (Throwable e) {
90 // If there was an error or exception thrown, the build failed
91 currentBuild.result = "FAILURE"
92 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
93 throw e
94 }
95 }
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030096}