blob: 5326321cc3df04e22b6772830ed94fb79dbe5c7a [file] [log] [blame]
Ivan Berezovskiy14436462019-11-05 17:42:09 +04001package com.mirantis.mk
2
3/**
4 *
5 * Ceph functions
6 *
7 */
8
9/**
10 * Ceph health check
11 *
12 */
13def waitForHealthy(master, target, flags=[], count=0, attempts=300) {
14 def common = new com.mirantis.mk.Common()
15 def salt = new com.mirantis.mk.Salt()
16 // wait for healthy cluster
17 while (count < attempts) {
18 def health = salt.cmdRun(master, target, 'ceph health')['return'][0].values()[0]
19 if (health.contains('HEALTH_OK')) {
20 common.infoMsg('Cluster is healthy')
21 break
22 } else {
23 for (flag in flags) {
24 if (health.contains(flag + ' flag(s) set') && !(health.contains('down'))) {
25 common.infoMsg('Cluster is healthy')
26 return
27 }
28 }
29 }
30 common.infoMsg("Ceph health status: ${health}")
31 count++
32 sleep(10)
33 }
34}
35
36/**
37 * Ceph remove partition
38 *
39 */
40def removePartition(master, target, partition_uuid, type='', id=-1) {
41 def salt = new com.mirantis.mk.Salt()
42 def common = new com.mirantis.mk.Common()
43 def partition = ""
mjedynskiffed8f82019-12-12 20:46:47 +010044 def dev = ''
45 def lvm_enabled = salt.getPillar(master, "I@ceph:osd", "ceph:osd:lvm_enabled")['return'].first().containsValue(true)
46 if ( !lvm_enabled ){
47 if (type == 'lockbox') {
48 try {
49 // umount - partition = /dev/sdi2
50 partition = salt.cmdRun(master, target, "lsblk -rp | grep -v mapper | grep ${partition_uuid} ")['return'][0].values()[0].split()[0]
51 salt.cmdRun(master, target, "umount ${partition}")
52 } catch (Exception e) {
53 common.warningMsg(e)
54 }
55 } else if (type == 'data') {
56 try {
57 // umount - partition = /dev/sdi2
58 partition = salt.cmdRun(master, target, "df | grep /var/lib/ceph/osd/ceph-${id}")['return'][0].values()[0].split()[0]
59 salt.cmdRun(master, target, "umount ${partition}")
60 } catch (Exception e) {
61 common.warningMsg(e)
62 }
63 try {
64 // partition = /dev/sdi2
65 partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0]
66 } catch (Exception e) {
67 common.warningMsg(e)
68 }
69 } else {
70 try {
71 // partition = /dev/sdi2
72 partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0]
73 } catch (Exception e) {
74 common.warningMsg(e)
75 }
Ivan Berezovskiy14436462019-11-05 17:42:09 +040076 }
mjedynskiffed8f82019-12-12 20:46:47 +010077 if (partition?.trim()) {
78 if (partition.contains("nvme")) {
79 // partition = /dev/nvme1n1p2
80 // dev = /dev/nvme1n1
81 dev = partition.replaceAll('p\\d+$', "")
82 // part_id = 2
83 def part_id = partition.substring(partition.lastIndexOf("p") + 1).replaceAll("[^0-9]+", "")
84
85 } else {
86 // partition = /dev/sdi2
87 // dev = /dev/sdi
88 dev = partition.replaceAll('\\d+$', "")
89 // part_id = 2
90 def part_id = partition.substring(partition.lastIndexOf("/") + 1).replaceAll("[^0-9]+", "")
91 }
Ivan Berezovskiy14436462019-11-05 17:42:09 +040092 }
93 }
mjedynskiffed8f82019-12-12 20:46:47 +010094 if (lvm_enabled && type != 'lockbox') {
95 salt.cmdRun(master, target, "ceph-volume lvm zap ${partition_uuid} --destroy")
96 } else if (dev != '') {
97 salt.cmdRun(master, target, "parted ${dev} rm ${part_id}")
98 } else {
99 common.infoMsg("Did not found any device to be wiped.")
Ivan Berezovskiy14436462019-11-05 17:42:09 +0400100 }
101 return
102}