From fae03d45ab74a87ce0ff2342e18f77a852344cb5 Mon Sep 17 00:00:00 2001 From: Abhishek jaiswal Date: Mon, 21 Apr 2025 07:25:02 -0400 Subject: [PATCH] Refactor phased deployment test case and keywords This commit refactors the phased deployment test case and associated keywords to use the new configuration for retrieving labs and their deployment assets. * The test case and keywords have been updated to utilize the new configuration system. * This ensures that the tests accurately reflect the current lab setup and deployment process. * Removes reliance on older methods of obtaining lab and deployment information. Change-Id: I26e7b170ff07711b999486665153ab00812e874c Signed-off-by: Abhishek jaiswal --- config/lab/objects/lab_config.py | 13 +- .../dcmanager_subcloud_add_keywords.py | 2 +- .../dcmanager_subcloud_deploy_keywords.py | 383 +++++------------- .../dcmanager_subcloud_list_keywords.py | 2 +- .../test_subcloud_phased_deployment.py | 202 ++------- 5 files changed, 145 insertions(+), 457 deletions(-) diff --git a/config/lab/objects/lab_config.py b/config/lab/objects/lab_config.py index 842ae6b1..fb611d40 100644 --- a/config/lab/objects/lab_config.py +++ b/config/lab/objects/lab_config.py @@ -496,5 +496,16 @@ class LabConfig: List[str]: List of subcloud names of the specified type """ if subcloud_type is None: - return self.subclouds + return [subcloud.get_lab_name() for subcloud in self.subclouds] return [subcloud.get_lab_name() for subcloud in self.get_subclouds_by_type(subcloud_type)] + + def get_first_controller(self) -> Optional[Node]: + """Get the first controller node. + + Returns: + Optional[Node]: The first controller node if found, None otherwise + """ + controllers = self.get_controllers() + if len(controllers) > 0: + return controllers[0] + return None diff --git a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_add_keywords.py b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_add_keywords.py index d2a3e7a8..17184840 100644 --- a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_add_keywords.py +++ b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_add_keywords.py @@ -36,7 +36,7 @@ class DcManagerSubcloudAddKeywords(BaseKeyword): install_file = sc_assets.get_install_file() # Get the subcloud bootstrap address - boot_add = sc_config.get_nodes()[0].get_ip() + boot_add = sc_config.get_first_controller().get_ip() admin_creds = sc_config.get_admin_credentials() # Execute the command diff --git a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_deploy_keywords.py b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_deploy_keywords.py index 2f23e4a7..5dc1d9ad 100644 --- a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_deploy_keywords.py +++ b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_deploy_keywords.py @@ -1,15 +1,8 @@ -import os -import re - from config.configuration_manager import ConfigurationManager -from framework.logging.automation_logger import get_logger from framework.ssh.ssh_connection import SSHConnection -from framework.validation.validation import validate_equals_with_retry from keywords.base_keyword import BaseKeyword from keywords.cloud_platform.command_wrappers import source_openrc from keywords.cloud_platform.dcmanager.dcmanager_subcloud_list_keywords import DcManagerSubcloudListKeywords -from keywords.cloud_platform.dcmanager.objects.dcmanager_subcloud_config_files_object import DcManagerSubcloudConfigFilesObject -from keywords.cloud_platform.dcmanager.objects.dcmanager_subcloud_deploy_object import DcManagerSubcloudDeployObject class DCManagerSubcloudDeployKeywords(BaseKeyword): @@ -26,317 +19,125 @@ class DCManagerSubcloudDeployKeywords(BaseKeyword): """ self.ssh_connection = ssh_connection - # States of the subcloud create - CREATE_EXECUTION_FAILED = "create-failed" - CREATE_EXECUTED = "create-complete" - - # States of the subcloud install - INSTALL_EXECUTION_FAILED = "install-failed" - INSTALL_EXECUTING = "installing" - INSTALL_EXECUTED = "install-complete" - - # States of the subcloud bootstrap - BOOTSTRAP_EXECUTION_FAILED = "bootstrap-failed" - BOOTSTRAP_EXECUTING = "bootstrapping" - BOOTSTRAP_EXECUTED = "bootstrap-complete" - - # States of the subcloud config - CONFIG_EXECUTION_FAILED = "config-failed" - CONFIG_EXECUTED = "complete" - - # Timeout values for the states of subcloud deploy - SUBCLOUD_DEPLOY_CREATE = 180 - SUBCLOUD_DEPLOY_INSTALL = 1200 - SUBCLOUD_DEPLOY_BOOTSTRAP = 2700 - SUBCLOUD_DEPLOY_CONFIG = 2700 - - def find_config_filename(self, folder_path: str, phase: str, files: list[str]) -> str: - """ - Find the configuration filename for a specific phase in the given folder. + def dcmanager_subcloud_deploy_abort(self, subcloud_name: str): + """Aborts the subcloud deployment using 'dcmanager subcloud deploy abort'. Args: - folder_path (str): The path to the folder containing configuration files - phase (str): The deployment phase to find (e.g., 'install', 'bootstrap', 'deploy') - files (list[str]): List of filenames in the folder to search through - - Returns: - str: The full path to the configuration file for the specified phase - - Raises: - ValueError: If files list is empty or None - FileNotFoundError: If no configuration file is found for the specified phase + subcloud_name (str): a str name for the subcloud. """ - if not files: - error_msg = f"No files found in folder {folder_path} for phase {phase}" - get_logger().log_error(error_msg) - raise ValueError(error_msg) - - matching_files = [file_name for file_name in files if phase in file_name] - if not matching_files: - error_msg = f"No configuration file found for phase {phase} in {folder_path}" - get_logger().log_error(error_msg) - raise FileNotFoundError(error_msg) - - # Use the first matching file if multiple exist - config_file = os.path.join(folder_path, matching_files[0].rstrip("\n")) - get_logger().log_info(f"Found configuration file for phase {phase}: {config_file}") - return config_file - - def get_subcloud_config_files(self, subcloud: str) -> DcManagerSubcloudConfigFilesObject: - """ - Get subcloud config YAML files - - Args: - subcloud (str): Name of the subcloud - - Returns: - DcManagerSubcloudConfigFilesObject: Object containing paths to configuration files - """ - lab_config = ConfigurationManager.get_lab_config() - user_name = lab_config.get_admin_credentials().get_user_name() - match = re.search(r"\d+$", subcloud) - num = int(match.group()) - folder_name = f"subcloud-{num}" - - subcloud_folder = f"/home/{user_name}/{folder_name}" - get_logger().log_info(f"subcloud_folder {subcloud_folder}") - - file_phases = ["install", "bootstrap", "deploy"] - files = self.ssh_connection.send(f"ls {subcloud_folder}") - - install_file = None - bootstrap_file = None - deploy_file = None - - for phase in file_phases: - file_name = self.find_config_filename(subcloud_folder, phase, files) - get_logger().log_info(f"config file of {phase} is {file_name}") - - if phase == "install": - install_file = file_name - elif phase == "bootstrap": - bootstrap_file = file_name - elif phase == "deploy": - deploy_file = file_name - - return DcManagerSubcloudConfigFilesObject(install_file=install_file, bootstrap_file=bootstrap_file, deploy_file=deploy_file) - - def check_deploy_status(self, subcloud: str) -> str: - """ - Get the deploy status of the subcloud - - Args: - subcloud (str): Name or ID of the subcloud - - Returns: - str: - Deployment status of the subcloud(deploy_status) - - """ - dcmanager_subcloud_list_keywords = DcManagerSubcloudListKeywords(self.ssh_connection) - dcmanager_subcloud_list = dcmanager_subcloud_list_keywords.get_dcmanager_subcloud_list() - subcloud = dcmanager_subcloud_list.get_subcloud_by_name(subcloud) - deploy_status = subcloud.get_deploy_status() - return deploy_status - - def deploy_create_subcloud( - self, - deploy_params: DcManagerSubcloudDeployObject, - ) -> str: - """ - Perform subcloud configuration on the System Controller without execution of subsequent phases - - Args: - deploy_params (DcManagerSubcloudDeployObject): Object containing all deployment parameters - - Returns: - str: - Deployment status of the subcloud(deploy_status) - """ - operation = "create" - subcloud = deploy_params.get_subcloud() - get_logger().log_info(f"Attempt to deploy {operation} : {subcloud}") - - cmd = f"dcmanager subcloud deploy {operation} --bootstrap-address {deploy_params.get_bootstrap_address()} --bootstrap-values {deploy_params.get_bootstrap_values()}" - - if deploy_params.get_install_values(): - cmd += f" --install-values {deploy_params.get_install_values()}" - if deploy_params.get_bmc_password(): - cmd += f" --bmc-password {deploy_params.get_bmc_password()}" - if deploy_params.get_deploy_config(): - cmd += f" --deploy-config {deploy_params.get_deploy_config()}" - if deploy_params.get_group(): - cmd += f" --group {deploy_params.get_group()}" - if deploy_params.get_release(): - cmd += f" --release {deploy_params.get_release()}" - + # Execute the command + cmd = f"dcmanager subcloud deploy abort {subcloud_name}" self.ssh_connection.send(source_openrc(cmd)) self.validate_success_return_code(self.ssh_connection) - def check_deploy_create_status() -> str: - """ - Checks the subcloud deploy status - """ - return self.check_deploy_status(subcloud) - - check_interval = 30 - validate_equals_with_retry( - function_to_execute=check_deploy_create_status, - expected_value=self.CREATE_EXECUTED, - validation_description=f"Deploy create for subcloud {subcloud} completed.", - timeout=self.SUBCLOUD_DEPLOY_CREATE, - polling_sleep_time=check_interval, - ) - - subcloud_obj = DcManagerSubcloudListKeywords(self.ssh_connection).get_dcmanager_subcloud_list().get_subcloud_by_name(subcloud) - deploy_status = subcloud_obj.get_deploy_status() - return deploy_status - - def deploy_install_subcloud( - self, - deploy_params: DcManagerSubcloudDeployObject, - ) -> str: - """ - Perform install operation only (no bootstrap) + def dcmanager_subcloud_deploy_complete(self, subcloud_name: str): + """Completes the subcloud deployment using 'dcmanager subcloud deploy complete'. Args: - deploy_params (DcManagerSubcloudDeployObject): Object containing all deployment parameters - - Returns: - str: - Deployment status of the subcloud(deploy_status) + subcloud_name (str): a str name for the subcloud. """ - operation = "install" - subcloud = deploy_params.get_subcloud() - get_logger().log_info(f"Attempt to deploy {operation} : {subcloud}") - - # Get sysadmin password from lab config - sysadmin_password = ConfigurationManager.get_lab_config().get_admin_credentials().get_password() - cmd = f"dcmanager subcloud deploy {operation} {subcloud} --sysadmin-password {sysadmin_password}" - - if deploy_params.get_install_values(): - cmd += f" --install-values {deploy_params.get_install_values()}" - if deploy_params.get_bmc_password(): - cmd += f" --bmc-password {deploy_params.get_bmc_password()}" - if deploy_params.get_group(): - cmd += f" --group {deploy_params.get_group()}" - if deploy_params.get_release(): - cmd += f" --release {deploy_params.get_release()}" - + # Execute the command + cmd = f"dcmanager subcloud deploy complete {subcloud_name}" self.ssh_connection.send(source_openrc(cmd)) self.validate_success_return_code(self.ssh_connection) - def check_deploy_install_status() -> str: - """ - Checks the subcloud deploy status - """ - return self.check_deploy_status(subcloud) - - check_interval = 60 - validate_equals_with_retry( - function_to_execute=check_deploy_install_status, - expected_value=self.INSTALL_EXECUTED, - validation_description=f"Deploy install for subcloud {subcloud} completed.", - timeout=self.SUBCLOUD_DEPLOY_INSTALL, - polling_sleep_time=check_interval, - ) - - subcloud_obj = DcManagerSubcloudListKeywords(self.ssh_connection).get_dcmanager_subcloud_list().get_subcloud_by_name(subcloud) - deploy_status = subcloud_obj.get_deploy_status() - return deploy_status - - def deploy_bootstrap_subcloud( - self, - deploy_params: DcManagerSubcloudDeployObject, - ) -> str: - """ - Perform the bootstrap operation only (perform play or replay) + def dcmanager_subcloud_deploy_create(self, subcloud_name: str): + """Creates the subcloud using 'dcmanager subcloud deploy create'. Args: - deploy_params (DcManagerSubcloudDeployObject): Object containing all deployment parameters - - Returns: - str: - Deployment status of the subcloud(deploy_status) + subcloud_name (str): a str name for the subcloud. """ - operation = "bootstrap" - subcloud = deploy_params.get_subcloud() - get_logger().log_info(f"Attempt to deploy {operation} : {subcloud}") - - # Get sysadmin password from lab config - sysadmin_password = ConfigurationManager.get_lab_config().get_admin_credentials().get_password() - cmd = f"dcmanager subcloud deploy {operation} {subcloud} --sysadmin-password {sysadmin_password}" - - if deploy_params.get_bootstrap_values(): - cmd += f" --bootstrap-values {deploy_params.get_bootstrap_values()}" - if deploy_params.get_bootstrap_address(): - cmd += f" --bootstrap-address {deploy_params.get_bootstrap_address()}" + # Get the subcloud config + sc_config = ConfigurationManager.get_lab_config().get_subcloud(subcloud_name) + # Get the subcloud deployment assets + deployment_assets_config = ConfigurationManager.get_deployment_assets_config() + sc_assets = deployment_assets_config.get_subcloud_deployment_assets(subcloud_name) + bootstrap_file = sc_assets.get_bootstrap_file() + deploy_file = sc_assets.get_deployment_config_file() + install_file = sc_assets.get_install_file() + # Get the subcloud bootstrap address + boot_add = sc_config.get_first_controller().get_ip() + # Execute the command + cmd = f"dcmanager subcloud deploy create --bootstrap-address {boot_add} --bootstrap-values {bootstrap_file} --install-values {install_file} --bmc-password {sc_config.get_bm_password()} --deploy-config {deploy_file} " self.ssh_connection.send(source_openrc(cmd)) self.validate_success_return_code(self.ssh_connection) - def check_deploy_bootstrap_status() -> str: - """ - Checks the subcloud deploy status - """ - return self.check_deploy_status(subcloud) + # validate subcloud status until complete + success_status = "create-complete" + dc_manager_sc_list_kw = DcManagerSubcloudListKeywords(self.ssh_connection) + dc_manager_sc_list_kw.validate_subcloud_status(subcloud_name, success_status) - check_interval = 60 - validate_equals_with_retry( - function_to_execute=check_deploy_bootstrap_status, - expected_value=self.BOOTSTRAP_EXECUTED, - validation_description=f"Deploy bootstrap for subcloud {subcloud} completed.", - timeout=self.SUBCLOUD_DEPLOY_BOOTSTRAP, - polling_sleep_time=check_interval, - ) - - subcloud_obj = DcManagerSubcloudListKeywords(self.ssh_connection).get_dcmanager_subcloud_list().get_subcloud_by_name(subcloud) - deploy_status = subcloud_obj.get_deploy_status() - return deploy_status - - def deploy_config_subcloud( - self, - deploy_params: DcManagerSubcloudDeployObject, - ) -> str: - """ - Perform deployment config/reconfig only + def dcmanager_subcloud_deploy_install(self, subcloud_name: str): + """Installs the subcloud using 'dcmanager subcloud deploy install'. Args: - deploy_params (DcManagerSubcloudDeployObject): Object containing all deployment parameters - - Returns: - str: - Deployment status of the subcloud(deploy_status) + subcloud_name (str): a str name for the subcloud. """ - operation = "config" - subcloud = deploy_params.get_subcloud() - get_logger().log_info(f"Attempt to deploy {operation} : {subcloud}") + # Get the subcloud config + deployment_assets_config = ConfigurationManager.get_deployment_assets_config() + sc_config = ConfigurationManager.get_lab_config().get_subcloud(subcloud_name) + sc_assets = deployment_assets_config.get_subcloud_deployment_assets(subcloud_name) - # Get sysadmin password from lab config - sysadmin_password = ConfigurationManager.get_lab_config().get_admin_credentials().get_password() - cmd = f"dcmanager subcloud deploy {operation} {subcloud} --sysadmin-password {sysadmin_password}" - - if deploy_params.get_deploy_config(): - cmd += f" --deploy-config {deploy_params.get_deploy_config()}" + admin_creds = sc_config.get_admin_credentials() + install_file = sc_assets.get_install_file() + # Execute the command + cmd = f"dcmanager subcloud deploy install {subcloud_name} --sysadmin-password {admin_creds.get_password()} --bmc-password {sc_config.get_bm_password()} --install-values {install_file} " self.ssh_connection.send(source_openrc(cmd)) self.validate_success_return_code(self.ssh_connection) - def check_deploy_config_status() -> str: - """ - Checks the subcloud deploy status - """ - return self.check_deploy_status(subcloud) + # validate subcloud status until complete + success_status = "install-complete" + dc_manager_sc_list_kw = DcManagerSubcloudListKeywords(self.ssh_connection) + dc_manager_sc_list_kw.validate_subcloud_status(subcloud_name, success_status) - check_interval = 60 - validate_equals_with_retry( - function_to_execute=check_deploy_config_status, - expected_value=self.CONFIG_EXECUTED, - validation_description=f"Deploy config for subcloud {subcloud} completed.", - timeout=self.SUBCLOUD_DEPLOY_CONFIG, - polling_sleep_time=check_interval, - ) + def dcmanager_subcloud_deploy_bootstrap(self, subcloud_name: str): + """Bootstraps the subcloud using 'dcmanager subcloud deploy bootstrap'. - subcloud_obj = DcManagerSubcloudListKeywords(self.ssh_connection).get_dcmanager_subcloud_list().get_subcloud_by_name(subcloud) - deploy_status = subcloud_obj.get_deploy_status() - return deploy_status + Args: + subcloud_name (str): a str name for the subcloud. + """ + # Get the subcloud config + deployment_assets_config = ConfigurationManager.get_deployment_assets_config() + sc_config = ConfigurationManager.get_lab_config().get_subcloud(subcloud_name) + sc_assets = deployment_assets_config.get_subcloud_deployment_assets(subcloud_name) + + admin_creds = sc_config.get_admin_credentials() + bootstrap_file = sc_assets.get_bootstrap_file() + # Get the subcloud bootstrap address + boot_add = sc_config.get_first_controller().get_ip() + + # Execute the command + cmd = f"dcmanager subcloud deploy bootstrap {subcloud_name} --sysadmin-password {admin_creds.get_password()} --bootstrap-address {boot_add} --bootstrap-values {bootstrap_file} " + self.ssh_connection.send(source_openrc(cmd)) + self.validate_success_return_code(self.ssh_connection) + + # validate subcloud status until complete + success_status = "bootstrap-complete" + dc_manager_sc_list_kw = DcManagerSubcloudListKeywords(self.ssh_connection) + dc_manager_sc_list_kw.validate_subcloud_status(subcloud_name, success_status) + + def dcmanager_subcloud_deploy_config(self, subcloud_name: str): + """Configures the subcloud using 'dcmanager subcloud deploy config'. + + Args: + subcloud_name (str): a str name for the subcloud. + """ + # Get the subcloud config + deployment_assets_config = ConfigurationManager.get_deployment_assets_config() + sc_config = ConfigurationManager.get_lab_config().get_subcloud(subcloud_name) + sc_assets = deployment_assets_config.get_subcloud_deployment_assets(subcloud_name) + + admin_creds = sc_config.get_admin_credentials() + deploy_file = sc_assets.get_deployment_config_file() + + # Execute the command + cmd = f"dcmanager subcloud deploy config {subcloud_name} --sysadmin-password {admin_creds.get_password()} --deploy-config {deploy_file} " + self.ssh_connection.send(source_openrc(cmd)) + self.validate_success_return_code(self.ssh_connection) + + # validate subcloud status until complete + success_status = "complete" + dc_manager_sc_list_kw = DcManagerSubcloudListKeywords(self.ssh_connection) + dc_manager_sc_list_kw.validate_subcloud_status(subcloud_name, success_status) diff --git a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_list_keywords.py b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_list_keywords.py index 1d738ed5..8d563ff4 100644 --- a/keywords/cloud_platform/dcmanager/dcmanager_subcloud_list_keywords.py +++ b/keywords/cloud_platform/dcmanager/dcmanager_subcloud_list_keywords.py @@ -51,7 +51,7 @@ class DcManagerSubcloudListKeywords(BaseKeyword): Exception: if the subcloud is in a failed state. """ - failed_status = ["bootstrap-failed", "install-failed", "create-failed"] + failed_status = ["bootstrap-failed", "install-failed", "create-failed", "config-failed"] time_out = 4800 polling_sleep_time = 60 end_time = time.time() + time_out diff --git a/testcases/cloud_platform/regression/dc/phased_deployment/test_subcloud_phased_deployment.py b/testcases/cloud_platform/regression/dc/phased_deployment/test_subcloud_phased_deployment.py index 527fa5b8..ecfbc849 100644 --- a/testcases/cloud_platform/regression/dc/phased_deployment/test_subcloud_phased_deployment.py +++ b/testcases/cloud_platform/regression/dc/phased_deployment/test_subcloud_phased_deployment.py @@ -1,180 +1,56 @@ -import time +from pytest import mark -import yaml -from pytest import fail, mark - -from config.configuration_manager import ConfigurationManager from framework.logging.automation_logger import get_logger -from framework.ssh.ssh_connection import SSHConnection -from framework.validation.validation import validate_equals from keywords.cloud_platform.dcmanager.dcmanager_subcloud_delete_keywords import DcManagerSubcloudDeleteKeywords from keywords.cloud_platform.dcmanager.dcmanager_subcloud_deploy_keywords import DCManagerSubcloudDeployKeywords from keywords.cloud_platform.dcmanager.dcmanager_subcloud_list_keywords import DcManagerSubcloudListKeywords -from keywords.cloud_platform.dcmanager.objects.dcmanager_subcloud_address_object import DcManagerSubcloudAddressObject -from keywords.cloud_platform.dcmanager.objects.dcmanager_subcloud_deploy_object import DcManagerSubcloudDeployObject -from keywords.cloud_platform.dcmanager.objects.dcmanger_subcloud_list_availability_enum import DcManagerSubcloudListAvailabilityEnum -from keywords.cloud_platform.dcmanager.objects.dcmanger_subcloud_list_management_enum import DcManagerSubcloudListManagementEnum +from keywords.cloud_platform.dcmanager.dcmanager_subcloud_manager_keywords import DcManagerSubcloudManagerKeywords from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords -from keywords.files.file_keywords import FileKeywords -def select_test_subcloud(ssh_connection: SSHConnection) -> str: - """ - Select the subcloud to perform the test on. - - Args: - ssh_connection(SSHConnection): The ssh connection of the active controller - - Returns: - str: - Subcloud name to test on - """ - subcloud_list_keywords = DcManagerSubcloudListKeywords(ssh_connection) - subclouds_list = subcloud_list_keywords.get_dcmanager_subcloud_list() - real_subclouds = subclouds_list.get_dcmanager_subcloud_list_objects() - if len(real_subclouds) == 0: - get_logger().log_error("No subclouds found for testing.") - fail("No subclouds found for testing.") - - for subcloud in real_subclouds: - # Get the subcloud with state unmanaged and offline - if subcloud.get_availability == DcManagerSubcloudListManagementEnum.UNMANAGED and subcloud.get_availability == DcManagerSubcloudListAvailabilityEnum.OFFLINE: - return subcloud.get_name() - - get_logger().log_error("No subcloud found with required state (UNMANAGED and OFFLINE) for testing.") - fail("No subcloud found with required state (UNMANAGED and OFFLINE) for testing.") - - -def get_bmc_bootstrap_address(ssh_connection: SSHConnection, subcloud: str) -> DcManagerSubcloudAddressObject: - """ - Get bmc & bootstrap address from install-values-.yaml file - - Args: - ssh_connection (SSHConnection): The ssh connection of the active controller - subcloud (str): Name of the subcloud - - Raises: - FileNotFoundError: If the file does not exist. - KeyError: If required keys are missing in the file. - - Returns: - DcManagerSubcloudAddressObject: Object containing BMC and bootstrap addresses - """ - get_logger().log_info(f"Get BMC and bootstrap address for {subcloud}") - config_files = DCManagerSubcloudDeployKeywords(ssh_connection).get_subcloud_config_files(subcloud) - install_values_file_path = config_files.get_install_file() - if not FileKeywords(ssh_connection).file_exists(install_values_file_path): - raise FileNotFoundError(f"{install_values_file_path} is not found") - - get_logger().log_info(f"Get BMC & bootstrap addresses from {install_values_file_path}") - stream = ssh_connection.send("cat {}".format(install_values_file_path)) - stream_string = "\n".join(stream) - install_params = yaml.load(stream_string, Loader=yaml.SafeLoader) - install_param_yaml = yaml.dump(install_params, default_flow_style=False) - get_logger().log_info(f"Loaded install-values parameters:{install_param_yaml}") - - if "bmc_address" not in install_params or "bootstrap_address" not in install_params: - raise KeyError(f"Missing required keys in {install_values_file_path}. Available keys: {list(install_params.keys())}") - - bmc_address = install_params["bmc_address"] - bootstrap_address = install_params["bootstrap_address"] - - if not bmc_address or not bootstrap_address: - raise ValueError(f"BMC address or bootstrap address cannot be empty in {install_values_file_path}") - - get_logger().log_info(f"Extracted BMC address: {bmc_address}, Bootstrap address: {bootstrap_address}") - - return DcManagerSubcloudAddressObject(bmc_address=bmc_address, bootstrap_address=bootstrap_address) - - -def capture_kpi(node_name: str, start_time: str, end_time: str, stage: str): - """ - Capture kpi for subcloud deploy phases from start and end time - - Args: - node_name (str): Name of the noden - start_time (str): The start time of the specified stage execution - end_time (str): The end time of the specified stage execution - stage (str): The stage of the execution - """ - time_taken = float(end_time) - float(start_time) - get_logger().log_info(f"------The time taken for the node {node_name} to finish the stage {stage} is {time_taken} seconds-------") - - -@mark.p1 -@mark.lab_has_subcloud -def test_kpi_subcloud_deploy_phases(): - """Capture Kpi for subcloud deploy - verify subcloud deploy create, install, bootstrap and config with KPI's for each phase +@mark.p0 +@mark.lab_has_min_2_subclouds +def test_phased_deployment(request): + """Test Phased deployment steps for subcloud deployment. Test Steps: - - Verify subcloud deploy create - - Verify subcloud deploy install - - Verify subcloud deploy bootstrap - - Verify subcloud deploy config - - Collect KPI data for create, install, bootstrap and config phases + - log onto system controller + - get the ssh connection to the active controller + - execute the phased deployment create + - execute the phased deployment install + - execute the phased deployment bootstrap + - execute the phased deployment config + - execute the phased deployment complete + - delete the subcloud """ - get_logger().log_info("Starting 'test_kpi_subcloud_deploy_phases' test case.") - - # Gets the SSH connection to the active controller of the central cloud. ssh_connection = LabConnectionKeywords().get_active_controller_ssh() + dcm_sc_list_kw = DcManagerSubcloudListKeywords(ssh_connection) + subcloud_name = dcm_sc_list_kw.get_dcmanager_subcloud_list().get_undeployed_subcloud_name(None) + dcm_sc_deploy_kw = DCManagerSubcloudDeployKeywords(ssh_connection) + # dcmanager subcloud deploy create + get_logger().log_info(f"dcmanager subcloud deploy create {subcloud_name}.") + dcm_sc_deploy_kw.dcmanager_subcloud_deploy_create(subcloud_name) - # Get subcloud to perform the test on - subcloud = select_test_subcloud(ssh_connection) - get_logger().log_info(f"Selected subcloud for testing: {subcloud}") + # dcmanager subcloud deploy install + get_logger().log_info(f"dcmanager subcloud deploy install {subcloud_name}.") + dcm_sc_deploy_kw.dcmanager_subcloud_deploy_install(subcloud_name) - # Delete the selected subcloud to test on - DcManagerSubcloudDeleteKeywords(ssh_connection).dcmanager_subcloud_delete(subcloud) + # dcmanager subcloud deploy bootstrap + get_logger().log_info(f"dcmanager subcloud deploy bootstrap {subcloud_name}.") + dcm_sc_deploy_kw.dcmanager_subcloud_deploy_bootstrap(subcloud_name) - # Get sysadmin password from lab config - sysadmin_password = ConfigurationManager.get_lab_config().get_admin_credentials().get_password() + # dcmanager subcloud deploy config + get_logger().log_info(f"dcmanager subcloud deploy config {subcloud_name}.") + dcm_sc_deploy_kw.dcmanager_subcloud_deploy_config(subcloud_name) - # Get config files - config_files = DCManagerSubcloudDeployKeywords(ssh_connection).get_subcloud_config_files(subcloud) - bootstrap_file_path = config_files.get_bootstrap_file() - install_values_file_path = config_files.get_install_file() - deploy_standard_file_path = config_files.get_deploy_file() + def teardown(): + get_logger().log_info("Phased Deployment Teardown") + dcm_sc_manager_kw = DcManagerSubcloudManagerKeywords(ssh_connection) + # poweroff the subcloud. + get_logger().log_test_case_step(f"Poweroff subcloud={subcloud_name}.") + dcm_sc_manager_kw.set_subcloud_poweroff(subcloud_name) + # delete the subcloud. + dcm_sc_del_kw = DcManagerSubcloudDeleteKeywords(ssh_connection) + dcm_sc_del_kw.dcmanager_subcloud_delete(subcloud_name) - get_logger().log_info(f"Verify subcloud deploy create {subcloud}") - - # Get BMC and bootstrap addresses - address_info = get_bmc_bootstrap_address(ssh_connection, subcloud) - - # Create phase - start_time = time.time() - deploy_params = DcManagerSubcloudDeployObject(subcloud=subcloud, bootstrap_address=address_info.get_bootstrap_address(), bootstrap_values=bootstrap_file_path) - DCManagerSubcloudDeployKeywords(ssh_connection).deploy_create_subcloud(deploy_params) - create_end_time = time.time() - create_duration = create_end_time - start_time - get_logger().log_info(f"Subcloud deploy create duration: {create_duration} seconds") - - # Install phase - start_time = time.time() - deploy_params = DcManagerSubcloudDeployObject(subcloud=subcloud, install_values=install_values_file_path, bmc_password=sysadmin_password) - DCManagerSubcloudDeployKeywords(ssh_connection).deploy_install_subcloud(deploy_params) - install_end_time = time.time() - install_duration = install_end_time - start_time - get_logger().log_info(f"Subcloud deploy install duration: {install_duration} seconds") - - # Bootstrap phase - start_time = time.time() - deploy_params = DcManagerSubcloudDeployObject(subcloud=subcloud, bootstrap_values=bootstrap_file_path, bootstrap_address=address_info.get_bootstrap_address(), bmc_password=sysadmin_password) - DCManagerSubcloudDeployKeywords(ssh_connection).deploy_bootstrap_subcloud(deploy_params) - bootstrap_end_time = time.time() - bootstrap_duration = bootstrap_end_time - start_time - get_logger().log_info(f"Subcloud deploy bootstrap duration: {bootstrap_duration} seconds") - - # Config phase - start_time = time.time() - deploy_params = DcManagerSubcloudDeployObject(subcloud=subcloud, deploy_config=deploy_standard_file_path, bmc_password=sysadmin_password) - DCManagerSubcloudDeployKeywords(ssh_connection).deploy_config_subcloud(deploy_params) - config_end_time = time.time() - config_duration = config_end_time - start_time - get_logger().log_info(f"Subcloud deploy config duration: {config_duration} seconds") - - # Verify final state - subcloud_obj = DcManagerSubcloudListKeywords(ssh_connection).get_dcmanager_subcloud_list().get_subcloud_by_name(subcloud) - validate_equals(subcloud_obj.get_deploy_status, DCManagerSubcloudDeployKeywords.CONFIG_EXECUTED, f"Succeeded to verify subcloud deploy config {subcloud}") - end_time = time.time() - total_duration = end_time - start_time - get_logger().log_info(f"Total subcloud deploy duration: {total_duration} seconds") + request.addfinalizer(teardown)