Adjusting PTPSetupTemplate for new Config format.

Change-Id: Icf80fc3498fd45e70a267e81a5d89223ec333be5
Signed-off-by: croy <Christian.Roy@windriver.com>
This commit is contained in:
croy
2025-03-19 16:41:28 -04:00
parent 61c53d98dc
commit 04c370cd7c
8 changed files with 188 additions and 16 deletions

View File

@@ -19,7 +19,7 @@ class PTPNic:
nic_dict (Dict[str, str]): The dictionary read from the JSON config file associated with this NIC.
"""
self.name = nic_name
self.name: str = nic_name
self.gpio_switch_port = None
self.pci_slot = None
self.base_port = None
@@ -31,9 +31,6 @@ class PTPNic:
self.conn_to_spirent = None
self.spirent_port = None
# Store the raw dictionary for JINJA templating.
self.nic_dictionary = nic_dict
if "gpio_switch_port" in nic_dict and nic_dict["gpio_switch_port"]:
self.gpio_switch_port = nic_dict["gpio_switch_port"]
@@ -71,7 +68,40 @@ class PTPNic:
Dict[str, str]: Dictionary representation
"""
return self.nic_dictionary
sma1_dict = None
if self.sma1:
sma1_dict = self.sma1.to_dictionary()
sma2_dict = None
if self.sma2:
sma2_dict = self.sma2.to_dictionary()
ufl1_dict = None
if self.ufl1:
ufl1_dict = self.ufl1.to_dictionary()
ufl2_dict = None
if self.ufl2:
ufl2_dict = self.ufl2.to_dictionary()
nic_connection_dict = None
if self.nic_connection:
nic_connection_dict = self.nic_connection.to_dictionary()
ptp_nic_dictionary = {
"name": self.name,
"gpio_switch_port": self.gpio_switch_port,
"pci_slot": self.pci_slot,
"base_port": self.base_port,
"sma1": sma1_dict,
"sma2": sma2_dict,
"ufl1": ufl1_dict,
"ufl2": ufl2_dict,
"nic_connection": nic_connection_dict,
"conn_to_spirent": self.conn_to_spirent,
"spirent_port": self.spirent_port,
}
return ptp_nic_dictionary
def get_name(self) -> str:
"""

View File

@@ -31,6 +31,24 @@ class PTPNicConnection:
"""
return f"{self.from_nic} to {self.to_host}:{self.to_nic}"
def to_dictionary(self) -> Dict[str, str]:
"""
This function will return a dictionary view of the PTPNicConnection.
This is mostly used for substitution in JINJA templates.
Returns:
Dict[str, str]: Dictionary representation
"""
dictionary = {
"from_nic": self.from_nic,
"to_host": self.to_host,
"to_nic": self.to_nic,
"interface": self.interface,
}
return dictionary
def validate_nic_connection_dict(self, nic_connection_dict: Dict[str, str]) -> None:
"""
Checks if the nic_connection_dict contains all the necessary fields.

View File

@@ -58,6 +58,25 @@ class SMAConnector:
"""
return self.name
def to_dictionary(self) -> Dict[str, str]:
"""
This function will return a dictionary view of the SMA Connector.
This is mostly used for substitution in JINJA templates.
Returns:
Dict[str, str]: Dictionary representation
"""
dictionary = {
"name": self.name,
"input_nic": self.input_nic,
"input_sma": self.input_sma,
"output_nic": self.output_nic,
"output_sma": self.output_sma,
}
return dictionary
def get_name(self) -> str:
"""
Retrieves the name from the SMA connector.

View File

@@ -58,6 +58,25 @@ class UFLConnector:
"""
return self.name
def to_dictionary(self) -> Dict[str, str]:
"""
This function will return a dictionary view of the UFL Connector.
This is mostly used for substitution in JINJA templates.
Returns:
Dict[str, str]: Dictionary representation
"""
dictionary = {
"name": self.name,
"input_nic": self.input_nic,
"input_ufl": self.input_ufl,
"output_nic": self.output_nic,
"output_ufl": self.output_ufl,
}
return dictionary
def get_name(self) -> str:
"""
Retrieves the name from the SMA connector.

View File

@@ -39,7 +39,7 @@ class PTP4LSetup:
ptp_interfaces.append(ptp_host_ifs_dict[ptp_interface_name])
self.ptp_interfaces = ptp_interfaces
def __str__(self):
def __str__(self) -> str:
"""
String representation of this object.
@@ -84,3 +84,18 @@ class PTP4LSetup:
List[PTPHostInterfaceSetup]: The list of PTP interfaces.
"""
return self.ptp_interfaces
def get_ptp_interface(self, interface_name: str) -> PTPHostInterfaceSetup:
"""
Gets the PTP interface with the name specified
Args:
interface_name (str): Name of the interface that we are looking for
Returns:
PTPHostInterfaceSetup: the matching setup
"""
for ptp_interface in self.ptp_interfaces:
if ptp_interface.get_name() == interface_name:
return ptp_interface
raise Exception(f"There is no ptp interface named {interface_name} in the ptp4l setup.")

View File

@@ -63,7 +63,7 @@ class PTPSetup:
clock_setup = ClockSetup(clock_entry_dict, self.host_ptp_if_dict)
self.clock_setup_list.append(clock_setup)
def __str__(self):
def __str__(self) -> str:
"""
String representation of this object.
@@ -82,6 +82,21 @@ class PTPSetup:
"""
return self.ptp4l_setup_list
def get_ptp4l_setup(self, setup_name: str) -> PTP4LSetup:
"""
Getter for the PTP4LSetup with the specified name.
Args:
setup_name (str): Name of the specified setup.
Returns:
PTP4LSetup: The setup matching that name.
"""
for setup in self.ptp4l_setup_list:
if setup.get_name() == setup_name:
return setup
raise Exception(f"There is no ptp4l setup named {setup_name}")
def get_phc2sys_setup_list(self) -> List[PHC2SysSetup]:
"""
Getter for the list of phc2sys setups.
@@ -91,6 +106,21 @@ class PTPSetup:
"""
return self.phc2sys_setup_list
def get_phc2sys_setup(self, setup_name: str) -> PHC2SysSetup:
"""
Getter for the PHC2SysSetup with the specified name.
Args:
setup_name (str): Name of the specified setup.
Returns:
PHC2SysSetup: The setup matching that name.
"""
for setup in self.phc2sys_setup_list:
if setup.get_name() == setup_name:
return setup
raise Exception(f"There is no phc2sys setup named {setup_name}")
def get_ts2phc_setup_list(self) -> List[TS2PHCSetup]:
"""
Getter for the list of ts2phc setups.
@@ -100,6 +130,21 @@ class PTPSetup:
"""
return self.ts2phc_setup_list
def get_ts2phc_setup(self, setup_name: str) -> TS2PHCSetup:
"""
Getter for the TS2PHCSetup with the specified name.
Args:
setup_name (str): Name of the specified setup.
Returns:
TS2PHCSetup: The setup matching that name.
"""
for setup in self.ts2phc_setup_list:
if setup.get_name() == setup_name:
return setup
raise Exception(f"There is no ts2phc setup named {setup_name}")
def get_clock_setup_list(self) -> List[ClockSetup]:
"""
Getter for the list of clock setups.
@@ -108,3 +153,18 @@ class PTPSetup:
List[ClockSetup]: list of clock setups
"""
return self.clock_setup_list
def get_clock_setup(self, setup_name: str) -> ClockSetup:
"""
Getter for the ClockSetup with the specified name.
Args:
setup_name (str): Name of the specified setup.
Returns:
ClockSetup: The setup matching that name.
"""
for setup in self.clock_setup_list:
if setup.get_name() == setup_name:
return setup
raise Exception(f"There is no clock setup named {setup_name}")

View File

@@ -118,8 +118,8 @@
{
name: "ptp1if1",
controller_0_interfaces: ["{{ controller_0.nic1.conn_to_ctrl1_nic1 }}"],
controller_1_interfaces: ["{{ controller_1.nic1.conn_to_ctrl0_nic1 }}"],
controller_0_interfaces: ["{{ controller_0.nic1.nic_connection.interface }}"], // Connection to controller1-nic1
controller_1_interfaces: ["{{ controller_1.nic1.nic_connection.interface }}"], // Connection to controller0-nic1
ptp_interface_parameter : "",
},
@@ -146,7 +146,7 @@
{
name: "ptp3if1",
controller_0_interfaces: ["{{ controller_0.nic2.conn_to_ctrl1_nic2 }}"],
controller_0_interfaces: ["{{ controller_0.nic2.nic_connection.interface }}"], // Connection to Controller1 Nic 2
controller_1_interfaces: [],
ptp_interface_parameter : "",
},
@@ -161,7 +161,7 @@
{
name: "ptp4if1",
controller_0_interfaces: [],
controller_1_interfaces: ["{{ controller_0.nic2.conn_to_ctrl1_nic2 }}"],
controller_1_interfaces: ["{{ controller_0.nic2.nic_connection.interface }}"], // Connection to Controller1 Nic 2
ptp_interface_parameter : "",
},
@@ -211,14 +211,14 @@
name: "clock1if1",
controller_0_interfaces: ["{{ controller_0.nic1.conn_to_spirent }}"],
controller_1_interfaces: [],
ptp_interface_parameter : "sma1={{ controller_0.nic1.sma1_to_nic2 }}",
ptp_interface_parameter : "sma1={{ controller_0.nic1.sma1.name }}",
},
{
name: "clock1if2",
controller_0_interfaces: ["{{ controller_0.nic2.base_port }}"],
controller_1_interfaces: [],
ptp_interface_parameter : "sma1={{ controller_0.nic2.sma1_to_nic1 }}",
ptp_interface_parameter : "sma1={{ controller_0.nic2.sma1.name }}",
},
],

View File

@@ -1,6 +1,4 @@
from config.configuration_file_locations_manager import (
ConfigurationFileLocationsManager,
)
from config.configuration_file_locations_manager import ConfigurationFileLocationsManager
from config.configuration_manager import ConfigurationManager
from framework.resources.resource_finder import get_stx_resource_path
from keywords.ptp.setup.ptp_setup_reader import PTPSetupKeywords
@@ -18,13 +16,26 @@ def test_generate_ptp_setup_from_template():
ptp_setup_keywords = PTPSetupKeywords()
ptp_setup = ptp_setup_keywords.generate_ptp_setup_from_template(ptp_setup_template_path)
# ptp4l Validations
ptp4l_setup_list = ptp_setup.get_ptp4l_setup_list()
assert len(ptp4l_setup_list) == 4
ptp1 = ptp_setup.get_ptp4l_setup("ptp1")
ptp1if1 = ptp1.get_ptp_interface("ptp1if1")
assert ptp1if1.get_controller_0_interfaces() == ["enp81s0f1"]
ptp1if2 = ptp1.get_ptp_interface("ptp1if2")
assert ptp1if2.get_controller_0_interfaces() == ["conn_spirent_placeholder"]
# phc2sys Validations
phc2sys_setup_list = ptp_setup.get_phc2sys_setup_list()
assert len(phc2sys_setup_list) == 4
phc1 = ptp_setup.get_phc2sys_setup("phc1")
assert phc1.get_instance_parameters() == "'cmdline_opts=-s conn_spirent_placeholder -O -37 -m'"
# ts2phc Validations
ts2phc_setup_list = ptp_setup.get_ts2phc_setup_list()
assert len(ts2phc_setup_list) == 1
# clock Validations
clock_setup_list = ptp_setup.get_clock_setup_list()
assert len(clock_setup_list) == 1
clock1 = clock_setup_list[0]