Ivan Berezovskiy | 1443646 | 2019-11-05 17:42:09 +0400 | [diff] [blame] | 1 | package com.mirantis.mk |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * Ceph functions |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * Ceph health check |
| 11 | * |
| 12 | */ |
| 13 | def 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 | */ |
| 40 | def 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 Jaroszyk | 3a82bbe | 2020-04-07 11:34:48 +0200 | [diff] [blame] | 43 | def partition = '' |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 44 | def dev = '' |
Tomek Jaroszyk | 3a82bbe | 2020-04-07 11:34:48 +0200 | [diff] [blame] | 45 | def part_id = '' |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 46 | 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 Jaroszyk | 3a82bbe | 2020-04-07 11:34:48 +0200 | [diff] [blame] | 59 | partition = salt.cmdRun(master, target, "lsblk -rp | grep /var/lib/ceph/osd/ceph-${id}")['return'][0].values()[0].split()[0] |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 60 | 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 Berezovskiy | 1443646 | 2019-11-05 17:42:09 +0400 | [diff] [blame] | 77 | } |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 78 | 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 Jaroszyk | 3a82bbe | 2020-04-07 11:34:48 +0200 | [diff] [blame] | 84 | part_id = partition.substring(partition.lastIndexOf("p") + 1).replaceAll("[^0-9]+", "") |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 85 | |
| 86 | } else { |
| 87 | // partition = /dev/sdi2 |
| 88 | // dev = /dev/sdi |
| 89 | dev = partition.replaceAll('\\d+$', "") |
| 90 | // part_id = 2 |
Tomek Jaroszyk | 3a82bbe | 2020-04-07 11:34:48 +0200 | [diff] [blame] | 91 | part_id = partition.substring(partition.lastIndexOf("/") + 1).replaceAll("[^0-9]+", "") |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 92 | } |
Ivan Berezovskiy | 1443646 | 2019-11-05 17:42:09 +0400 | [diff] [blame] | 93 | } |
| 94 | } |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 95 | if (lvm_enabled && type != 'lockbox') { |
Mateusz Los | 88e0bb4 | 2020-05-11 13:28:59 +0200 | [diff] [blame] | 96 | salt.cmdRun(master, target, "ceph-volume lvm zap /dev/disk/by-partuuid/${partition_uuid} --destroy") |
mjedynski | ffed8f8 | 2019-12-12 20:46:47 +0100 | [diff] [blame] | 97 | } 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 Berezovskiy | 1443646 | 2019-11-05 17:42:09 +0400 | [diff] [blame] | 101 | } |
| 102 | return |
| 103 | } |