From 7786dc129a32a071d1335f7720173e54d34e7862 Mon Sep 17 00:00:00 2001 From: Elior Erez Date: Thu, 9 Jan 2025 17:34:10 +0200 Subject: [PATCH] NO-ISSUE: Set OCI bucket name to include cluster name. Upload terraform output to the generated bucket. --- .../node_controllers/oci_api_controller.py | 27 ++++++++++++++----- .../config/base_cluster_config.py | 1 - .../config/base_entity_config.py | 1 + .../config/base_infra_env_config.py | 1 - 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/assisted_test_infra/test_infra/controllers/node_controllers/oci_api_controller.py b/src/assisted_test_infra/test_infra/controllers/node_controllers/oci_api_controller.py index fb9683c76fc..96d0e868b39 100644 --- a/src/assisted_test_infra/test_infra/controllers/node_controllers/oci_api_controller.py +++ b/src/assisted_test_infra/test_infra/controllers/node_controllers/oci_api_controller.py @@ -150,8 +150,16 @@ def _create_bucket( # Need the namespace and bucket name return namespace - def _upload_iso_to_bucket(self, file_path: str, namespace: str, bucket_name: str) -> None: - log.info(f"Upload iso file to bucket object storage {file_path}") + def _upload_data_to_bucket(self, data: str, filename: str, namespace: str, bucket_name: str): + file_path = f"/tmp/{filename}" + + with os.path.open(file_path, "w") as f: + f.write(data) + + return self._upload_file_to_bucket(file_path, namespace, bucket_name) + + def _upload_file_to_bucket(self, file_path: str, namespace: str, bucket_name: str): + log.info(f"Upload file to bucket object storage {file_path}") if os.path.isfile(file_path): try: self._object_storage_client.put_object( @@ -444,11 +452,11 @@ def setup_time(self) -> str: def prepare_nodes(self) -> None: log.info("OCI prepare all nodes") - bucket_name = random_name("bucket-") + bucket_name = f"bucket-{self._entity_config.cluster_id}" namespace = self._create_bucket(bucket_name) - self._upload_iso_to_bucket(self._entity_config.iso_download_path, namespace, bucket_name) + self._upload_file_to_bucket(self._entity_config.iso_download_path, namespace, bucket_name) url_path = self._create_pre_authenticated( - random_name("preauth-"), self._entity_config.iso_download_path, namespace, bucket_name + f"preauth-{self._entity_config.cluster_id}", self._entity_config.iso_download_path, namespace, bucket_name ) terraform_variables = self._terraform_variables( @@ -460,9 +468,16 @@ def prepare_nodes(self) -> None: base_dns=self._entity_config.base_dns_domain, ) stack_id = self._create_stack( - random_name("stack-"), namespace, bucket_name, self._config.oci_infrastructure_zip_file, terraform_variables + f"stack-{self._entity_config.cluster_id}", + namespace, + bucket_name, + self._config.oci_infrastructure_zip_file, + terraform_variables, ) terraform_output = self._apply_job_from_stack(stack_id, random_name("job-")) + self._upload_data_to_bucket( + terraform_output, f"terraform-output-{self._entity_config.cluster_id}.yaml", namespace, bucket_name + ) self.cloud_provider = terraform_output def is_active(self, node_name) -> bool: diff --git a/src/assisted_test_infra/test_infra/helper_classes/config/base_cluster_config.py b/src/assisted_test_infra/test_infra/helper_classes/config/base_cluster_config.py index 63a2b91affc..11bb2f0231c 100644 --- a/src/assisted_test_infra/test_infra/helper_classes/config/base_cluster_config.py +++ b/src/assisted_test_infra/test_infra/helper_classes/config/base_cluster_config.py @@ -16,7 +16,6 @@ class BaseClusterConfig(BaseEntityConfig, ABC): All arguments must default to None and be type annotated. """ - cluster_id: str = None cluster_tags: str = None olm_operators: List[str] = None vip_dhcp_allocation: bool = None diff --git a/src/assisted_test_infra/test_infra/helper_classes/config/base_entity_config.py b/src/assisted_test_infra/test_infra/helper_classes/config/base_entity_config.py index 65da04e5ba5..6dc1852f36c 100644 --- a/src/assisted_test_infra/test_infra/helper_classes/config/base_entity_config.py +++ b/src/assisted_test_infra/test_infra/helper_classes/config/base_entity_config.py @@ -34,3 +34,4 @@ class BaseEntityConfig(BaseConfig, ABC): is_bonded: bool = None num_bonded_slaves: int = None bonding_mode: str = None + cluster_id: str = None diff --git a/src/assisted_test_infra/test_infra/helper_classes/config/base_infra_env_config.py b/src/assisted_test_infra/test_infra/helper_classes/config/base_infra_env_config.py index 71354143d5d..1bf1bb4b48a 100644 --- a/src/assisted_test_infra/test_infra/helper_classes/config/base_infra_env_config.py +++ b/src/assisted_test_infra/test_infra/helper_classes/config/base_infra_env_config.py @@ -13,7 +13,6 @@ class BaseInfraEnvConfig(BaseEntityConfig, ABC): """ infra_env_id: str = None - cluster_id: str = None static_network_config: List[dict] = None ignition_config_override: str = None verify_download_iso_ssl: bool = None