Merge "system ptp-interface and ptp-instance-apply keywords"
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
class SystemPTPInterfaceListObject:
|
||||
"""
|
||||
Represents a SystemPTPInterfaceListObject with associated attributes.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes a SystemPTPInterfaceListObject instance.
|
||||
"""
|
||||
self.uuid = None
|
||||
self.name = None
|
||||
self.ptp_instance_name = None
|
||||
self.parameters = []
|
||||
|
||||
|
||||
def set_uuid(self, uuid: str):
|
||||
"""
|
||||
Setter for this ptp-interface-list uuid
|
||||
"""
|
||||
self.uuid = uuid
|
||||
|
||||
def get_uuid(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface-list uuid
|
||||
"""
|
||||
return self.uuid
|
||||
|
||||
def set_name(self, name: str):
|
||||
"""
|
||||
Setter for this ptp-interface-list name
|
||||
"""
|
||||
self.name = name
|
||||
|
||||
def get_name(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface-list name
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def set_ptp_instance_name(self, ptp_instance_name: str):
|
||||
"""
|
||||
Setter for this ptp-interface-list ptp_instance_name
|
||||
"""
|
||||
self.ptp_instance_name = ptp_instance_name
|
||||
|
||||
def get_ptp_instance_name(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface-list ptp_instance_name
|
||||
"""
|
||||
return self.ptp_instance_name
|
||||
|
||||
def set_parameters(self, parameters: list):
|
||||
"""
|
||||
Setter for this ptp-interface-list parameters
|
||||
"""
|
||||
self.parameters = parameters
|
||||
|
||||
def get_parameters(self) -> list[str]:
|
||||
"""
|
||||
Getter for this ptp-interface-list parameters
|
||||
"""
|
||||
return self.parameters
|
||||
|
||||
|
@@ -0,0 +1,43 @@
|
||||
from keywords.cloud_platform.system.ptp.objects.system_ptp_interface_list_object import SystemPTPInterfaceListObject
|
||||
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
|
||||
from keywords.python.type_converter import TypeConverter
|
||||
|
||||
|
||||
class SystemPTPInterfaceListOutput:
|
||||
"""
|
||||
This class parses the output of ptp-interface-list command into an object of type SystemPTPInterfaceListObject.
|
||||
"""
|
||||
|
||||
def __init__(self, system_ptp_interface_list_output):
|
||||
"""
|
||||
Constructor
|
||||
|
||||
Args:
|
||||
system_ptp_interface_list_output (str): Output of the system ptp-interface-list command.
|
||||
"""
|
||||
self.system_ptp_interface_list_output: list[SystemPTPInterfaceListObject] = []
|
||||
system_table_parser = SystemTableParser(system_ptp_interface_list_output)
|
||||
output_values = system_table_parser.get_output_values_list()
|
||||
|
||||
for value in output_values:
|
||||
system_ptp_interface_list_object = SystemPTPInterfaceListObject()
|
||||
if 'uuid' in value:
|
||||
system_ptp_interface_list_object.set_uuid(value['uuid'])
|
||||
|
||||
if 'name' in value:
|
||||
system_ptp_interface_list_object.set_name(value['name'])
|
||||
|
||||
if 'ptp_instance_name' in value:
|
||||
system_ptp_interface_list_object.set_ptp_instance_name(value['ptp_instance_name'])
|
||||
|
||||
if 'parameters' in value:
|
||||
system_ptp_interface_list_object.set_parameters(TypeConverter.parse_string_to_list(value['parameters']))
|
||||
self.system_ptp_interface_list_output.append(system_ptp_interface_list_object)
|
||||
|
||||
def get_ptp_interface_list(self) -> SystemPTPInterfaceListObject:
|
||||
"""
|
||||
Returns the parsed system ptp-interface-list
|
||||
|
||||
Returns:
|
||||
"""
|
||||
return self.system_ptp_interface_list_output
|
@@ -0,0 +1,77 @@
|
||||
class SystemPTPInterfaceObject:
|
||||
"""
|
||||
Represents a SystemPTPInterfaceObject with associated attributes.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes a SystemPTPInterfaceObject instance.
|
||||
"""
|
||||
self.uuid = None
|
||||
self.name = None
|
||||
self.interface_names = []
|
||||
self.ptp_instance_name = None
|
||||
self.parameters = []
|
||||
|
||||
|
||||
def set_uuid(self, uuid: str):
|
||||
"""
|
||||
Setter for this ptp-interface uuid
|
||||
"""
|
||||
self.uuid = uuid
|
||||
|
||||
def get_uuid(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface uuid
|
||||
"""
|
||||
return self.uuid
|
||||
|
||||
def set_name(self, name: str):
|
||||
"""
|
||||
Setter for this ptp-interface name
|
||||
"""
|
||||
self.name = name
|
||||
|
||||
def get_name(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface name
|
||||
"""
|
||||
return self.name
|
||||
|
||||
def set_interface_names(self, interface_names: list):
|
||||
"""
|
||||
Setter for this ptp-interface interface_names
|
||||
"""
|
||||
self.interface_names = interface_names
|
||||
|
||||
def get_interface_names(self) -> list[str]:
|
||||
"""
|
||||
Getter for this ptp-interface interface_names
|
||||
"""
|
||||
return self.interface_names
|
||||
|
||||
def set_ptp_instance_name(self, ptp_instance_name: str):
|
||||
"""
|
||||
Setter for this ptp-interface ptp_instance_name
|
||||
"""
|
||||
self.ptp_instance_name = ptp_instance_name
|
||||
|
||||
def get_ptp_instance_name(self) -> str:
|
||||
"""
|
||||
Getter for this ptp-interface ptp_instance_name
|
||||
"""
|
||||
return self.ptp_instance_name
|
||||
|
||||
def set_parameters(self, parameters: list):
|
||||
"""
|
||||
Setter for this ptp-interface parameters
|
||||
"""
|
||||
self.parameters = parameters
|
||||
|
||||
def get_parameters(self) -> list[str]:
|
||||
"""
|
||||
Getter for this ptp-interface parameters
|
||||
"""
|
||||
return self.parameters
|
||||
|
||||
|
@@ -0,0 +1,47 @@
|
||||
from framework.exceptions.keyword_exception import KeywordException
|
||||
from keywords.cloud_platform.system.ptp.objects.system_ptp_interface_object import SystemPTPInterfaceObject
|
||||
from keywords.cloud_platform.system.system_vertical_table_parser import SystemVerticalTableParser
|
||||
from keywords.python.type_converter import TypeConverter
|
||||
|
||||
|
||||
class SystemPTPInterfaceOutput:
|
||||
"""
|
||||
This class parses the output of ptp-interface command into an object of type SystemPTPInterfaceObject.
|
||||
"""
|
||||
|
||||
def __init__(self, system_ptp_interface_output):
|
||||
"""
|
||||
Constructor
|
||||
|
||||
Args:
|
||||
system_ptp_interface_output (str): Output of the system ptp-interface command.
|
||||
"""
|
||||
|
||||
system_vertical_table_parser = SystemVerticalTableParser(system_ptp_interface_output)
|
||||
output_values = system_vertical_table_parser.get_output_values_dict()
|
||||
|
||||
self.system_ptp_interface_object = SystemPTPInterfaceObject()
|
||||
|
||||
if 'uuid' not in output_values:
|
||||
raise KeywordException(f"The output line {output_values} was not valid because it is missing an 'uuid'.")
|
||||
self.system_ptp_interface_object.set_uuid(output_values['uuid'])
|
||||
|
||||
if 'name' in output_values:
|
||||
self.system_ptp_interface_object.set_name(output_values['name'])
|
||||
|
||||
if 'interface_names' in output_values:
|
||||
self.system_ptp_interface_object.set_interface_names(TypeConverter.parse_string_to_list(output_values['interface_names']))
|
||||
|
||||
if 'ptp_instance_name' in output_values:
|
||||
self.system_ptp_interface_object.set_ptp_instance_name(output_values['ptp_instance_name'])
|
||||
|
||||
if 'parameters' in output_values:
|
||||
self.system_ptp_interface_object.set_parameters(TypeConverter.parse_string_to_list(output_values['parameters']))
|
||||
|
||||
def get_ptp_interface(self) -> SystemPTPInterfaceObject:
|
||||
"""
|
||||
Returns the parsed system ptp-interface
|
||||
|
||||
Returns:
|
||||
"""
|
||||
return self.system_ptp_interface_object
|
@@ -53,7 +53,11 @@ class SystemPTPInstanceKeywords(BaseKeyword):
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
|
||||
return output
|
||||
# output is a List of 1 string. "['Deleted PTP instance: xxxx-xxxx-xxx\n']"
|
||||
if output and len(output) > 0:
|
||||
return output[0].strip()
|
||||
else:
|
||||
raise "Output is expected to be a List with one element."
|
||||
|
||||
def get_system_ptp_instance_show(self,name: str) -> SystemPTPInstanceOutput :
|
||||
"""
|
||||
@@ -70,7 +74,7 @@ class SystemPTPInstanceKeywords(BaseKeyword):
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
system_ptp_instance_show_output = SystemPTPInstanceOutput(output)
|
||||
|
||||
return system_ptp_instance_show_output[0].strip('\n')
|
||||
return system_ptp_instance_show_output
|
||||
|
||||
def get_system_ptp_instance_list(self) -> SystemPTPInstanceListOutput :
|
||||
"""
|
||||
@@ -84,3 +88,19 @@ class SystemPTPInstanceKeywords(BaseKeyword):
|
||||
system_ptp_instance_list_output = SystemPTPInstanceListOutput(output)
|
||||
|
||||
return system_ptp_instance_list_output
|
||||
|
||||
def system_ptp_instance_apply(self) -> str :
|
||||
"""
|
||||
Apply the PTP Instance config
|
||||
|
||||
Returns:
|
||||
"""
|
||||
command = source_openrc("system ptp-instance-apply")
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
|
||||
# output is a List of 1 string. "['Applying the PTP Instance configuration\n']"
|
||||
if output and len(output) > 0:
|
||||
return output[0].strip()
|
||||
else:
|
||||
raise "Output is expected to be a List with one element."
|
@@ -0,0 +1,90 @@
|
||||
from keywords.base_keyword import BaseKeyword
|
||||
from keywords.cloud_platform.command_wrappers import source_openrc
|
||||
from starlingx.keywords.cloud_platform.system.ptp.objects.system_ptp_interface_output import SystemPTPInterfaceOutput
|
||||
from keywords.cloud_platform.system.ptp.objects.system_ptp_interface_list_output import SystemPTPInterfaceListOutput
|
||||
|
||||
class SystemPTPInterfaceKeywords(BaseKeyword):
|
||||
"""
|
||||
Provides methods to interact with the system ptp-interface
|
||||
using given SSH connection.
|
||||
|
||||
Attributes:
|
||||
ssh_connection: An interface of an SSH connection.
|
||||
"""
|
||||
|
||||
def __init__(self, ssh_connection):
|
||||
"""
|
||||
Initializes the SystemPTPInterfaceKeywords with an SSH connection.
|
||||
|
||||
Args:
|
||||
ssh_connection: An interface of an SSH connection.
|
||||
"""
|
||||
self.ssh_connection = ssh_connection
|
||||
|
||||
def system_ptp_interface_add(self,name: str, ptp_instance_name: str) -> SystemPTPInterfaceOutput :
|
||||
"""
|
||||
Add a PTP interface
|
||||
|
||||
Args:
|
||||
name : name of interface
|
||||
ptp_instance_name: ptp instance name
|
||||
|
||||
Returns:
|
||||
"""
|
||||
cmd = f"system ptp-interface-add {name} {ptp_instance_name}"
|
||||
command = source_openrc(cmd)
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
system_ptp_interface_add_output = SystemPTPInterfaceOutput(output)
|
||||
|
||||
return system_ptp_interface_add_output
|
||||
|
||||
def system_ptp_interface_delete(self,name: str) -> str :
|
||||
"""
|
||||
Delete an interface
|
||||
|
||||
Args:
|
||||
name : name or UUID of interface
|
||||
|
||||
Returns:
|
||||
"""
|
||||
cmd = f"system ptp-interface-delete {name}"
|
||||
command = source_openrc(cmd)
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
|
||||
# output is a List of 1 string. "['Deleted PTP interface: xxxx-xxxx-xxx\n']"
|
||||
if output and len(output) > 0:
|
||||
return output[0].strip()
|
||||
else:
|
||||
raise "Output is expected to be a List with one element."
|
||||
|
||||
def get_system_ptp_interface_show(self,name: str) -> SystemPTPInterfaceOutput :
|
||||
"""
|
||||
Show PTP interface attributes.
|
||||
|
||||
Args:
|
||||
name : name or UUID of interface
|
||||
|
||||
Returns:
|
||||
"""
|
||||
cmd = f"system ptp-interface-show {name}"
|
||||
command = source_openrc(cmd)
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
system_ptp_interface_show_output = SystemPTPInterfaceOutput(output)
|
||||
|
||||
return system_ptp_interface_show_output
|
||||
|
||||
def get_system_ptp_interface_list(self) -> SystemPTPInterfaceListOutput :
|
||||
"""
|
||||
List all PTP interfaces
|
||||
|
||||
Returns:
|
||||
"""
|
||||
command = source_openrc("system ptp-interface-list")
|
||||
output = self.ssh_connection.send(command)
|
||||
self.validate_success_return_code(self.ssh_connection)
|
||||
system_ptp_interface_list_output = SystemPTPInterfaceListOutput(output)
|
||||
|
||||
return system_ptp_interface_list_output
|
Reference in New Issue
Block a user