From 49a83f155dcf9e173920f402c23d669e1da8c60c Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Wed, 22 May 2019 18:31:25 +0530 Subject: Make 'validate_multipath_pod' func raise exceptions in case of errors Now, this function hides info about the real problem which caused error So, make it raise exceptions in place with info about error for ease of debugging. Also, fix it's usage providing mpath always. Change-Id: I8cbc62a12f3999e3d64fb6b504865f30b1602cf1 --- .../openshiftstoragelibs/openshift_storage_libs.py | 60 ++++++++-------------- 1 file changed, 21 insertions(+), 39 deletions(-) (limited to 'openshift-storage-libs') diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py b/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py index 4d2b4f61..e9ad670d 100644 --- a/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py +++ b/openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py @@ -12,54 +12,36 @@ from openshiftstoragelibs.openshift_version import get_openshift_version MASTER_CONFIG_FILEPATH = "/etc/origin/master/master-config.yaml" -def validate_multipath_pod(hostname, podname, hacount, mpath=""): - ''' - This function validates multipath for given app-pod +def validate_multipath_pod(hostname, podname, hacount, mpath): + """Validate multipath for given app-pod. + Args: hostname (str): ocp master node name podname (str): app-pod name for which we need to validate multipath. ex : nginx1 hacount (int): multipath count or HA count. ex: 3 + mpath (str): multipath value to check Returns: - bool: True if successful, - otherwise False - ''' + bool: True if successful, otherwise raises exception + """ + cmd = "oc get pods -o wide | grep %s | awk '{print $7}'" % podname - ret, out, err = g.run(hostname, cmd, "root") - if ret != 0 or out == "": - g.log.error("failed to exectute cmd %s on %s, err %s" - % (cmd, hostname, out)) - return False - pod_nodename = out.strip() - active_node_count = 1 - enable_node_count = hacount - 1 + pod_nodename = cmd_run(cmd, hostname) + + active_node_count, enable_node_count = (1, hacount - 1) cmd = "multipath -ll %s | grep 'status=active' | wc -l" % mpath - ret, out, err = g.run(pod_nodename, cmd, "root") - if ret != 0 or out == "": - g.log.error("failed to exectute cmd %s on %s, err %s" - % (cmd, pod_nodename, out)) - return False - active_count = int(out.strip()) - if active_node_count != active_count: - g.log.error("active node count on %s for %s is %s and not 1" - % (pod_nodename, podname, active_count)) - return False + active_count = int(cmd_run(cmd, pod_nodename)) + assert active_node_count == active_count, ( + "Active node count on %s for %s is %s and not 1" % ( + pod_nodename, podname, active_count)) + cmd = "multipath -ll %s | grep 'status=enabled' | wc -l" % mpath - ret, out, err = g.run(pod_nodename, cmd, "root") - if ret != 0 or out == "": - g.log.error("failed to exectute cmd %s on %s, err %s" - % (cmd, pod_nodename, out)) - return False - enable_count = int(out.strip()) - if enable_node_count != enable_count: - g.log.error("passive node count on %s for %s is %s " - "and not %s" % ( - pod_nodename, podname, enable_count, - enable_node_count)) - return False - - g.log.info("validation of multipath for %s is successfull" - % podname) + enable_count = int(cmd_run(cmd, pod_nodename)) + assert enable_node_count == enable_count, ( + "Passive node count on %s for %s is %s and not %s" % ( + pod_nodename, podname, enable_count, enable_node_count)) + + g.log.info("Validation of multipath for %s is successfull" % podname) return True -- cgit