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

Fix shared_cluster creation #79

Merged
merged 1 commit into from
Aug 9, 2024
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
16 changes: 11 additions & 5 deletions container_ci_suite/openshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,40 @@ def __init__(
self.create_prj = False

def create_project(self):
print(f"Create project {self.create_prj} and {self.shared_cluster}")
if self.create_prj:
if self.shared_cluster:
self.shared_random_name = f"{random.randrange(10000, 100000)}"
self.shared_random_name = f"sclorg-{random.randrange(10000, 100000)}"
self.namespace = f"core-services-ocp--{self.shared_random_name}"
self.openshift_ops.set_namespace(self.namespace)
self.prepare_tenant_namespace()
if not self.prepare_tenant_namespace():
return False
else:
self.namespace = f"sclorg-{random.randrange(10000, 100000)}"
self.openshift_ops.set_namespace(self.namespace)
run_oc_command(f"new-project {self.namespace}", json_output=False, return_output=True)
print(f"Project with the name '{self.namespace}' were created.")
else:
run_oc_command(f"project {self.namespace}", json_output=False)
print(f"Project with the name '{self.namespace}' were created.")
return self.openshift_ops.is_project_exits()

def prepare_tenant_namespace(self):
print(f"Prepare Tenant Namespace with name: '{self.shared_random_name}'")
json_flag = False
self.login_to_shared_cluster()
tenant_yaml_file = utils.save_tenant_namespace_yaml(project_name=self.shared_random_name)
run_oc_command(cmd=f"create -f {tenant_yaml_file}", json_output=json_flag, return_output=True)
tentant_output = run_oc_command(cmd=f"create -f {tenant_yaml_file}", json_output=json_flag, return_output=True)
print(tentant_output)
tenant_egress_file = utils.save_tenant_egress_yaml(project_name=self.shared_random_name)
run_oc_command(cmd=f"apply -f {tenant_egress_file}", json_output=False, return_output=True)
tentant_output = run_oc_command(cmd=f"apply -f {tenant_egress_file}", json_output=False, return_output=True)
print(tentant_output)
time.sleep(3)
run_oc_command(
cmd=f"project {self.namespace}",
json_output=json_flag,
return_output=True
)
print("Tenant Namespace were created")

def delete_tenant_namespace(self):
json_flag = False
Expand Down
6 changes: 4 additions & 2 deletions container_ci_suite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ def save_tenant_egress_yaml(project_name: str) -> str:
]
}
}

temp_file = tempfile.NamedTemporaryFile(prefix="tenant-egress-yml", delete=False)
with open(temp_file.name, "w") as fp:
yaml.dump(tenant_egress_yaml, fp)
Expand Down Expand Up @@ -376,11 +375,14 @@ def load_shared_credentials(credential: str) -> Any:

def is_share_cluster() -> bool:
file_shared_cluster = load_shared_credentials("SHARED_CLUSTER")
print(f"Is shared cluster allowed? {file_shared_cluster}")
if not file_shared_cluster:
print("Not defined variable SHARED_CLUSTER")
return False
file_shared_cluster = ''.join(file_shared_cluster.split())
if file_shared_cluster in ["True", "true", "1", "yes", "Yes", "y", "Y"]:
print("Shared cluster allowed")
return True
print("\nShared cluster is not allowed.\nTo allow it add 'true' to file in variable $SHARED_CLUSTER.")
return False


Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def test_tenantnegress_yaml(self):
("1", True),
("No", False),
("0", False),
("true\n\n", True),
],
)
def test_is_shared_cluster(self, os_env, expected_output):
Expand Down
Loading