diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index 719dc2561eb..06610ba6006 100644 --- a/ocs_ci/helpers/helpers.py +++ b/ocs_ci/helpers/helpers.py @@ -2847,6 +2847,27 @@ def modify_deployment_replica_count( return ocp_obj.patch(resource_name=deployment_name, params=params) +def modify_deploymentconfig_replica_count( + deploymentconfig_name, replica_count, namespace=config.ENV_DATA["cluster_namespace"] +): + """ + Function to modify deploymentconfig replica count, + i.e to scale up or down deploymentconfig + + Args: + deploymentcofig_name (str): Name of deployment + replica_count (int): replica count to be changed to + namespace (str): namespace where the deployment exists + + Returns: + bool: True in case if changes are applied. False otherwise + + """ + dc_ocp_obj = ocp.OCP(kind=constants.DEPLOYMENTCONFIG, namespace=namespace) + params = f'{{"spec": {{"replicas": {replica_count}}}}}' + return dc_ocp_obj.patch(resource_name=deploymentconfig_name, params=params) + + def modify_job_parallelism_count( job_name, count, namespace=config.ENV_DATA["cluster_namespace"] ): diff --git a/tests/cross_functional/kcs/test_selinux_relabel_solution.py b/tests/cross_functional/kcs/test_selinux_relabel_solution.py index bc7048f02ff..f2f84bf4654 100644 --- a/tests/cross_functional/kcs/test_selinux_relabel_solution.py +++ b/tests/cross_functional/kcs/test_selinux_relabel_solution.py @@ -8,7 +8,10 @@ from ocs_ci.framework import config from ocs_ci.helpers import helpers -from ocs_ci.helpers.helpers import check_selinux_relabeling +from ocs_ci.helpers.helpers import ( + check_selinux_relabeling, + modify_deploymentconfig_replica_count, +) from ocs_ci.ocs import ocp, constants from ocs_ci.framework.testlib import E2ETest from ocs_ci.ocs.exceptions import PodNotCreated, CommandFailed @@ -301,17 +304,30 @@ def test_selinux_relabel_for_existing_pvc( self.apply_selinux_solution_on_existing_pvc(self.pvc_obj) # Delete pod so that fix will be applied for new pod - for _ in range(2): - self.pod_obj = self.get_app_pod_obj() - self.pod_obj.delete(wait=True) - time.sleep(waiting_time) - self.pod_obj = self.get_app_pod_obj() - assert wait_for_pods_to_be_running( - pod_names=[self.pod_obj.name], timeout=600, sleep=15 - ), f"Pod {self.pod_obj.name} didn't reach to running state" + POD_OBJ = ocp.OCP( + kind=constants.POD, namespace=config.ENV_DATA["cluster_namespace"] + ) + assert modify_deploymentconfig_replica_count( + deploymentconfig_name=self.pod_obj.get_labels().get("name"), replica_count=0 + ), "Failed to scale down deploymentconfig to 0" + POD_OBJ.wait_for_delete(resource_name=self.pod_obj.name, timeout=600) + + assert modify_deploymentconfig_replica_count( + deploymentconfig_name=self.pod_obj.get_labels().get("name"), replica_count=1 + ), "Failed to scale down deploymentconfig to 1" + + self.pod_obj = self.get_app_pod_obj() + + POD_OBJ.wait_for_resource( + condition=constants.STATUS_RUNNING, + resource_name=self.pod_obj.name, + resource_count=1, + timeout=600, + sleep=5, + ) # Check SeLinux Relabeling is set to false - retry((AssertionError), tries=5, delay=10,)( + retry(AssertionError, tries=5, delay=10,)( check_selinux_relabeling )(pod_obj=self.pod_obj) log.info(f"SeLinux Relabeling is not happening for the pvc {self.pvc_obj.name}")