Skip to content

Commit

Permalink
add OCI custom manifests to cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
adriengentil committed Dec 3, 2024
1 parent c29061c commit e68007f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from assisted_test_infra.test_infra.controllers.node_controllers.node_controller import NodeController
from assisted_test_infra.test_infra.helper_classes.config import BaseNodesConfig
from assisted_test_infra.test_infra.helper_classes.config.base_oci_config import BaseOciConfig
from assisted_test_infra.test_infra.utils.manifests import Manifest
from service_client import log


Expand Down Expand Up @@ -85,18 +86,11 @@ class OciApiController(NodeController):

def __init__(self, config: BaseNodesConfig, cluster_config: BaseClusterConfig):
super().__init__(config, cluster_config)
self._cloud_provider = None
self.cloud_provider = None
self.custom_manifests = None
self._oci_compartment_oicd = self._config.oci_compartment_oicd
self._initialize_oci_clients()

@property
def cloud_provider(self):
# Called from test_cases , modify manifests
return self._cloud_provider

@cloud_provider.setter
def cloud_provider(self, cloud_provider):
self._cloud_provider = cloud_provider

def _initialize_oci_clients(self):
"""Initialize oci clients.
Expand Down Expand Up @@ -356,7 +350,10 @@ def _apply_job_from_stack(
items = self._resource_manager_client.list_job_outputs(job.data.id).data.items
for item in items:
if item.output_name == "oci_ccm_config":
return item.output_value
self.cloud_provider = item.output_value
elif item.output_name == "dynamic_custom_manifest":
manifest = Manifest(folder="manifests", file_name="oci_custom_manifests.yaml", content=item.output_value)
self._entity_config.custom_manifests.append(manifest)
raise RuntimeError(f"Missing oci_ccm_config for stack {stack_id}")

@staticmethod
Expand Down Expand Up @@ -469,8 +466,7 @@ def prepare_nodes(self) -> None:
stack_id = self._create_stack(
random_name("stack-"), namespace, bucket_name, self._config.oci_infrastructure_zip_file, terraform_variables
)
terraform_output = self._apply_job_from_stack(stack_id, random_name("job-"))
self.cloud_provider = terraform_output
self._apply_job_from_stack(stack_id, random_name("job-"))

def is_active(self, node_name) -> bool:
pass
Expand Down
3 changes: 1 addition & 2 deletions src/assisted_test_infra/test_infra/helper_classes/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,7 @@ def prepare_nodes(self, is_static_ip: bool = False, **kwargs):
def create_custom_manifests(self):
log.info(f"Adding {len(self._config.custom_manifests)} custom manifests")
for local_manifest in self._config.custom_manifests:
with open(local_manifest.local_path, "rb") as f:
encoded_content = base64.b64encode(f.read()).decode("utf-8", "ignore")
encoded_content = base64.b64encode(local_manifest.content).decode("utf-8", "ignore")

manifest = self.create_custom_manifest(local_manifest.folder, local_manifest.file_name, encoded_content)

Expand Down
15 changes: 8 additions & 7 deletions src/assisted_test_infra/test_infra/utils/manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Manifest:

folder: str
file_name: str
local_path: Path
content: str

def is_folder_allowed(self) -> bool:
return self.folder in self.__ALLOWED_FOLDERS
Expand All @@ -20,16 +20,17 @@ def get_allowed_folders(self) -> List[str]:

@classmethod
def get_manifests(cls, path: Path) -> List["Manifest"]:
manifests_files = []

manifest_files = []
if path.is_dir():
for file_type in ("yaml", "yml", "json"):
manifests_files.extend(list(path.rglob(f"*.{file_type}")))
manifest_files.extend(list(path.rglob(f"*.{file_type}")))
else:
manifests_files.append(path)
manifest_files.append(path)

manifests = []
for file in manifests_files:
manifests.append(Manifest(folder=file.parent.name, file_name=file.name, local_path=file))
for manifest in manifest_files:
with open(manifest, "rb") as f:
content = f.read()
manifests.append(Manifest(folder=manifest.parent.name, file_name=manifest.name, content=content))

return manifests

0 comments on commit e68007f

Please sign in to comment.