system host-addr-show keyword
Change-Id: I7f874fd6057a5ac5ec564a5a77ac239c632ac372
This commit is contained in:
parent
3ab1465d4d
commit
0cd076ff6e
@ -8,9 +8,14 @@ class SystemHostAddrObject:
|
||||
|
||||
def __init__(self):
|
||||
self.uuid: str = None
|
||||
self.interface_uuid: str = None
|
||||
self.if_name: str = None
|
||||
self.forihostid: int = -1
|
||||
self.address: str = None
|
||||
self.prefix: int = -1
|
||||
self.enable_dad: bool = None
|
||||
self.pool_uuid:str = None
|
||||
|
||||
|
||||
def set_uuid(self, uuid):
|
||||
"""
|
||||
@ -60,3 +65,50 @@ class SystemHostAddrObject:
|
||||
"""
|
||||
return self.prefix
|
||||
|
||||
def set_interface_uuid(self, interface_uuid):
|
||||
"""
|
||||
Setter for host-addr interface_uuid
|
||||
"""
|
||||
self.interface_uuid = interface_uuid
|
||||
|
||||
def get_interface_uuid(self) -> str:
|
||||
"""
|
||||
Getter for host-addr interface_uuid
|
||||
"""
|
||||
return self.interface_uuid
|
||||
|
||||
def set_forihostid(self, forihostid):
|
||||
"""
|
||||
Setter for host interface forihostid
|
||||
"""
|
||||
self.forihostid = forihostid
|
||||
|
||||
def get_forihostid(self) -> int:
|
||||
"""
|
||||
Getter for host interface forihostid
|
||||
"""
|
||||
return self.forihostid
|
||||
|
||||
def set_enable_dad(self, enable_dad):
|
||||
"""
|
||||
Setter for host-addr enable_dad
|
||||
"""
|
||||
self.enable_dad = enable_dad
|
||||
|
||||
def get_enable_dad(self) -> bool:
|
||||
"""
|
||||
Getter for host-addr enable_dad
|
||||
"""
|
||||
return self.enable_dad
|
||||
|
||||
def set_pool_uuid(self, pool_uuid):
|
||||
"""
|
||||
Setter for host-addr pool_uuid
|
||||
"""
|
||||
self.pool_uuid = pool_uuid
|
||||
|
||||
def get_pool_uuid(self) -> str:
|
||||
"""
|
||||
Getter for host-addr pool_uuid
|
||||
"""
|
||||
return self.pool_uuid
|
@ -0,0 +1,68 @@
|
||||
from framework.exceptions.keyword_exception import KeywordException
|
||||
from framework.logging.automation_logger import get_logger
|
||||
from keywords.cloud_platform.system.host.objects.system_host_addr_object import SystemHostAddrObject
|
||||
from keywords.cloud_platform.system.system_vertical_table_parser import SystemVerticalTableParser
|
||||
|
||||
class SystemHostAddrShowOutput:
|
||||
"""
|
||||
This class parses the output of 'system host-addr-show' command into an object of type SystemHostAddrObject.
|
||||
"""
|
||||
|
||||
def __init__(self, system_output):
|
||||
"""
|
||||
Constructor
|
||||
|
||||
Args:
|
||||
system_output (str): Output of the 'system host-addr-list' 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_host_addr_object = SystemHostAddrObject()
|
||||
self.system_host_addr_object.set_uuid(output_values['uuid'])
|
||||
self.system_host_addr_object.set_interface_uuid(output_values['interface_uuid'])
|
||||
self.system_host_addr_object.set_if_name(output_values['ifname'])
|
||||
self.system_host_addr_object.set_forihostid(output_values['forihostid'])
|
||||
self.system_host_addr_object.set_address(output_values['address'])
|
||||
self.system_host_addr_object.set_prefix(output_values['prefix'])
|
||||
self.system_host_addr_object.set_enable_dad(output_values['enable_dad'])
|
||||
self.system_host_addr_object.set_pool_uuid(output_values['pool_uuid'])
|
||||
else:
|
||||
raise KeywordException(f"The output line {output_values} was not valid")
|
||||
|
||||
def get_system_host_addr_show(self):
|
||||
"""
|
||||
Returns the parsed system host-addr object.
|
||||
|
||||
Returns:
|
||||
SystemHostAddrObject: The parsed system host-addr object.
|
||||
"""
|
||||
|
||||
return self.system_host_addr_object
|
||||
|
||||
@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", "interface_uuid", "ifname", "forihostid", "address", "prefix",
|
||||
"enable_dad", "pool_uuid"]
|
||||
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
|
@ -1,6 +1,7 @@
|
||||
from keywords.base_keyword import BaseKeyword
|
||||
from keywords.cloud_platform.command_wrappers import source_openrc
|
||||
from keywords.cloud_platform.system.host.objects.system_host_addr_output import SystemHostAddrOutput
|
||||
from keywords.cloud_platform.system.host.objects.system_host_addr_show_output import SystemHostAddrShowOutput
|
||||
|
||||
class SystemHostAddrKeywords(BaseKeyword):
|
||||
"""
|
||||
@ -31,4 +32,20 @@ class SystemHostAddrKeywords(BaseKeyword):
|
||||
system_host_addr_output = SystemHostAddrOutput(output)
|
||||
return system_host_addr_output
|
||||
|
||||
def get_system_host_addr_show(self, uuid) -> SystemHostAddrShowOutput:
|
||||
"""
|
||||
Gets the system host-addr-show
|
||||
|
||||
Args:
|
||||
uuid: uuid of the host addr
|
||||
Returns:
|
||||
SystemHostAddrShowOutput object.
|
||||
|
||||
"""
|
||||
command = source_openrc(f'system host-addr-show {uuid}')
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
system_host_addr_output = SystemHostAddrShowOutput(output)
|
||||
return system_host_addr_output
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user