diff --git a/config/configuration_file_locations_manager.py b/config/configuration_file_locations_manager.py index 2e65ddd7..9372fdbe 100644 --- a/config/configuration_file_locations_manager.py +++ b/config/configuration_file_locations_manager.py @@ -10,6 +10,7 @@ class ConfigurationFileLocationsManager: def __init__(self): self.lab_config_file = None + self.deployment_assets_config_file = None self.k8s_config_file = None self.ptp_config_file = None self.logger_config_file = None @@ -35,6 +36,10 @@ class ConfigurationFileLocationsManager: if lab_config_file: self.set_lab_config_file(lab_config_file) + deployment_assets_config_file = session.config.getoption("--deployment_assets_config_file") + if deployment_assets_config_file: + self.set_deployment_assets_config_file(deployment_assets_config_file) + k8s_config_file = session.config.getoption("--k8s_config_file") if k8s_config_file: self.set_k8s_config_file(k8s_config_file) @@ -93,6 +98,10 @@ class ConfigurationFileLocationsManager: if lab_config_file: self.set_lab_config_file(lab_config_file) + deployment_assets_config_file = options.deployment_assets_config_file + if deployment_assets_config_file: + self.set_deployment_assets_config_file(deployment_assets_config_file) + k8s_config_file = options.k8s_config_file if k8s_config_file: self.set_k8s_config_file(k8s_config_file) @@ -151,6 +160,14 @@ class ConfigurationFileLocationsManager: help="the lab file used for scanning", ) + parser.add_option( + "--deployment_assets_config_file", + action="store", + type="str", + dest="deployment_assets_config_file", + help="The location of the files used to deploy the lab", + ) + parser.add_option( "--k8s_config_file", action="store", @@ -256,6 +273,27 @@ class ConfigurationFileLocationsManager: """ return self.lab_config_file + def set_deployment_assets_config_file(self, deployment_assets_config_file: str): + """ + Setter for deployment assets config file. + + Args: + deployment_assets_config_file (str): the location of the deployment assets config file + + Returns: None + + """ + self.deployment_assets_config_file = deployment_assets_config_file + + def get_deployment_assets_config_file(self) -> str: + """ + Getter for deployment assets config file. + + Returns: the deployment assets config file. + + """ + return self.deployment_assets_config_file + def set_k8s_config_file(self, k8s_config_file: str): """ Setter for k8s config file. diff --git a/config/configuration_manager.py b/config/configuration_manager.py index fb14d914..8dcc236e 100644 --- a/config/configuration_manager.py +++ b/config/configuration_manager.py @@ -1,6 +1,7 @@ from config.app.objects.app_config import AppConfig from config.configuration_file_locations_manager import ConfigurationFileLocationsManager from config.database.objects.database_config import DatabaseConfig +from config.deployment_assets.objects.deployment_assets_config import DeploymentAssetsConfig from config.docker.objects.docker_config import DockerConfig from config.k8s.objects.k8s_config import K8sConfig from config.lab.objects.lab_config import LabConfig @@ -21,6 +22,7 @@ class ConfigurationManagerClass: def __init__(self): self.loaded = False self.lab_config: LabConfig = None + self.deployment_assets_config: DeploymentAssetsConfig = None self.k8s_config: K8sConfig = None self.ptp_config: PTPConfig = None self.logger_config: LoggerConfig = None @@ -62,6 +64,10 @@ class ConfigurationManagerClass: if not lab_config_file: lab_config_file = get_stx_resource_path("config/lab/files/default.json5") + deployment_assets_config_file = config_file_locations.get_deployment_assets_config_file() + if not deployment_assets_config_file: + deployment_assets_config_file = get_stx_resource_path("config/deployment_assets/files/default.json5") + k8s_config_file = config_file_locations.get_k8s_config_file() if not k8s_config_file: k8s_config_file = get_stx_resource_path("config/k8s/files/default.json5") @@ -105,6 +111,7 @@ class ConfigurationManagerClass: if not self.loaded: try: self.lab_config = LabConfig(lab_config_file) + self.deployment_assets_config = DeploymentAssetsConfig(deployment_assets_config_file) self.k8s_config = K8sConfig(k8s_config_file) self.ptp_config = PTPConfig(ptp_config_file) self.logger_config = LoggerConfig(logger_config_file) @@ -139,6 +146,15 @@ class ConfigurationManagerClass: """ self.lab_config = lab_config + def get_deployment_assets_config(self) -> DeploymentAssetsConfig: + """ + Getter for deployment assets config. + + Returns (DeploymentAssetsConfig): the deployment assets config object representing the content of the deployment assets config file. + + """ + return self.deployment_assets_config + def get_k8s_config(self) -> K8sConfig: """ Getter for k8s config. @@ -241,6 +257,8 @@ class ConfigurationManagerClass: if self.configuration_locations_manager.get_lab_config_file(): pytest_config_args.append(f"--lab_config_file={self.configuration_locations_manager.get_lab_config_file()}") + if self.configuration_locations_manager.get_deployment_assets_config_file(): + pytest_config_args.append(f"--deployment_assets_config_file={self.configuration_locations_manager.get_deployment_assets_config_file()}") if self.configuration_locations_manager.get_k8s_config_file(): pytest_config_args.append(f"--k8s_config_file={self.configuration_locations_manager.get_k8s_config_file()}") if self.configuration_locations_manager.get_ptp_config_file(): diff --git a/config/deployment_assets/files/default.json5 b/config/deployment_assets/files/default.json5 new file mode 100644 index 00000000..a432cc0e --- /dev/null +++ b/config/deployment_assets/files/default.json5 @@ -0,0 +1,27 @@ +{ + + // This config file keeps track of the location of the Installation / Boostrap config files + // used to deploy the lab (and its subclouds, if any) + // All the files are assumed to be stored on the Central Cloud in the case of a DC system. + + "controller" : { + deployment_config_file: "/home/sysadmin/deployment-config.yaml", + }, + + "subclouds" : { + + "subcloud1": { + bootstrap_file: "/home/sysadmin/subcloud1/subcloud1-bootstrap-values.yaml", + deployment_config_file: "/home/sysadmin/subcloud1/subcloud1-deploy-standard.yaml", + install_file: "/home/sysadmin/subcloud1/subcloud1-install-values.yaml" + }, + + "subcloud2": { + bootstrap_file: "/home/sysadmin/subcloud2/subcloud2-bootstrap-values.yaml", + deployment_config_file: "/home/sysadmin/subcloud2/subcloud2-deploy-standard.yaml", + install_file: "/home/sysadmin/subcloud2/subcloud2-install-values.yaml" + }, + + }, + +} \ No newline at end of file diff --git a/config/deployment_assets/objects/deployment_assets.py b/config/deployment_assets/objects/deployment_assets.py new file mode 100644 index 00000000..4994bd77 --- /dev/null +++ b/config/deployment_assets/objects/deployment_assets.py @@ -0,0 +1,53 @@ +from typing import Dict + + +class DeploymentAssets: + """ + Class for DeploymentAssets object + """ + + def __init__(self, deployment_assets_dict: Dict[str, str]): + """ + Constructor + + Args: + deployment_assets_dict (Dict[str, str]): Dictionary version of the deployment_assets config for controllers or a given subcloud. + """ + self.bootstrap_file = None + if "bootstrap_file" in deployment_assets_dict: + self.bootstrap_file = deployment_assets_dict["bootstrap_file"] + + self.deployment_config_file = None + if "deployment_config_file" in deployment_assets_dict: + self.deployment_config_file = deployment_assets_dict["deployment_config_file"] + + self.install_file = None + if "install_file" in deployment_assets_dict: + self.install_file = deployment_assets_dict["install_file"] + + def get_bootstrap_file(self) -> str: + """ + Getter for the boostrap_file + + Returns (str): boostrap_file + + """ + return self.bootstrap_file + + def get_deployment_config_file(self) -> str: + """ + Getter for the deployment_config_file + + Returns (str): deployment_config_file + + """ + return self.deployment_config_file + + def get_install_file(self) -> str: + """ + Getter for the install_file + + Returns (str): install_file + + """ + return self.install_file diff --git a/config/deployment_assets/objects/deployment_assets_config.py b/config/deployment_assets/objects/deployment_assets_config.py new file mode 100644 index 00000000..d3ef8196 --- /dev/null +++ b/config/deployment_assets/objects/deployment_assets_config.py @@ -0,0 +1,50 @@ +import json5 + +from config.deployment_assets.objects.deployment_assets import DeploymentAssets + + +class DeploymentAssetsConfig: + """ + Class to hold configuration for Deployment Assets + """ + + def __init__(self, config): + try: + json_data = open(config) + except FileNotFoundError: + print(f"Could not find the Deployment Assets config file: {config}") + raise + + deployment_assets_dict = json5.load(json_data) + self.controller_deployment_assets = DeploymentAssets(deployment_assets_dict["controller"]) + + self.subclouds_deployment_assets = {} + if "subclouds" in deployment_assets_dict: + subclouds_dict = deployment_assets_dict["subclouds"] + for subcloud_name in subclouds_dict.keys(): + self.subclouds_deployment_assets[subcloud_name] = DeploymentAssets(subclouds_dict[subcloud_name]) + + def get_controller_deployment_assets(self) -> DeploymentAssets: + """ + Getter for the controller deployment assets + + Returns: + DeploymentAssets: + + """ + return self.controller_deployment_assets + + def get_subcloud_deployment_assets(self, subcloud_name: str) -> DeploymentAssets: + """ + Getter for the deployment assets associated with the specified subcloud. + + Args: + subcloud_name (str): Name of the subcloud. + + Returns: + DeploymentAssets: + + """ + if subcloud_name not in self.subclouds_deployment_assets: + raise Exception(f"There is no DeploymentAssets configuration set for {subcloud_name}") + return self.subclouds_deployment_assets[subcloud_name] diff --git a/testcases/conftest.py b/testcases/conftest.py index 327683ba..a0e93c63 100644 --- a/testcases/conftest.py +++ b/testcases/conftest.py @@ -16,6 +16,7 @@ def pytest_addoption(parser: Any): """ parser.addoption("--lab_config_file", action="store") + parser.addoption("--deployment_assets_config_file", action="store") parser.addoption("--k8s_config_file", action="store") parser.addoption("--ptp_config_file", action="store") parser.addoption("--logger_config_file", action="store") diff --git a/unit_tests/config/deployment_assets/custom_deployment_assets_config.json5 b/unit_tests/config/deployment_assets/custom_deployment_assets_config.json5 new file mode 100644 index 00000000..17505935 --- /dev/null +++ b/unit_tests/config/deployment_assets/custom_deployment_assets_config.json5 @@ -0,0 +1,19 @@ +{ + + // File used for unit testing. + + "controller" : { + deployment_config_file: "Hooray!", + }, + + "subclouds" : { + + "subcloud4": { + bootstrap_file: "StarlingX", + deployment_config_file: "Is", + install_file: "Awesome" + }, + + }, + +} \ No newline at end of file diff --git a/unit_tests/config/deployment_assets/deployment_assets_config_test.py b/unit_tests/config/deployment_assets/deployment_assets_config_test.py new file mode 100644 index 00000000..c97c1cbf --- /dev/null +++ b/unit_tests/config/deployment_assets/deployment_assets_config_test.py @@ -0,0 +1,35 @@ +from config.configuration_file_locations_manager import ConfigurationFileLocationsManager +from config.configuration_manager import ConfigurationManagerClass +from framework.resources.resource_finder import get_stx_resource_path + + +def test_default_deployment_assets_config(): + """ + Tests that the default deployment assets configuration is as expected. + + """ + configuration_manager = ConfigurationManagerClass() + config_file_locations = ConfigurationFileLocationsManager() + configuration_manager.load_configs(config_file_locations) + default_config = configuration_manager.get_deployment_assets_config() + + assert default_config is not None, "Default deployment_assets config wasn't loaded successfully" + assert not default_config.get_controller_deployment_assets().get_bootstrap_file(), "There should be no Boostrap Config for controller" + assert default_config.get_controller_deployment_assets().get_deployment_config_file() == "/home/sysadmin/deployment-config.yaml", "There should be a Deployment Config for controller" + assert default_config.get_subcloud_deployment_assets("subcloud1").get_deployment_config_file() == "/home/sysadmin/subcloud1/subcloud1-deploy-standard.yaml", "There should be a Deployment Config for subcloud1" + + +def test_custom_deployment_assets_config(): + """ + Tests that we can load a custom lab files configuration. + + """ + custom_file = get_stx_resource_path("unit_tests/config/deployment_assets/custom_deployment_assets_config.json5") + configuration_manager = ConfigurationManagerClass() + config_file_locations = ConfigurationFileLocationsManager() + config_file_locations.set_deployment_assets_config_file(custom_file) + configuration_manager.load_configs(config_file_locations) + + custom_config = configuration_manager.get_deployment_assets_config() + assert custom_config is not None, "Custom deployment assets config wasn't loaded successfully" + assert custom_config.get_subcloud_deployment_assets("subcloud4").get_install_file() == "Awesome", "The Custom Config file values aren't loaded correctly."