Skip to content

Commit

Permalink
Fix shared_cluster creation
Browse files Browse the repository at this point in the history
Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Aug 9, 2024
1 parent ce48091 commit 3de669e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
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

0 comments on commit 3de669e

Please sign in to comment.