summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Kumar <aanand01762@gmail.com>2020-05-09 17:30:42 +0530
committerVaibhav Mahajan <vamahaja@redhat.com>2020-05-27 11:27:20 +0000
commit61797eb7fcc2d9cdf8870e376a7c5f957ad5ba42 (patch)
tree0cb753f53366c09e1ee8ad6ce5f42fdfbaef3904
parent56105c6e292093bb84f417ffcaa35e0c187fb6d3 (diff)
[Lib] Add library to valiadte heketi device uuid and vg
Change-Id: If583d912d6c24862f8b26424abf62f8e0942dc45 Signed-off-by: Arun Kumar <aanand01762@gmail.com>
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/heketi_ops.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
index 4f4c9bd..053f760 100644
--- a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
+++ b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py
@@ -2033,3 +2033,37 @@ def heketi_volume_list_by_name_prefix(
vol_regex = re.compile(HEKETI_VOLUME % prefix)
return vol_regex.findall(h_volumes.strip())
+
+
+def validate_dev_path_vg_and_uuid(
+ heketi_client_node, heketi_server_url, hostname, device_id):
+ """Validate dev_path between node and heketi
+
+ Args:
+ heketi_client_node (str): Node on which cmd has to be executed.
+ heketi_server_url (str): Heketi server url.
+ hostname (str): Hostname of the node to which device is attached.
+ device_id (str): Device id to match the uuid and vg with node.
+
+ Returns:
+ bool: True if uuid and vg entry in heketi matches the actual values
+ else False
+ """
+ # Get dev_name, vg and uuid from heketi
+ dev_info = heketi_device_info(
+ heketi_client_node, heketi_server_url, device_id, json=True)
+ dev_name, h_uuid = dev_info["name"], dev_info["pv_uuid"]
+ bricks = dev_info["bricks"]
+ if bricks:
+ h_vg = bricks[0]["path"].split("/")[5]
+
+ # Collect data from the node
+ cmd = "pvs --noheadings -o vg_name,uuid -S name={}".format(dev_name)
+ n_vg, n_uuid = command.cmd_run(cmd, hostname=hostname).split()
+
+ # Compare the vg from node and heketi
+ if bricks and h_vg != n_vg:
+ return False
+
+ # Compare the uuid from node and heketi
+ return n_uuid == h_uuid