Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.15] Fix selinux relabeling testcase #9881

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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"]
):
Expand Down
35 changes: 27 additions & 8 deletions tests/cross_functional/kcs/test_selinux_relabel_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading