Updated test to wait for subcloud go out of sync

- changes for coding guidelines
- added function to wait until it reaches it state

Change-Id: I11778823d310a11330e551e339742bf23a043d41
Signed-off-by: Abhishek jaiswal <abhishek.jaiswal@windriver.com>
This commit is contained in:
Abhishek jaiswal
2025-06-13 01:22:34 -04:00
parent 8f228b369e
commit 9acdb394eb
5 changed files with 105 additions and 59 deletions

View File

@@ -40,7 +40,7 @@ class DcmanagerPrestageStrategyKeywords(BaseKeyword):
self.ssh_connection.send(command)
self.validate_success_return_code(self.ssh_connection)
# wait for apply to complete
return self.wait_for_state(["complete", "apply-failed"])
return self.wait_for_state(["complete", "failed"])
def get_dcmanager_prestage_strategy_create(self, sysadmin_password: str, sw_deploy: bool = True) -> DcmanagerPrestageStrategyShowOutput:
"""Gets the prestage-strategy create.

View File

@@ -1,3 +1,7 @@
import time
from framework.logging.automation_logger import get_logger
from framework.ssh.ssh_connection import SSHConnection
from keywords.base_keyword import BaseKeyword
from keywords.cloud_platform.command_wrappers import source_openrc
from keywords.cloud_platform.dcmanager.objects.dcmanager_subcloud_show_output import DcManagerSubcloudShowOutput
@@ -8,27 +12,51 @@ class DcManagerSubcloudShowKeywords(BaseKeyword):
This class contains all the keywords related to the 'dcmanager subcloud show' commands.
"""
def __init__(self, ssh_connection):
"""
Constructor
Args:
ssh_connection:
def __init__(self, ssh_connection: SSHConnection):
"""Constructor
Args:
ssh_connection (SSHConnection): The SSH connection object used for executing commands.
"""
self.ssh_connection = ssh_connection
def get_dcmanager_subcloud_show(self, subcloud_name: str) -> DcManagerSubcloudShowOutput:
"""
Gets the 'dcmanager subcloud show <subcloud name>' output.
Args: subcloud_name (str): a str representing na subcloud's name.
"""Gets the 'dcmanager subcloud show <subcloud name>' output.
Args:
subcloud_name (str): The name of the subcloud to show.
Returns:
dcmanager subcloud show (DcManagerSubcloudShowOutput): a DcManagerSubcloudShowOutput object representing the
DcManagerSubcloudShowOutput: a DcManagerSubcloudShowOutput object representing the
output of the command 'dcmanager subcloud show <subcloud name>'.
"""
output = self.ssh_connection.send(source_openrc(f'dcmanager subcloud show {subcloud_name}'))
output = self.ssh_connection.send(source_openrc(f"dcmanager subcloud show {subcloud_name}"))
self.validate_success_return_code(self.ssh_connection)
dcmanager_subcloud_show_output = DcManagerSubcloudShowOutput(output)
return DcManagerSubcloudShowOutput(output)
return dcmanager_subcloud_show_output
def wait_for_state(self, subcloud_name: str, field: str, expected_status: str, timeout: int = 300, check_interval: int = 10) -> DcManagerSubcloudShowOutput:
"""
Waits for the subcloud to reach a specific state.
Args:
subcloud_name (str): The name of the subcloud.
field (str): The field to check in the subcloud status.
expected_status (str): The expected status of the field.
timeout (int): Maximum time to wait for the status change.
check_interval (int): Time interval between checks.
Returns:
DcManagerSubcloudShowOutput: The output of the subcloud show command when the expected status is reached.
"""
start_time = time.time()
while time.time() - start_time < timeout:
sc_show_obj = self.get_dcmanager_subcloud_show(subcloud_name).get_dcmanager_subcloud_show_object()
# Dynamically call the method
method_name = f"get_{field}"
result = getattr(sc_show_obj, method_name)() # Call the method
if result == expected_status:
return sc_show_obj
get_logger().log_info(f"Waiting for {field} to reach state '{expected_status}'. Current state: '{result}'")
# Sleep for the specified interval before checking again
time.sleep(check_interval)
raise TimeoutError(f"Timed out waiting for {field} to reach state '{expected_status}' after {timeout} seconds.")

View File

@@ -1,6 +1,6 @@
class DcManagerSubcloudShowObject:
"""
This class represents a detailed subcloud as object.
"""This class represents a detailed subcloud as object.
This is typically the output of the 'dcmanager subcloud show <subcloud name>' command output table as shown below.
+-----------------------------+----------------------------------+
@@ -26,6 +26,11 @@ class DcManagerSubcloudShowObject:
"""
def __init__(self, id: str):
"""Constructor for the DcManagerSubcloudShowObject class.
Args:
id (str): The unique identifier for the subcloud.
"""
self.id: str = id
self.name: str
self.description: str
@@ -418,6 +423,18 @@ class DcManagerSubcloudShowObject:
"""
self.usm_sync_status = usm_sync_status
def get_software_sync_status(self) -> str:
"""
Getter for the software Sync Status
"""
return self.software_sync_status
def set_software_sync_status(self, software_sync_status: str):
"""
Setter for the software Sync Status
"""
self.software_sync_status = software_sync_status
def get_region_name(self) -> str:
"""
Getter for the Region Name

View File

@@ -8,63 +8,61 @@ class DcManagerSubcloudShowOutput:
Represents the output of 'dcmanager subcloud show <subcloud>' command as DcManagerSubcloudListObject object.
"""
def __init__(self, dcmanager_subcloud_show_output):
def __init__(self, dcmanager_subcloud_show_output: list[str]) -> None:
"""
Constructor
Args:
dcmanager_subcloud_show_output (list(str)): the output of 'dcmanager subcloud show <subcloud>' command
dcmanager_subcloud_show_output (list[str]): the output of 'dcmanager subcloud show <subcloud>' command
"""
self.dcmanager_subcloud_show_object: DcManagerSubcloudShowObject
dcmanager_vertical_table_parser = DcManagerVerticalTableParser(dcmanager_subcloud_show_output)
output_values = dcmanager_vertical_table_parser.get_output_values_dict()
if 'id' not in output_values:
if "id" not in output_values:
raise KeywordException(f"The output {dcmanager_subcloud_show_output} was not valid because it is missing an 'id'.")
dcmanager_subcloud_show_object = DcManagerSubcloudShowObject(output_values.get('id'))
dcmanager_subcloud_show_object = DcManagerSubcloudShowObject(output_values.get("id"))
dcmanager_subcloud_show_object.set_name(output_values.get('name'))
dcmanager_subcloud_show_object.set_description(output_values.get('description'))
dcmanager_subcloud_show_object.set_location(output_values.get('location'))
dcmanager_subcloud_show_object.set_software_version(output_values.get('software_version'))
dcmanager_subcloud_show_object.set_management(output_values.get('management'))
dcmanager_subcloud_show_object.set_availability(output_values.get('availability'))
dcmanager_subcloud_show_object.set_deploy_status(output_values.get('deploy_status'))
dcmanager_subcloud_show_object.set_management_subnet(output_values.get('management_subnet'))
dcmanager_subcloud_show_object.set_management_start_ip(output_values.get('management_start_ip'))
dcmanager_subcloud_show_object.set_management_end_ip(output_values.get('management_end_ip'))
dcmanager_subcloud_show_object.set_management_gateway_ip(output_values.get('management_gateway_ip'))
dcmanager_subcloud_show_object.set_systemcontroller_gateway_ip(output_values.get('systemcontroller_gateway_ip'))
dcmanager_subcloud_show_object.set_group_id(output_values.get('group_id'))
dcmanager_subcloud_show_object.set_peer_group_id(output_values.get('peer_group_id'))
dcmanager_subcloud_show_object.set_created_at(output_values.get('created_at'))
dcmanager_subcloud_show_object.set_updated_at(output_values.get('updated_at'))
dcmanager_subcloud_show_object.set_backup_status(output_values.get('backup_status'))
dcmanager_subcloud_show_object.set_backup_datetime(output_values.get('backup_datetime'))
dcmanager_subcloud_show_object.set_prestage_status(output_values.get('prestage_status'))
dcmanager_subcloud_show_object.set_prestage_versions(output_values.get('prestage_versions'))
dcmanager_subcloud_show_object.set_dc_cert_sync_status(output_values.get('dc-cert_sync_status'))
dcmanager_subcloud_show_object.set_firmware_sync_status(output_values.get('firmware_sync_status'))
dcmanager_subcloud_show_object.set_identity_sync_status(output_values.get('identity_sync_status'))
dcmanager_subcloud_show_object.set_kubernetes_sync_status(output_values.get('kubernetes_sync_status'))
dcmanager_subcloud_show_object.set_kube_rootca_sync_status(output_values.get('kube-rootca_sync_status'))
dcmanager_subcloud_show_object.set_load_sync_status(output_values.get('load_sync_status'))
dcmanager_subcloud_show_object.set_patching_sync_status(output_values.get('patching_sync_status'))
dcmanager_subcloud_show_object.set_platform_sync_status(output_values.get('platform_sync_status'))
dcmanager_subcloud_show_object.set_usm_sync_status(output_values.get('usm_sync_status'))
dcmanager_subcloud_show_object.set_region_name(output_values.get('region_name'))
dcmanager_subcloud_show_object.set_name(output_values.get("name"))
dcmanager_subcloud_show_object.set_description(output_values.get("description"))
dcmanager_subcloud_show_object.set_location(output_values.get("location"))
dcmanager_subcloud_show_object.set_software_version(output_values.get("software_version"))
dcmanager_subcloud_show_object.set_management(output_values.get("management"))
dcmanager_subcloud_show_object.set_availability(output_values.get("availability"))
dcmanager_subcloud_show_object.set_deploy_status(output_values.get("deploy_status"))
dcmanager_subcloud_show_object.set_management_subnet(output_values.get("management_subnet"))
dcmanager_subcloud_show_object.set_management_start_ip(output_values.get("management_start_ip"))
dcmanager_subcloud_show_object.set_management_end_ip(output_values.get("management_end_ip"))
dcmanager_subcloud_show_object.set_management_gateway_ip(output_values.get("management_gateway_ip"))
dcmanager_subcloud_show_object.set_systemcontroller_gateway_ip(output_values.get("systemcontroller_gateway_ip"))
dcmanager_subcloud_show_object.set_group_id(output_values.get("group_id"))
dcmanager_subcloud_show_object.set_peer_group_id(output_values.get("peer_group_id"))
dcmanager_subcloud_show_object.set_created_at(output_values.get("created_at"))
dcmanager_subcloud_show_object.set_updated_at(output_values.get("updated_at"))
dcmanager_subcloud_show_object.set_backup_status(output_values.get("backup_status"))
dcmanager_subcloud_show_object.set_backup_datetime(output_values.get("backup_datetime"))
dcmanager_subcloud_show_object.set_prestage_status(output_values.get("prestage_status"))
dcmanager_subcloud_show_object.set_prestage_versions(output_values.get("prestage_versions"))
dcmanager_subcloud_show_object.set_dc_cert_sync_status(output_values.get("dc-cert_sync_status"))
dcmanager_subcloud_show_object.set_firmware_sync_status(output_values.get("firmware_sync_status"))
dcmanager_subcloud_show_object.set_identity_sync_status(output_values.get("identity_sync_status"))
dcmanager_subcloud_show_object.set_kubernetes_sync_status(output_values.get("kubernetes_sync_status"))
dcmanager_subcloud_show_object.set_kube_rootca_sync_status(output_values.get("kube-rootca_sync_status"))
dcmanager_subcloud_show_object.set_load_sync_status(output_values.get("load_sync_status"))
dcmanager_subcloud_show_object.set_patching_sync_status(output_values.get("patching_sync_status"))
dcmanager_subcloud_show_object.set_platform_sync_status(output_values.get("platform_sync_status"))
dcmanager_subcloud_show_object.set_usm_sync_status(output_values.get("usm_sync_status"))
dcmanager_subcloud_show_object.set_region_name(output_values.get("region_name"))
dcmanager_subcloud_show_object.set_software_sync_status(output_values.get("software_sync_status"))
self.dcmanager_subcloud_show_object = dcmanager_subcloud_show_object
def get_dcmanager_subcloud_show_object(self) -> DcManagerSubcloudShowObject:
"""
This function will return the DcManagerSubcloudObjet object representing the output of
'dcmanager subcloud show <subcloud>' command.
Args: None
Returns: DcManagerSubcloudShowObject object.
"""DcManagerSubcloudShowObject.
Returns:
DcManagerSubcloudShowObject: the DcManagerSubcloudShowObject object representing the
output of the command 'dcmanager subcloud show <subcloud>'.
"""
return self.dcmanager_subcloud_show_object

View File

@@ -8,6 +8,7 @@ from keywords.cloud_platform.dcmanager.dcmanager_prestage_strategy_keywords impo
from keywords.cloud_platform.dcmanager.dcmanager_strategy_step_keywords import DcmanagerStrategyStepKeywords
from keywords.cloud_platform.dcmanager.dcmanager_subcloud_list_keywords import DcManagerSubcloudListKeywords
from keywords.cloud_platform.dcmanager.dcmanager_subcloud_prestage import DcmanagerSubcloudPrestage
from keywords.cloud_platform.dcmanager.dcmanager_subcloud_show_keywords import DcManagerSubcloudShowKeywords
from keywords.cloud_platform.dcmanager.dcmanager_sw_deploy_strategy_keywords import DcmanagerSwDeployStrategy
from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords
from keywords.cloud_platform.swmanager.swmanager_sw_deploy_strategy_keywords import SwManagerSwDeployStrategyKeywords
@@ -76,8 +77,7 @@ def swman_sw_deploy_strategy_create_apply(release: str):
swman_deploy_kw = SwManagerSwDeployStrategyKeywords(central_ssh)
get_logger().log_test_case_step("Through the VIM orchestration deploy the patch in the system controller")
swman_strat_out = swman_deploy_kw.get_sw_deploy_strategy_create(release=release, delete=True)
swman_obj = swman_strat_out.get_swmanager_sw_deploy_strategy_show()
swman_obj = swman_deploy_kw.get_sw_deploy_strategy_create(release=release, delete=True)
get_logger().log_info(f"Created sw-deploy strategy: {swman_obj.get_strategy_uuid()} for release {swman_obj.get_release_id()}")
get_logger().log_info(f"release = {release} get_release_id = {swman_obj.get_release_id()}")
get_logger().log_test_case_step("Apply the strategy")
@@ -114,6 +114,9 @@ def dcman_sw_deploy_strategy_create_apply(subcloud_name: str, release: str):
central_ssh = LabConnectionKeywords().get_active_controller_ssh()
dcman_sw_deploy_kw = DcmanagerSwDeployStrategy(central_ssh)
# before creating the strategy, waith for subcloud software_sync_status to out-of-sync
sc_show_obj = DcManagerSubcloudShowKeywords(central_ssh).wait_for_state(subcloud_name, field="software_sync_status", expected_status="in-sync")
validate_equals(sc_show_obj.get_software_sync_status(), "out-of-sync", "Ready to create the sw-deploy strategy.")
get_logger().log_test_case_step(f"Create the sw-deploy strategy for {subcloud_name} with {release}")
dcman_sw_deploy_kw.dcmanager_sw_deploy_strategy_create(subcloud_name=subcloud_name, sw_version=release)
get_logger().log_test_case_step("Apply the strategy")