From 718e66dd5d434ff54e1738862acbe20351cbe335 Mon Sep 17 00:00:00 2001 From: Rity Menon Date: Tue, 10 Dec 2024 12:52:36 -0800 Subject: [PATCH] system host-lvg-list keyword Change-Id: I9f681ef7254c742ec1bdc2bfdc9339f79934c880 --- .../host/objects/system_host_lvg_object.py | 114 ++++++++++++++++++ .../host/objects/system_host_lvg_output.py | 71 +++++++++++ .../system/host/system_host_lvg_keywords.py | 34 ++++++ 3 files changed, 219 insertions(+) create mode 100644 keywords/cloud_platform/system/host/objects/system_host_lvg_object.py create mode 100644 keywords/cloud_platform/system/host/objects/system_host_lvg_output.py create mode 100644 keywords/cloud_platform/system/host/system_host_lvg_keywords.py diff --git a/keywords/cloud_platform/system/host/objects/system_host_lvg_object.py b/keywords/cloud_platform/system/host/objects/system_host_lvg_object.py new file mode 100644 index 0000000..8577548 --- /dev/null +++ b/keywords/cloud_platform/system/host/objects/system_host_lvg_object.py @@ -0,0 +1,114 @@ + + +class SystemHostLvgObject: + + """ + This class represents system host-lvg as an object. + """ + + def __init__(self): + self.uuid: str = None + self.lvg_name: str = None + self.state: str = None + self.access: str = None + self.total_size: float = -1.0 + self.avail_size: float = -1.0 + self.current_pvs: int = -1 + self.current_lvs: int = -1 + + + def set_uuid(self, uuid): + """ + Setter for host-lvg uuid + """ + self.uuid = uuid + + def get_uuid(self) -> str: + """ + Getter for host-lvg UUID + """ + return self.uuid + + def set_lvg_name(self, lvg_name): + """ + Setter for the lvg_name + """ + self.lvg_name = lvg_name + + def get_lvg_name(self) -> str: + """ + Getter for the lvg_name + """ + return self.lvg_name + + def set_state(self, state): + """ + Setter for the state + """ + self.state = state + + def get_state(self) -> str: + """ + Getter for the state + """ + return self.state + + def set_access(self, access): + """ + Setter for access + """ + self.access = access + + def get_access(self) -> str: + """ + Getter for access + """ + return self.access + + def set_total_size(self, total_size): + """ + Setter for total_size + """ + self.total_size = total_size + + def get_total_size(self) -> float: + """ + Getter for total_size + """ + return self.total_size + + def set_avail_size(self, avail_size): + """ + Setter for avail_size + """ + self.avail_size = avail_size + + def get_avail_size(self) -> float: + """ + Getter for avail_size + """ + return self.avail_size + + def set_current_pvs(self, current_pvs): + """ + Setter for current_pvs + """ + self.current_pvs = current_pvs + + def get_current_pvs(self) -> int: + """ + Getter for current_pvs + """ + return self.current_pvs + + def set_current_lvs(self, current_lvs): + """ + Setter for current_lvs + """ + self.current_lvs = current_lvs + + def get_current_lvs(self) -> int: + """ + Getter for current_lvs + """ + return self.current_lvs diff --git a/keywords/cloud_platform/system/host/objects/system_host_lvg_output.py b/keywords/cloud_platform/system/host/objects/system_host_lvg_output.py new file mode 100644 index 0000000..9c003d6 --- /dev/null +++ b/keywords/cloud_platform/system/host/objects/system_host_lvg_output.py @@ -0,0 +1,71 @@ +from framework.exceptions.keyword_exception import KeywordException +from framework.logging.automation_logger import get_logger +from keywords.cloud_platform.system.host.objects.system_host_lvg_object import SystemHostLvgObject +from keywords.cloud_platform.system.system_table_parser import SystemTableParser + +class SystemHostLvgOutput: + """ + This class parses the output of 'system host-lvg-list' command into an object of type SystemHostLvgObject. + """ + + def __init__(self, system_output): + """ + Constructor + + Args: + system_output (str): Output of the 'system host-lvg-list' command. + + Raises: + KeywordException: If the output is not valid. + """ + + self.system_host_lvg : [SystemHostLvgObject] = [] + system_table_parser = SystemTableParser(system_output) + output_values = system_table_parser.get_output_values_list() + + for value in output_values: + if self.is_valid_output(value): + system_host_lvg = SystemHostLvgObject() + system_host_lvg.set_uuid(value['UUID']) + system_host_lvg.set_lvg_name(value['LVG Name']) + system_host_lvg.set_state(value['State']) + system_host_lvg.set_access(value['Access']) + system_host_lvg.set_total_size(value['Total Size (GiB)']) + system_host_lvg.set_avail_size(value['Avail Size (GiB)']) + system_host_lvg.set_current_pvs(value['Current PVs']) + system_host_lvg.set_current_lvs(value['Current LVs']) + self.system_host_lvg.append(system_host_lvg) + else: + raise KeywordException(f"The output line {value} was not valid") + + def get_system_host_lvg(self): + """ + Returns the parsed system host-lvg object. + + Returns: + SystemHostAddrObject: The parsed system host-lvg object. + """ + + return self.system_host_lvg + + @staticmethod + def is_valid_output(value): + """ + Checks if the output contains all the expected fields. + + Args: + value (dict): The dictionary of output values. + + Returns: + bool: True if the output contains all required fields, False otherwise. + """ + + required_fields = ["UUID", "LVG Name", "State", "Access", "Total Size (GiB)", "Avail Size (GiB)", + "Current PVs", "Current LVs"] + valid = True + for field in required_fields: + if field not in value: + get_logger().log_error(f'{field} is not in the output value') + valid = False + break + return valid diff --git a/keywords/cloud_platform/system/host/system_host_lvg_keywords.py b/keywords/cloud_platform/system/host/system_host_lvg_keywords.py new file mode 100644 index 0000000..a3d8f01 --- /dev/null +++ b/keywords/cloud_platform/system/host/system_host_lvg_keywords.py @@ -0,0 +1,34 @@ +from keywords.base_keyword import BaseKeyword +from keywords.cloud_platform.command_wrappers import source_openrc +from keywords.cloud_platform.system.host.objects.system_host_lvg_output import SystemHostLvgOutput + + +class SystemHostLvgKeywords(BaseKeyword): + """ + This class contains all the keywords related to the 'system host-lvg' commands. + """ + + def __init__(self, ssh_connection): + """ + Constructor + Args: + ssh_connection: + """ + self.ssh_connection = ssh_connection + + def get_system_host_lvg_list(self, host_id) -> SystemHostLvgOutput: + """ + Gets the system host-lvg-list + + Args: + host_id: name or id of the host + Returns: + SystemHostLvgOutput object with the list of host-lvg. + + """ + command = source_openrc(f'system host-lvg-list {host_id}') + output = self.ssh_connection.send(command) + self.validate_success_return_code(self.ssh_connection) + system_host_lvg_output = SystemHostLvgOutput(output) + return system_host_lvg_output +