blob: 6cef0b327a9eb40bc8e53b8efc81c8a9de50f8a8 [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(',') : []
Mateusz Losc5de5c82020-05-11 10:37:23 +020018def runHighState = RUNHIGHSTATE
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030019
20timeout(time: 12, unit: 'HOURS') {
21 node() {
22 try {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030023 def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon",
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040024 "mgr" : "ceph-mgr", "radosgw": "radosgw"]
Alena Kiselevaf99b1162019-06-12 13:16:33 +030025
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030026 stage('Setup virtualenv for Pepper') {
27 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
28 }
29
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030030 stage('Apply package upgrades on all nodes') {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030031 targets.each { key, value ->
Mateusz Los66e43902020-05-11 10:22:53 +020032 salt.enforceState(pepperEnv, "I@ceph:${key}", 'linux.system.repo', true)
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040033 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
Mateusz Losc5de5c82020-05-11 10:37:23 +020042 stage('Set cluster flags') {
43 if (flags.size() > 0) {
44 stage('Set cluster flags') {
45 for (flag in flags) {
46 salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", 'ceph osd set ' + flag)
47 }
48 }
49 }
50 }
51
52 stage("Restart MONs") {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030053 selMinions = salt.getMinions(pepperEnv, "I@ceph:mon")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030054 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030055 // runSaltProcessStep 'service.restart' don't work for this services
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040056 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mon.target")
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040057 ceph.waitForHealthy(pepperEnv, tgt, flags)
Mateusz Losc5de5c82020-05-11 10:37:23 +020058 if (runHighState) {
59 salt.enforceHighstate(pepperEnv, tgt)
60 }
Alena Kiselevaf99b1162019-06-12 13:16:33 +030061 }
Mateusz Los0d098192020-01-31 13:11:55 +010062 selMinions = salt.getMinions(pepperEnv, "I@ceph:mgr")
63 for (tgt in selMinions) {
64 // runSaltProcessStep 'service.restart' don't work for this services
65 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-mgr.target")
66 ceph.waitForHealthy(pepperEnv, tgt, flags)
Mateusz Losc5de5c82020-05-11 10:37:23 +020067 if (runHighState) {
68 salt.enforceHighstate(pepperEnv, tgt)
69 }
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030070 }
71 }
72
73 stage('Restart OSDs') {
Mateusz Los2ae66db2020-04-28 16:36:11 +020074 def device_grain_name = "ceph_disk"
Alena Kiselevaf99b1162019-06-12 13:16:33 +030075 selMinions = salt.getMinions(pepperEnv, "I@ceph:osd")
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030076 for (tgt in selMinions) {
Alena Kiselevaf99b1162019-06-12 13:16:33 +030077 salt.runSaltProcessStep(pepperEnv, tgt, 'saltutil.sync_grains', [], null, true, 5)
mjedynski12955c72019-12-09 15:17:58 +010078 def ceph_disks = salt.getGrain(pepperEnv, tgt, 'ceph')['return'][0].values()[0].values()[0][device_grain_name]
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030079
Alena Kiselevaf99b1162019-06-12 13:16:33 +030080 def osd_ids = []
81 for (i in ceph_disks) {
82 def osd_id = i.getKey().toString()
83 osd_ids.add('osd.' + osd_id)
Alena Kiseleva895bc7a2018-12-07 17:03:02 +030084 }
Alena Kiselevaf99b1162019-06-12 13:16:33 +030085
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040086 salt.cmdRun(pepperEnv, tgt, 'ceph osd set noout')
Ivan Berezovskiy4c39c7d2019-11-19 20:04:12 +040087 flags = 'noout' in flags ? flags : flags + ['noout']
Alena Kiselevaf99b1162019-06-12 13:16:33 +030088
89 for (i in osd_ids) {
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040090 salt.runSaltProcessStep(pepperEnv, tgt, 'service.restart', ['ceph-osd@' + i.replaceAll('osd.', '')], null, true)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030091 // wait for healthy cluster
Tomek Jaroszyk08ad67e2020-11-09 13:58:02 +010092 ceph.waitForHealthy(pepperEnv, tgt, flags, 100)
Alena Kiselevaf99b1162019-06-12 13:16:33 +030093 }
94
Mateusz Losc5de5c82020-05-11 10:37:23 +020095 if (runHighState) {
96 salt.enforceHighstate(pepperEnv, tgt)
97 }
98
Ivan Berezovskiy19c685a2019-11-05 17:42:57 +040099 salt.cmdRun(pepperEnv, tgt, 'ceph osd unset noout')
Alena Kiseleva895bc7a2018-12-07 17:03:02 +0300100 }
101 }
102
Mateusz Losc5de5c82020-05-11 10:37:23 +0200103 stage('Restart RGWs') {
104 selMinions = salt.getMinions(pepperEnv, "I@ceph:radosgw")
105 for (tgt in selMinions) {
106 salt.cmdRun(pepperEnv, tgt, "systemctl restart ceph-radosgw.target")
107 ceph.waitForHealthy(pepperEnv, tgt, flags)
108 if (runHighState) {
109 salt.enforceHighstate(pepperEnv, tgt)
110 }
111 }
112 }
Alena Kiseleva895bc7a2018-12-07 17:03:02 +0300113 } catch (Throwable e) {
114 // If there was an error or exception thrown, the build failed
Mateusz Los05849762020-05-11 09:59:32 +0200115 if (flags.size() > 0) {
116 stage('Unset cluster flags') {
117 for (flag in flags) {
118 salt.cmdRun(pepperEnv, "I@ceph:mon and I@ceph:common:keyring:admin", 'ceph osd unset ' + flag)
119 }
120 }
121 }
Alena Kiseleva895bc7a2018-12-07 17:03:02 +0300122 currentBuild.result = "FAILURE"
123 currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
124 throw e
125 }
126 }
Tomek Jaroszyk6d8a3aa2020-07-07 12:07:40 +0200127}