diff --git a/ocs_ci/helpers/helpers.py b/ocs_ci/helpers/helpers.py index 719dc2561eb..615a71f7786 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 deploymentconfig + replica_count (int): replica count to be changed to + namespace (str): namespace where the deploymentconfig 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 0f1bed39598..bd1802a9a03 100644 --- a/tests/cross_functional/kcs/test_selinux_relabel_solution.py +++ b/tests/cross_functional/kcs/test_selinux_relabel_solution.py @@ -8,12 +8,16 @@ 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 from ocs_ci.ocs.resources import pod as res_pod from ocs_ci.ocs.resources.pod import wait_for_pods_to_be_running +from ocs_ci.utility.retry import retry from ocs_ci.utility.utils import run_cmd from ocs_ci.utility.templating import dump_data_to_temp_yaml from ocs_ci.framework.pytest_customization.marks import ( @@ -267,9 +271,9 @@ def test_selinux_relabel_for_existing_pvc( self.pod_selector = self.pod_obj.labels.get(constants.DEPLOYMENTCONFIG) # Leave pod for some time to run since file creation time is longer - waiting_time = 120 + waiting_time = 200 log.info(f"Waiting for {waiting_time} seconds") - time.sleep(120) + time.sleep(waiting_time) # Get the md5sum of some random files random_files = self.get_random_files(self.pod_obj) @@ -300,15 +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 - self.pod_obj = self.get_app_pod_obj() + assert modify_deploymentconfig_replica_count( + deploymentconfig_name=self.pod_obj.get_labels().get("name"), replica_count=0 + ), "Failed to scale down deploymentconfig to 0" self.pod_obj.delete(wait=True) + + 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() - 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" + ocp.OCP( + kind=constants.POD, namespace=constants.OPENSHIFT_STORAGE_NAMESPACE + ).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 - check_selinux_relabeling(pod_obj=self.pod_obj) + 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}") # Restart pod after applying fix