Skip to content

Commit

Permalink
fix code
Browse files Browse the repository at this point in the history
Signed-off-by: oviner <oviner@redhat.com>
  • Loading branch information
OdedViner committed Sep 28, 2023
1 parent 0432496 commit d820382
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
35 changes: 32 additions & 3 deletions ocs_ci/ocs/resources/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def workload_setup(self, storage_type, jobs=1, fio_installed=False):
# few io parameters for Fio

self.wl_obj = workload.WorkLoad(name, path, work_load, storage_type, self, jobs)
if not (fio_installed and work_load == "fio"):
assert self.wl_obj.setup(), f"Setup for FIO failed on pod {self.name}"
self.wl_setup_done = True

def run_io(
Expand Down Expand Up @@ -1329,7 +1331,7 @@ def get_fio_rw_iops(pod_obj):
Args:
pod_obj (Pod): The object of the pod
"""
fio_result = pod_obj.get_fio_results(120)
fio_result = pod_obj.get_fio_results()
logger.info(f"FIO output: {fio_result}")
logger.info("IOPs after FIO:")
logger.info(f"Read: {fio_result.get('jobs')[0].get('read').get('iops')}")
Expand Down Expand Up @@ -2213,6 +2215,7 @@ def check_pods_in_running_state(
("rook-ceph-osd-prepare" not in p.name)
and ("rook-ceph-drain-canary" not in p.name)
and ("debug" not in p.name)
and (constants.REPORT_STATUS_TO_PROVIDER_POD not in p.name)
):
status = ocp_pod_obj.get_resource(p.name, "STATUS")
if skip_for_status:
Expand Down Expand Up @@ -2606,14 +2609,17 @@ def get_osd_pod_id(osd_pod):


def get_pods_in_statuses(
status_options, namespace=config.ENV_DATA["cluster_namespace"]
status_options,
namespace=config.ENV_DATA["cluster_namespace"],
exclude_pod_name_prefixes=None,
):
"""
Get all the pods in specific statuses
Args:
status_options (list): The list of the status options.
namespace (str): Name of cluster namespace(default: config.ENV_DATA["cluster_namespace"])
exclude_pod_name_prefixes (list): The list of the pod name prefixes to exclude from the pods to get
Returns:
list: All the pods that their status in the 'status_options' list.
Expand All @@ -2632,6 +2638,14 @@ def get_pods_in_statuses(
if pod_status in status_options:
pods_in_status_options.append(p)

if exclude_pod_name_prefixes:
exclude_pod_name_prefixes = tuple(exclude_pod_name_prefixes)
pods_in_status_options = [
p
for p in pods_in_status_options
if not p.name.startswith(exclude_pod_name_prefixes)
]

return pods_in_status_options


Expand Down Expand Up @@ -2679,7 +2693,10 @@ def check_pods_after_node_replacement():
constants.STATUS_TERMINATING,
]

pods_not_ready = get_pods_in_statuses(status_options=not_ready_statuses)
pods_not_ready = get_pods_in_statuses(
status_options=not_ready_statuses,
exclude_pod_name_prefixes=[constants.REPORT_STATUS_TO_PROVIDER_POD],
)
if len(pods_not_ready) == 0:
logger.info("All the pods are running")
return True
Expand All @@ -2706,6 +2723,7 @@ def check_pods_after_node_replacement():
expected_statuses=expected_statuses,
timeout=timeout,
sleep=30,
exclude_pod_name_prefixes=constants.REPORT_STATUS_TO_PROVIDER_POD,
)
if are_pods_running:
logger.info("All the pods are running")
Expand Down Expand Up @@ -2927,6 +2945,7 @@ def check_pods_in_statuses(
pod_names=None,
namespace=config.ENV_DATA["cluster_namespace"],
raise_pod_not_found_error=False,
exclude_pod_name_prefixes=None,
):
"""
checks whether the pods in a given namespace are in the expected statuses or not
Expand All @@ -2939,6 +2958,7 @@ def check_pods_in_statuses(
raise_pod_not_found_error (bool): If True, it raises an exception, if one of the pods
in the pod names are not found. If False, it ignores the case of pod not found and
check the pod objects of the rest of the pod names. The default value is False
exclude_pod_name_prefixes (list): The list of the pod name prefixes to exclude from the pods to check
Returns:
Boolean: True, if the pods are in the expected statuses. False, otherwise
Expand All @@ -2953,6 +2973,12 @@ def check_pods_in_statuses(
else:
list_of_pods = get_all_pods(namespace)

if exclude_pod_name_prefixes:
exclude_pod_name_prefixes = tuple(exclude_pod_name_prefixes)
list_of_pods = [
p for p in list_of_pods if not p.name.startswith(exclude_pod_name_prefixes)
]

ocp_pod_obj = OCP(kind=constants.POD, namespace=namespace)
for p in list_of_pods:
try:
Expand All @@ -2976,6 +3002,7 @@ def wait_for_pods_to_be_in_statuses(
pod_names=None,
namespace=config.ENV_DATA["cluster_namespace"],
raise_pod_not_found_error=False,
exclude_pod_name_prefixes=None,
timeout=180,
sleep=10,
):
Expand All @@ -2990,6 +3017,7 @@ def wait_for_pods_to_be_in_statuses(
raise_pod_not_found_error (bool): If True, it raises an exception, if one of the pods
in the pod names are not found. If False, it ignores the case of pod not found and
check the pod objects of the rest of the pod names. The default value is False
exclude_pod_name_prefixes (list): The list of the pod name prefixes to exclude from the pods to check
timeout (int): time to wait for the pods to be in the expected statuses
sleep (int): Time in seconds to sleep between attempts
Expand All @@ -3004,6 +3032,7 @@ def wait_for_pods_to_be_in_statuses(
pod_names=pod_names,
namespace=namespace,
raise_pod_not_found_error=raise_pod_not_found_error,
exclude_pod_name_prefixes=exclude_pod_name_prefixes,
)
return sample.wait_for_func_status(result=True)

Expand Down
2 changes: 2 additions & 0 deletions ocs_ci/utility/workloads/fio.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def setup(**kwargs):
bool: True if setup succeeds else False
"""
io_pod = kwargs["pod"]
if "fio" in io_pod.exec_cmd_on_pod(command="fio --version"):
return True
# For first cut doing simple fio install
distro = find_distro(io_pod)
pkg_mgr = DISTROS[distro]
Expand Down

0 comments on commit d820382

Please sign in to comment.