system remotelogging keywords

Change-Id: I098b3005ef108aca1eb3d5be80a32918df02bb1d
This commit is contained in:
Rity Menon
2025-02-11 10:35:36 -08:00
parent c63c7e6ae5
commit c766a24bc0
3 changed files with 196 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
class SystemRemoteloggingObject:
"""
This class represents a service as an object.
This is typically a line in the system remotelogging output table.
"""
def __init__(self):
self.uuid:str = None
self.ip_address:str = None
self.enabled:bool = None
self.transport:str = None
self.port: int = -1
self.created_at: str = None
self.updated_at: str = None
def set_uuid(self, uuid: str):
"""
Setter for the uuid
"""
self.uuid = uuid
def get_uuid(self) -> str:
"""
Getter for the uuid
"""
return self.uuid
def set_ip_address(self, ip_address: str):
"""
Setter for the ip_address
"""
self.ip_address = ip_address
def get_ip_address(self) -> str:
"""
Getter for ip_address
"""
return self.ip_address
def set_enabled(self, enabled: bool):
"""
Setter for the enabled
"""
self.enabled = enabled
def get_enabled(self) -> bool:
"""
Getter for the enabled
"""
return self.enabled
def set_transport(self, transport: str):
"""
Setter for the transport
"""
self.transport = transport
def get_transport(self) -> str:
"""
Getter for the transport
"""
return self.transport
def set_port(self, port: int):
"""
Setter for the port
"""
self.port = port
def get_port(self) -> int:
"""
Getter for the port
"""
return self.port
def set_created_at(self, created_at: str):
"""
Setter for created_at
"""
self.created_at = created_at
def get_created_at(self) -> str:
"""
Getter for created_at
"""
return self.created_at
def set_updated_at(self, updated_at: str):
"""
Setter for updated_at
"""
self.updated_at = updated_at
def get_updated_at(self) -> str:
"""
Getter for updated_at
"""
return self.updated_at

View File

@@ -0,0 +1,66 @@
from framework.exceptions.keyword_exception import KeywordException
from framework.logging.automation_logger import get_logger
from keywords.cloud_platform.system.remotelogging.objects.system_remotelogging_object import SystemRemoteloggingObject
from keywords.cloud_platform.system.system_vertical_table_parser import SystemVerticalTableParser
class SystemRemoteloggingShowOutput:
"""
This class parses the output of 'system remotelogging-show' command into an object of type SystemRemoteloggingShowObject.
"""
def __init__(self, system_output):
"""
Constructor
Args:
system_output (str): Output of the 'system remotelogging-show' command.
Raises:
KeywordException: If the output is not valid.
"""
system_vertical_table_parser = SystemVerticalTableParser(system_output)
output_values = system_vertical_table_parser.get_output_values_dict()
if self.is_valid_output(output_values):
self.system_remotelog = SystemRemoteloggingObject()
self.system_remotelog.set_uuid(output_values['uuid'])
self.system_remotelog.set_ip_address(output_values['ip_address'])
self.system_remotelog.set_enabled(output_values['enabled'])
self.system_remotelog.set_transport(output_values['transport'])
self.system_remotelog.set_port(output_values['port'])
self.system_remotelog.set_created_at(output_values['created_at'])
self.system_remotelog.set_updated_at(output_values['updated_at'])
else:
raise KeywordException(f"The output line {output_values} was not valid")
def get_system_remotelogging_show(self) -> SystemRemoteloggingObject:
"""
Returns the parsed system remotelogging-show object.
Returns:
SystemRemoteloggingObject: The parsed system remotelogging-show object.
"""
return self.system_remotelog
@staticmethod
def is_valid_output(value) -> bool:
"""
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", "ip_address", "enabled", "transport", "port", "created_at", "updated_at"]
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

View File

@@ -0,0 +1,31 @@
from keywords.base_keyword import BaseKeyword
from keywords.cloud_platform.command_wrappers import source_openrc
from keywords.cloud_platform.system.remotelogging.objects.system_remotelogging_show_output import SystemRemoteloggingShowOutput
class SystemRemoteloggingKeywords(BaseKeyword):
"""
This class contains all the keywords related to the 'system remotelogging' commands.
"""
def __init__(self, ssh_connection):
"""
Constructor
Args:
ssh_connection:
"""
self.ssh_connection = ssh_connection
def get_system_remotelogging_show(self) -> SystemRemoteloggingShowOutput:
"""
Gets the system remotelogging-show
Returns:
SystemRemoteloggingShowOutput object.
"""
command = source_openrc('system remotelogging-show')
output = self.ssh_connection.send(command)
self.validate_success_return_code(self.ssh_connection)
system_remotelog_show_output = SystemRemoteloggingShowOutput(output)
return system_remotelog_show_output