summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
diff options
context:
space:
mode:
authorSushilG96 <guptarahul201010@gmail.com>2020-01-14 19:10:33 +0530
committerVaibhav Mahajan <vamahaja@redhat.com>2020-01-24 09:47:41 +0000
commit1269e4fe3ac8c8ee3f19f94141675b8c71dbc81b (patch)
tree4ccf6b07a60c692302792d51ff873f85b9686342 /openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
parent85b1c8a2cb07071bcfd1ed1405ba9e7d5d66e483 (diff)
[lib] Add lib to match PV, Heketi and get gluster vols by name prefix
This contains libraries - 1. match_pv_and_heketi_volumes - library for matching heketi volumes and PVCs. 2. heketi_volume_list_by_name_prefix - library to getvolume id and cluster id. 3. match_heketi_and_gluster_volumes_by_prefix - library for matching heketi and gluster volumes. Change-Id: I02af31405a9836000d758a2ffac932be13e52a03
Diffstat (limited to 'openshift-storage-libs/openshiftstoragelibs/openshift_ops.py')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/openshift_ops.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
index 1835d9ca..07a527da 100644
--- a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py
@@ -1966,3 +1966,32 @@ def oc_patch(ocp_node, rtype, rname, changes, raise_on_error=True):
out = command.cmd_run(
cmd, hostname=ocp_node, raise_on_error=raise_on_error)
return out or None
+
+
+def match_pv_and_heketi_volumes(hostname, heketi_volumes, pvc_prefix):
+ """Match heketi volumes and PVs
+
+ Args:
+ hostname (str): Hostname on which we want to check heketi
+ volumes and PVCs
+ heketi_volumes (list): List of heketi volume names
+ pvc_prefix (str): PVC name prefix given by user at the time
+ of pvc creation
+ """
+
+ custom_columns = [
+ r':.spec.claimRef.name',
+ r':.metadata.annotations."pv\.kubernetes\.io\/provisioned\-by"',
+ r':.metadata.annotations."gluster\.kubernetes\.io\/heketi-volume\-id"'
+ ]
+ pv_volumes = set([
+ pv[2]
+ for pv in oc_get_custom_resource(hostname, "pv", custom_columns)
+ if pv[0].startswith(pvc_prefix) and pv[1] == "kubernetes.io/glusterfs"
+ ])
+
+ vol_diff = pv_volumes ^ set(heketi_volumes)
+ err_msg = ("PV and Heketi volume list match failed"
+ "PV: {}, Heketi volumes {}, "
+ "Difference: {}".format(pv_volumes, heketi_volumes, vol_diff))
+ assert not vol_diff, err_msg