diff --git a/container_ci_suite/openshift.py b/container_ci_suite/openshift.py index 5fb97e3..ace8945 100644 --- a/container_ci_suite/openshift.py +++ b/container_ci_suite/openshift.py @@ -45,13 +45,12 @@ def __init__( self, namespace: str = "default", pod_name_prefix: str = "", create_prj: bool = True, delete_prj: bool = True, - version: str = "", - shared_cluster: bool = False + version: str = "" ): self.namespace = namespace self.create_prj = create_prj self.delete_prj = delete_prj - self.shared_cluster = shared_cluster + self.shared_cluster = utils.is_share_cluster() self.pod_name_prefix = pod_name_prefix self.pod_json_data: Dict = {} self.version = version diff --git a/container_ci_suite/utils.py b/container_ci_suite/utils.py index e7dbde3..44de17c 100644 --- a/container_ci_suite/utils.py +++ b/container_ci_suite/utils.py @@ -354,3 +354,12 @@ def load_shared_credentials(credential: str) -> Any: if cred == "": return None return cred + + +def is_share_cluster() -> bool: + file_shared_cluster = load_shared_credentials("SHARED_CLUSTER") + if not file_shared_cluster: + return False + if file_shared_cluster in ["True", "true", "1", "yes", "Yes", "y"]: + return True + return False diff --git a/tests/test_utils.py b/tests/test_utils.py index 6a2d8bd..e1e1575 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,6 +25,8 @@ import os import yaml +from flexmock import flexmock + import pytest from container_ci_suite.utils import ( @@ -228,3 +230,23 @@ def test_tenantnegress_yaml(self): assert yaml_load assert yaml_load["metadata"]["namespace"] == "core-services-ocp--123456" assert yaml_load == expected_yaml + + @pytest.mark.parametrize( + "os_env,expected_output", + [ + ("False", False), + ("false", False), + (None, False), + ("True", True), + ("true", True), + ("", False), + ("Somthing", False), + ("Y", True), + ("1", True), + ("No", False), + ("0", False), + ], + ) + def test_is_shared_cluster(self, os_env, expected_output): + flexmock(utils).should_receive("load_shared_credentials").and_return(os_env) + assert utils.is_share_cluster() == expected_output