Skip to content

Commit

Permalink
add modify_deploymentconfig_replica_count
Browse files Browse the repository at this point in the history
Signed-off-by: Vishakha Kathole <[email protected]>
  • Loading branch information
vkathole authored and openshift-cherrypick-robot committed May 31, 2024
1 parent 6a16867 commit 4b1fe11
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
21 changes: 21 additions & 0 deletions ocs_ci/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
):
Expand Down
36 changes: 26 additions & 10 deletions tests/cross_functional/kcs/test_selinux_relabel_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 4b1fe11

Please sign in to comment.