blob: c26c22910e321b5d0b4dc31d2e66c28af49cc599 [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"
10salt = new com.mirantis.mk.Salt()
11def common = new com.mirantis.mk.Common()
12def python = new com.mirantis.mk.Python()
13def targetLiveSubset
14def targetLiveAll
15def minions
16def result
17def packages
18def command
19def commandKwargs
20def selMinions = []
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030021def check_mon
Alena Kiseleva3a49b802018-12-07 17:03:02 +030022
23def runCephCommand(master, target, cmd) {
24 return salt.cmdRun(master, target, cmd)
25}
26
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030027def waitForHealthy(master, tgt, count = 0, attempts=100) {
Alena Kiseleva3a49b802018-12-07 17:03:02 +030028 // wait for healthy cluster
29 common = new com.mirantis.mk.Common()
Alena Kiselevaa6afc5a2019-05-16 16:00:14 +030030 while (count<attempts) {
Martin Polreichbf174c92019-06-17 11:02:07 +020031 def health = runCephCommand(master, tgt, 'ceph health')['return'][0].values()[0]
Alena Kiseleva3a49b802018-12-07 17:03:02 +030032 if (health.contains('HEALTH_OK') || health.contains('HEALTH_WARN noout flag(s) set\n')) {
33 common.infoMsg('Cluster is healthy')
Alena Kiselevaa6afc5a2019-05-16 16:00:14 +030034 break;
Alena Kiseleva3a49b802018-12-07 17:03:02 +030035 }
Alena Kiselevaa6afc5a2019-05-16 16:00:14 +030036 count++
37 sleep(10)
Alena Kiseleva3a49b802018-12-07 17:03:02 +030038 }
39}
40
41timeout(time: 12, unit: 'HOURS') {
42 node() {
43 try {
44
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030045 def targets = ["common": "ceph-common", "osd": "ceph-osd", "mon": "ceph-mon",
46 "mgr":"ceph-mgr", "radosgw": "radosgw"]
47
Alena Kiseleva3a49b802018-12-07 17:03:02 +030048 stage('Setup virtualenv for Pepper') {
49 python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
50 }
51
Alena Kiseleva3a49b802018-12-07 17:03:02 +030052 stage('Apply package upgrades on all nodes') {
53
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030054 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 Kiseleva3a49b802018-12-07 17:03:02 +030062 }
63 }
64
65 stage("Restart MONs and RGWs") {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030066 selMinions = salt.getMinions(pepperEnv, "I@ceph:mon")
Alena Kiseleva3a49b802018-12-07 17:03:02 +030067 for (tgt in selMinions) {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030068 // 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 Kiseleva3a49b802018-12-07 17:03:02 +030076 }
77 }
78
79 stage('Restart OSDs') {
80
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030081 selMinions = salt.getMinions(pepperEnv, "I@ceph:osd")
Alena Kiseleva3a49b802018-12-07 17:03:02 +030082 for (tgt in selMinions) {
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030083 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 Kiseleva3a49b802018-12-07 17:03:02 +030085
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030086 def osd_ids = []
87 for (i in ceph_disks) {
88 def osd_id = i.getKey().toString()
89 osd_ids.add('osd.' + osd_id)
Alena Kiseleva3a49b802018-12-07 17:03:02 +030090 }
Alena Kiseleva7f3c3862019-06-12 13:16:33 +030091
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 Kiseleva3a49b802018-12-07 17:03:02 +0300101 }
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 Kiseleva7f3c3862019-06-12 13:16:33 +0300112}