blob: 86602334e922a945d184ed3aff165b2be716dd7a [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()
Tomek Jaroszyk3a82bbe2020-04-07 11:34:48 +020043 def partition = ''
mjedynskiffed8f82019-12-12 20:46:47 +010044 def dev = ''
Tomek Jaroszyk3a82bbe2020-04-07 11:34:48 +020045 def part_id = ''
mjedynskiffed8f82019-12-12 20:46:47 +010046 def lvm_enabled = salt.getPillar(master, "I@ceph:osd", "ceph:osd:lvm_enabled")['return'].first().containsValue(true)
47 if ( !lvm_enabled ){
48 if (type == 'lockbox') {
49 try {
50 // umount - partition = /dev/sdi2
51 partition = salt.cmdRun(master, target, "lsblk -rp | grep -v mapper | grep ${partition_uuid} ")['return'][0].values()[0].split()[0]
52 salt.cmdRun(master, target, "umount ${partition}")
53 } catch (Exception e) {
54 common.warningMsg(e)
55 }
56 } else if (type == 'data') {
57 try {
58 // umount - partition = /dev/sdi2
Tomek Jaroszyk3a82bbe2020-04-07 11:34:48 +020059 partition = salt.cmdRun(master, target, "lsblk -rp | grep /var/lib/ceph/osd/ceph-${id}")['return'][0].values()[0].split()[0]
mjedynskiffed8f82019-12-12 20:46:47 +010060 salt.cmdRun(master, target, "umount ${partition}")
61 } catch (Exception e) {
62 common.warningMsg(e)
63 }
64 try {
65 // partition = /dev/sdi2
66 partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0]
67 } catch (Exception e) {
68 common.warningMsg(e)
69 }
70 } else {
71 try {
72 // partition = /dev/sdi2
73 partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0]
74 } catch (Exception e) {
75 common.warningMsg(e)
76 }
Ivan Berezovskiy14436462019-11-05 17:42:09 +040077 }
mjedynskiffed8f82019-12-12 20:46:47 +010078 if (partition?.trim()) {
79 if (partition.contains("nvme")) {
80 // partition = /dev/nvme1n1p2
81 // dev = /dev/nvme1n1
82 dev = partition.replaceAll('p\\d+$', "")
83 // part_id = 2
Tomek Jaroszyk3a82bbe2020-04-07 11:34:48 +020084 part_id = partition.substring(partition.lastIndexOf("p") + 1).replaceAll("[^0-9]+", "")
mjedynskiffed8f82019-12-12 20:46:47 +010085
86 } else {
87 // partition = /dev/sdi2
88 // dev = /dev/sdi
89 dev = partition.replaceAll('\\d+$', "")
90 // part_id = 2
Tomek Jaroszyk3a82bbe2020-04-07 11:34:48 +020091 part_id = partition.substring(partition.lastIndexOf("/") + 1).replaceAll("[^0-9]+", "")
mjedynskiffed8f82019-12-12 20:46:47 +010092 }
Ivan Berezovskiy14436462019-11-05 17:42:09 +040093 }
94 }
mjedynskiffed8f82019-12-12 20:46:47 +010095 if (lvm_enabled && type != 'lockbox') {
Mateusz Los88e0bb42020-05-11 13:28:59 +020096 salt.cmdRun(master, target, "ceph-volume lvm zap /dev/disk/by-partuuid/${partition_uuid} --destroy")
mjedynskiffed8f82019-12-12 20:46:47 +010097 } else if (dev != '') {
98 salt.cmdRun(master, target, "parted ${dev} rm ${part_id}")
99 } else {
100 common.infoMsg("Did not found any device to be wiped.")
Ivan Berezovskiy14436462019-11-05 17:42:09 +0400101 }
102 return
103}