Skip to content

Commit

Permalink
Add function to check if shared_cluster is allowed
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <[email protected]>
  • Loading branch information
phracek committed Jul 26, 2024
1 parent 692a362 commit 7b4c53c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 2 additions & 3 deletions container_ci_suite/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions container_ci_suite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import os
import yaml

from flexmock import flexmock

import pytest

from container_ci_suite.utils import (
Expand Down Expand Up @@ -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

0 comments on commit 7b4c53c

Please sign in to comment.