Ivan Berezovskiy | 43755db | 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() |
| 43 | def partition = "" |
| 44 | if (type == 'lockbox') { |
| 45 | try { |
| 46 | // umount - partition = /dev/sdi2 |
| 47 | partition = salt.cmdRun(master, target, "lsblk -rp | grep -v mapper | grep ${partition_uuid} ")['return'][0].values()[0].split()[0] |
| 48 | salt.cmdRun(master, target, "umount ${partition}") |
| 49 | } catch (Exception e) { |
| 50 | common.warningMsg(e) |
| 51 | } |
| 52 | } else if (type == 'data') { |
| 53 | try { |
| 54 | // umount - partition = /dev/sdi2 |
| 55 | partition = salt.cmdRun(master, target, "df | grep /var/lib/ceph/osd/ceph-${id}")['return'][0].values()[0].split()[0] |
| 56 | salt.cmdRun(master, target, "umount ${partition}") |
| 57 | } catch (Exception e) { |
| 58 | common.warningMsg(e) |
| 59 | } |
| 60 | try { |
| 61 | // partition = /dev/sdi2 |
| 62 | partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0] |
| 63 | } catch (Exception e) { |
| 64 | common.warningMsg(e) |
| 65 | } |
| 66 | } else { |
| 67 | try { |
| 68 | // partition = /dev/sdi2 |
| 69 | partition = salt.cmdRun(master, target, "blkid | grep ${partition_uuid} ")['return'][0].values()[0].split(":")[0] |
| 70 | } catch (Exception e) { |
| 71 | common.warningMsg(e) |
| 72 | } |
| 73 | } |
| 74 | if (partition?.trim()) { |
| 75 | if (partition.contains("nvme")) { |
| 76 | // dev = /dev/nvme1n1p1 |
| 77 | def dev = partition.replaceAll('\\d+$', "") |
| 78 | print("Skipping " + dev) |
| 79 | // part_id = 2 |
| 80 | def part_id = partition.substring(partition.lastIndexOf("p") + 1).replaceAll("[^0-9]+", "") |
| 81 | print("Skipping" + part_id) |
| 82 | salt.cmdRun(master, target, "Ignore | parted ${dev} rm ${part_id}") |
| 83 | } else { |
| 84 | // dev = /dev/sdi |
| 85 | def dev = partition.replaceAll('\\d+$', "") |
| 86 | // part_id = 2 |
| 87 | def part_id = partition.substring(partition.lastIndexOf("/") + 1).replaceAll("[^0-9]+", "") |
| 88 | salt.cmdRun(master, target, "Ignore | parted ${dev} rm ${part_id}") |
| 89 | } |
| 90 | } |
| 91 | return |
| 92 | } |