diff options
-rw-r--r-- | openshift-storage-libs/openshiftstoragelibs/openshift_storage_libs.py | 60 | ||||
-rw-r--r-- | tests/functional/provisioning/test_storage_class_cases.py | 42 |
2 files changed, 57 insertions, 45 deletions
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 diff --git a/tests/functional/provisioning/test_storage_class_cases.py b/tests/functional/provisioning/test_storage_class_cases.py index 8a04c8ea..f0c61182 100644 --- a/tests/functional/provisioning/test_storage_class_cases.py +++ b/tests/functional/provisioning/test_storage_class_cases.py @@ -3,18 +3,28 @@ from unittest import skip import ddt from glusto.core import Glusto as g +from openshiftstoragelibs.heketi_ops import ( + heketi_blockvolume_info, +) from openshiftstoragelibs.baseclass import BaseClass -from openshiftstoragelibs.openshift_storage_libs import validate_multipath_pod +from openshiftstoragelibs.openshift_storage_libs import ( + get_iscsi_block_devices_by_path, + get_mpath_name_from_device_name, + validate_multipath_pod, +) from openshiftstoragelibs.heketi_ops import verify_volume_name_prefix from openshiftstoragelibs.openshift_ops import ( get_amount_of_gluster_nodes, get_gluster_blockvol_info_by_pvc_name, get_pod_name_from_dc, + get_pv_name_from_pvc, oc_create_app_dc_with_io, oc_create_pvc, oc_create_sc, oc_create_secret, oc_delete, + oc_get_custom_resource, + oc_get_pods, scale_dc_pod_amount_and_wait, wait_for_events, wait_for_pod_be_ready, @@ -138,11 +148,31 @@ class TestStorageClassCases(BaseClass): self.ocp_master_node[0], pod_name, timeout=120, wait_step=3 ) - # validates multipath for pod created with hacount - self.assertTrue( - validate_multipath_pod(self.ocp_master_node[0], pod_name, hacount), - "multipath validation failed" - ) + # Get pod info + pod_info = oc_get_pods( + self.ocp_master_node[0], selector='deploymentconfig=%s' % dc_name) + node = pod_info[pod_name]['node'] + + # Find iqn from volume info + pv_name = get_pv_name_from_pvc(self.ocp_master_node[0], self.pvc_name) + custom = [r':.metadata.annotations."gluster\.org\/volume\-id"'] + vol_id = oc_get_custom_resource( + self.ocp_master_node[0], 'pv', custom, pv_name)[0] + vol_info = heketi_blockvolume_info( + self.heketi_client_node, self.heketi_server_url, vol_id, json=True) + iqn = vol_info['blockvolume']['iqn'] + + # Get the paths info from the node + devices = get_iscsi_block_devices_by_path(node, iqn).keys() + self.assertEqual(hacount, len(devices)) + + # Validate mpath + mpaths = set() + for device in devices: + mpaths.add(get_mpath_name_from_device_name(node, device)) + self.assertEqual(1, len(mpaths)) + validate_multipath_pod( + self.ocp_master_node[0], pod_name, hacount, list(mpaths)[0]) @ddt.data( {"volumetype": "dist-rep:3"}, |