PTP Config initial implementation

Change-Id: I138f4c7637a410234d016c2f8b9a9c8d4ec5456c
This commit is contained in:
croy
2025-02-25 16:36:48 -05:00
committed by Christian Roy
parent 0d87c270d9
commit 4c1729d066
8 changed files with 648 additions and 135 deletions

View File

@@ -1,69 +1,77 @@
from optparse import OptionParser
from _pytest.main import Session
class ConfigurationFileLocationsManager:
"""
Class to hold all the file locations for different configs
Class to hold all the file locations for different configs.
"""
def __init__(self):
self.lab_config_file = None
self.k8s_config_file = None
self.ptp_config_file = None
self.logger_config_file = None
self.docker_config_file = None
self.web_config_file = None
self.database_config_file = None
self.rest_api_config_file = None
def set_configs_from_pytest_args(self, session):
def set_configs_from_pytest_args(self, session: Session):
"""
Sets the configs from pytest args
Sets the configs from pytest args.
Args:
session (): the pytest session
session (Session): the pytest session
Returns:
Returns: None
"""
lab_config_file = session.config.getoption('--lab_config_file')
lab_config_file = session.config.getoption("--lab_config_file")
if lab_config_file:
self.set_lab_config_file(lab_config_file)
k8s_config_file = session.config.getoption('--k8s_config_file')
k8s_config_file = session.config.getoption("--k8s_config_file")
if k8s_config_file:
self.set_k8s_config_file(k8s_config_file)
logger_config_file = session.config.getoption('--logger_config_file')
ptp_config_file = session.config.getoption("--ptp_config_file")
if ptp_config_file:
self.set_ptp_config_file(ptp_config_file)
logger_config_file = session.config.getoption("--logger_config_file")
if logger_config_file:
self.set_logger_config_file(logger_config_file)
docker_config_file = session.config.getoption('--docker_config_file')
docker_config_file = session.config.getoption("--docker_config_file")
if docker_config_file:
self.set_docker_config_file(docker_config_file)
web_config_file = session.config.getoption('--web_config_file')
web_config_file = session.config.getoption("--web_config_file")
if web_config_file:
self.set_web_config_file(web_config_file)
database_config_file = session.config.getoption('--database_config_file')
database_config_file = session.config.getoption("--database_config_file")
if database_config_file:
self.set_database_config_file(database_config_file)
rest_api_config_file = session.config.getoption('--rest_api_config_file')
rest_api_config_file = session.config.getoption("--rest_api_config_file")
if rest_api_config_file:
self.set_rest_api_config_file(rest_api_config_file)
def set_configs_from_options_parser(self, parser: OptionParser = None):
"""
Sets the config files from options parser
Sets the config files from options parser.
Args:
parser - (optional) this is needed for the case where we have other command line options besides just config,
parser (OptionParser): This is needed for the case where we have other command line options besides just config,
in these cases the parser will need to be instantiated and the other options added before passing to
config location manager.
Returns:
Returns: None
"""
options = self._add_options(parser)
lab_config_file = options.lab_config_file
@@ -74,6 +82,10 @@ class ConfigurationFileLocationsManager:
if k8s_config_file:
self.set_k8s_config_file(k8s_config_file)
ptp_config_file = options.ptp_config_file
if ptp_config_file:
self.set_ptp_config_file(ptp_config_file)
logger_config_file = options.logger_config_file
if logger_config_file:
self.set_logger_config_file(logger_config_file)
@@ -96,144 +108,182 @@ class ConfigurationFileLocationsManager:
def _add_options(self, parser: OptionParser):
"""
Adds the command line options we can expect
Returns:
Adds the command line options we can expect.
Returns: None
"""
if not parser:
parser = OptionParser()
parser.add_option(
'--lab_config_file',
action='store',
type='str',
dest='lab_config_file',
help='the lab file used for scanning',
"--lab_config_file",
action="store",
type="str",
dest="lab_config_file",
help="the lab file used for scanning",
)
parser.add_option(
'--k8s_config_file',
action='store',
type='str',
dest='k8s_config_file',
help='the k8s config file',
"--k8s_config_file",
action="store",
type="str",
dest="k8s_config_file",
help="the k8s config file",
)
parser.add_option(
'--logger_config_file',
action='store',
type='str',
dest='logger_config_file',
help='the logger config file',
"--ptp_config_file",
action="store",
type="str",
dest="ptp_config_file",
help="the PTP config file",
)
parser.add_option(
'--docker_config_file',
action='store',
type='str',
dest='docker_config_file',
help='the docker config file',
"--logger_config_file",
action="store",
type="str",
dest="logger_config_file",
help="the logger config file",
)
parser.add_option(
'--web_config_file',
action='store',
type='str',
dest='web_config_file',
help='The Web config file',
"--docker_config_file",
action="store",
type="str",
dest="docker_config_file",
help="the docker config file",
)
parser.add_option(
'--database_config_file',
action='store',
type='str',
dest='database_config_file',
help='The database config file',
"--web_config_file",
action="store",
type="str",
dest="web_config_file",
help="The Web config file",
)
parser.add_option(
'--rest_api_config_file',
action='store',
type='str',
dest='rest_api_config_file',
help='The rest api config file',
"--database_config_file",
action="store",
type="str",
dest="database_config_file",
help="The database config file",
)
parser.add_option(
"--rest_api_config_file",
action="store",
type="str",
dest="rest_api_config_file",
help="The rest api config file",
)
options, args = parser.parse_args()
return options
def set_lab_config_file(self, lab_config_file):
def set_lab_config_file(self, lab_config_file: str):
"""
Setter for lab config files
Args:
lab_config_file (): the location of the lab config file
Setter for lab config files.
Returns:
Args:
lab_config_file (str): the location of the lab config file
Returns: None
"""
self.lab_config_file = lab_config_file
def get_lab_config_file(self) -> str:
"""
Getter for lab config file
Getter for lab config file.
Returns: the lab config file
"""
return self.lab_config_file
def set_k8s_config_file(self, k8s_config_file):
def set_k8s_config_file(self, k8s_config_file: str):
"""
Setter for k8s config file
Args:
k8s_config_file (): the location of the k8s config file
Setter for k8s config file.
Returns:
Args:
k8s_config_file (str): the location of the k8s config file
Returns: None
"""
self.k8s_config_file = k8s_config_file
def get_k8s_config_file(self) -> str:
"""
Getter for k8s config file
Getter for k8s config file.
Returns: the k8s config file
"""
return self.k8s_config_file
def set_logger_config_file(self, logger_config_file):
def set_ptp_config_file(self, ptp_config_file: str):
"""
Setter for logger config file
Args:
logger_config_file (): the logger config file
Setter for ptp config file.
Returns:
Args:
ptp_config_file (str): the location of the ptp config file
Returns: None
"""
self.ptp_config_file = ptp_config_file
def get_ptp_config_file(self) -> str:
"""
Getter for ptp config file.
Returns: the ptp config file
"""
return self.ptp_config_file
def set_logger_config_file(self, logger_config_file: str):
"""
Setter for logger config file.
Args:
logger_config_file (str): the logger config file
Returns: None
"""
self.logger_config_file = logger_config_file
def get_logger_config_file(self) -> str:
"""
Getter for logger config file
Getter for logger config file.
Returns: the logger config file
"""
return self.logger_config_file
def set_docker_config_file(self, docker_config_file):
def set_docker_config_file(self, docker_config_file: str):
"""
Setter for docker config file
Args:
docker_config_file (): the docker config file
Setter for docker config file.
Returns:
Args:
docker_config_file (str): the docker config file
Returns: None
"""
self.docker_config_file = docker_config_file
def get_docker_config_file(self) -> str:
"""
Getter for docker config file
Getter for docker config file.
Returns: the docker config file
"""
@@ -241,18 +291,20 @@ class ConfigurationFileLocationsManager:
def set_web_config_file(self, web_config_file: str):
"""
Setter for web config file
Args:
web_config_file (): the web config file
Setter for web config file.
Returns:
Args:
web_config_file (str): the web config file
Returns: None
"""
self.web_config_file = web_config_file
def get_web_config_file(self) -> str:
"""
Getter for web config file
Getter for web config file.
Returns: the web config file
"""
@@ -260,18 +312,20 @@ class ConfigurationFileLocationsManager:
def set_database_config_file(self, database_config_file: str):
"""
Setter for database config file
Args:
database_config_file (): the database config file
Setter for database config file.
Returns:
Args:
database_config_file (str): the database config file
Returns: None
"""
self.database_config_file = database_config_file
def get_database_config_file(self) -> str:
"""
Getter for database config file
Getter for database config file.
Returns: the database config file
"""
@@ -279,20 +333,21 @@ class ConfigurationFileLocationsManager:
def set_rest_api_config_file(self, rest_api_config_file: str):
"""
Setter for rest_api_config_file
Args:
rest_api_config_file (): the rest_api_config_file
Setter for rest_api_config_file.
Returns:
Args:
rest_api_config_file (str): the rest_api_config_file
Returns: None
"""
self.rest_api_config_file = rest_api_config_file
def get_rest_api_config_file(self) -> str:
"""
Getter for rest_api_config_file
Getter for rest_api_config_file.
Returns: the rest_api_config_file
"""
return self.rest_api_config_file

View File

@@ -4,6 +4,7 @@ from config.docker.objects.docker_config import DockerConfig
from config.k8s.objects.k8s_config import K8sConfig
from config.lab.objects.lab_config import LabConfig
from config.logger.objects.logger_config import LoggerConfig
from config.ptp.objects.ptp_config import PTPConfig
from config.rest_api.objects.rest_api_config import RestAPIConfig
from config.web.objects.web_config import WebConfig
from framework.resources.resource_finder import get_stx_resource_path
@@ -11,13 +12,14 @@ from framework.resources.resource_finder import get_stx_resource_path
class ConfigurationManagerClass:
"""
Singleton class for loading and storing configs
Singleton class for loading and storing configs.
"""
def __init__(self):
self.loaded = False
self.lab_config: LabConfig = None
self.k8s_config: K8sConfig = None
self.ptp_config: PTPConfig = None
self.logger_config: LoggerConfig = None
self.docker_config: DockerConfig = None
self.web_config: WebConfig = None
@@ -29,7 +31,7 @@ class ConfigurationManagerClass:
"""
This function will return true if the configurations are already loaded.
Returns:
Returns (bool):
"""
return self.loaded
@@ -37,48 +39,53 @@ class ConfigurationManagerClass:
def load_configs(self, config_file_locations: ConfigurationFileLocationsManager):
"""
This function will load all the config files.
By default, the default.json5 files in each configuration folder will get loaded.
If a config_file parameter is specified, that file will be used instead for that config.
Args:
config_file_locations: class with all the config file locations
Returns:
Args:
config_file_locations (ConfigurationFileLocationsManager): class with all the config file locations
"""
self.configuration_locations_manager = config_file_locations
lab_config_file = config_file_locations.get_lab_config_file()
if not lab_config_file:
lab_config_file = get_stx_resource_path('config/lab/files/default.json5')
lab_config_file = get_stx_resource_path("config/lab/files/default.json5")
k8s_config_file = config_file_locations.get_k8s_config_file()
if not k8s_config_file:
k8s_config_file = get_stx_resource_path('config/k8s/files/default.json5')
k8s_config_file = get_stx_resource_path("config/k8s/files/default.json5")
ptp_config_file = config_file_locations.get_ptp_config_file()
if not ptp_config_file:
ptp_config_file = get_stx_resource_path("config/ptp/files/default.json5")
logger_config_file = config_file_locations.get_logger_config_file()
if not logger_config_file:
logger_config_file = get_stx_resource_path('config/logger/files/default.json5')
logger_config_file = get_stx_resource_path("config/logger/files/default.json5")
docker_config_file = config_file_locations.get_docker_config_file()
if not docker_config_file:
docker_config_file = get_stx_resource_path('config/docker/files/default.json5')
docker_config_file = get_stx_resource_path("config/docker/files/default.json5")
web_config_file = config_file_locations.get_web_config_file()
if not web_config_file:
web_config_file = get_stx_resource_path('config/web/files/default.json5')
web_config_file = get_stx_resource_path("config/web/files/default.json5")
database_config_file = config_file_locations.get_database_config_file()
if not database_config_file:
database_config_file = get_stx_resource_path('config/database/files/default.json5')
database_config_file = get_stx_resource_path("config/database/files/default.json5")
rest_api_config_file = config_file_locations.get_rest_api_config_file()
if not rest_api_config_file:
rest_api_config_file = get_stx_resource_path('config/rest_api/files/default.json5')
rest_api_config_file = get_stx_resource_path("config/rest_api/files/default.json5")
if not self.loaded:
try:
self.lab_config = LabConfig(lab_config_file)
self.k8s_config = K8sConfig(k8s_config_file)
self.ptp_config = PTPConfig(ptp_config_file)
self.logger_config = LoggerConfig(logger_config_file)
self.docker_config = DockerConfig(docker_config_file)
self.web_config = WebConfig(web_config_file)
@@ -91,94 +98,111 @@ class ConfigurationManagerClass:
def get_lab_config(self) -> LabConfig:
"""
Getter for lab config
Returns: lab config
Getter for lab config.
Returns (LabConfig): lab config
"""
return self.lab_config
def set_lab_config(self, lab_config: LabConfig):
"""
Setter for lab config
Setter for lab config.
Args:
lab_config (LabConfig): the lab config object representing the content of the lab config file.
Returns:
"""
self.lab_config = lab_config
def get_k8s_config(self) -> K8sConfig:
"""
Getter for k8s config
Returns: k8s config
Getter for k8s config.
Returns (K8sConfig): k8s config
"""
return self.k8s_config
def get_ptp_config(self) -> PTPConfig:
"""
Getter for ptp config.
Returns (PTPConfig): ptp config
"""
return self.ptp_config
def get_logger_config(self) -> LoggerConfig:
"""
Getter for logger config
Returns: logger config
Getter for logger config.
Returns (LoggerConfig): logger config
"""
return self.logger_config
def get_docker_config(self) -> DockerConfig:
"""
Getter for docker config
Returns: the docker config
Getter for docker config.
Returns (DockerConfig): the docker config
"""
return self.docker_config
def get_web_config(self) -> WebConfig:
"""
Getter for web config
Returns: the web config
Getter for web config.
Returns (WebConfig): the web config
"""
return self.web_config
def get_database_config(self) -> DatabaseConfig:
"""
Getter for database config
Returns: the database config
Getter for database config.
Returns (DatabaseConfig): the database config
"""
return self.database_config
def get_rest_api_config(self) -> RestAPIConfig:
"""
Getter for rest api config
Returns: the rest api config
Getter for rest api config.
Returns (RestAPIConfig): the rest api config
"""
return self.rest_api_config
def get_config_pytest_args(self) -> [str]:
"""
Returns the configuration file locations as pytest args
Returns:
Returns the configuration file locations as pytest args.
Returns ([str]):
"""
pytest_config_args = []
if self.configuration_locations_manager.get_lab_config_file():
pytest_config_args.append(f'--lab_config_file={self.configuration_locations_manager.get_lab_config_file()}')
pytest_config_args.append(f"--lab_config_file={self.configuration_locations_manager.get_lab_config_file()}")
if self.configuration_locations_manager.get_k8s_config_file():
pytest_config_args.append(f'--k8s_config_file={self.configuration_locations_manager.get_k8s_config_file()}')
pytest_config_args.append(f"--k8s_config_file={self.configuration_locations_manager.get_k8s_config_file()}")
if self.configuration_locations_manager.get_ptp_config_file():
pytest_config_args.append(f"--ptp_config_file={self.configuration_locations_manager.get_ptp_config_file()}")
if self.configuration_locations_manager.logger_config_file:
pytest_config_args.append(f'--logger_config_file{self.configuration_locations_manager.get_logger_config_file()}')
pytest_config_args.append(f"--logger_config_file{self.configuration_locations_manager.get_logger_config_file()}")
if self.configuration_locations_manager.docker_config_file:
pytest_config_args.append(f'--docker_config_file={self.configuration_locations_manager.get_docker_config_file()}')
pytest_config_args.append(f"--docker_config_file={self.configuration_locations_manager.get_docker_config_file()}")
if self.configuration_locations_manager.web_config_file:
pytest_config_args.append(f'--web_config_file={self.configuration_locations_manager.get_web_config_file()}')
pytest_config_args.append(f"--web_config_file={self.configuration_locations_manager.get_web_config_file()}")
if self.configuration_locations_manager.database_config_file:
pytest_config_args.append(f'--database_config_file={self.configuration_locations_manager.get_database_config_file()}')
pytest_config_args.append(f"--database_config_file={self.configuration_locations_manager.get_database_config_file()}")
if self.configuration_locations_manager.rest_api_config_file:
pytest_config_args.append(f'--rest_api_config_file={self.configuration_locations_manager.get_rest_api_config_file()}')
pytest_config_args.append(f"--rest_api_config_file={self.configuration_locations_manager.get_rest_api_config_file()}")
return pytest_config_args

View File

@@ -0,0 +1,89 @@
{
controller_0 : {
nic1 : {
gnss_switch_port: "./gnss_switch_port_file.exp 1",
// Parameters can be : sma1 input/output, sma2 input/output, u.fl1 output, u.fl2 input, synce_rclka enabled, synce_rclkb enabled
sma1_to_nic2: "output", // CLOCK OUTPUT INTERFACE Controller-0 NIC1
sma2_to_nic2: "",
// This port for TS2PHC and PHC2SYS.
// Can be assigned to any interface of the NIC connected to GNSS and with any NIC on the same host.
// By default, we use the first port.
base_port: "enp81s0f0",
conn_to_ctr1_nic1: "enp81s0f1",
// Optional Spirent config.
conn_to_spirent: "",
spirent_port: "",
},
nic2 : {
gnss_switch_port: "",
// Parameters can be : sma1 input/output, sma2 input/output, u.fl1 output, u.fl2 input, synce_rclka enabled, synce_rclkb enabled
sma1_to_nic1: "input", // CLOCK OUTPUT INTERFACE Controller-0 NIC2
sma2_to_nic1: "",
// This port for TS2PHC and PHC2SYS.
// Can be assigned to any interface of the NIC connected to GNSS and with any NIC on the same host.
// By default, we use the first port.
base_port: "",
conn_to_ctr1_nic2: "",
// Optional Spirent config.
conn_to_spirent: "",
spirent_port: "",
}
},
controller_1 : {
nic1 : {
gnss_switch_port: "",
// Parameters can be : sma1 input/output, sma2 input/output, u.fl1 output, u.fl2 input, synce_rclka enabled, synce_rclkb enabled
sma1_to_nic2: "output", // CLOCK OUTPUT INTERFACE Controller-1 NIC1
sma2_to_nic2: "",
// This port for TS2PHC and PHC2SYS.
// Can be assigned to any interface of the NIC connected to GNSS and with any NIC on the same host.
// By default, we use the first port.
base_port: "",
conn_to_ctr0_nic1: "",
// Optional Spirent config.
conn_to_spirent: "",
spirent_port: "",
},
nic2 : {
gnss_switch_port: "",
// Parameters can be : sma1 input/output, sma2 input/output, u.fl1 output, u.fl2 input, synce_rclka enabled, synce_rclkb enabled
sma1_to_nic1: "input", // CLOCK OUTPUT INTERFACE Controller-1 NIC2
sma2_to_nic1: "",
// This port for TS2PHC and PHC2SYS.
// Can be assigned to any interface of the NIC connected to GNSS and with any NIC on the same host.
// By default, we use the first port.
base_port: "",
conn_to_ctr0_nic2: "",
// Optional Spirent config.
conn_to_spirent: "",
spirent_port: "",
},
},
}

View File

@@ -0,0 +1,60 @@
from typing import List
import json5
from config.ptp.objects.ptp_host import PTPHost
class PTPConfig:
"""
Class to hold configuration of the Cloud Platform's PTP Configuration.
"""
def __init__(self, config):
try:
json_data = open(config)
except FileNotFoundError:
print(f"Could not find the ptp config file: {config}")
raise
ptp_dict = json5.load(json_data)
self.ptp_hosts = []
for ptp_host in ptp_dict:
host = PTPHost(ptp_host, ptp_dict[ptp_host])
self.ptp_hosts.append(host)
def __str__(self):
"""
Returns the string representation for this class.
Returns: (str)
"""
return "PTPConfig"
def get_all_hosts(self) -> List[PTPHost]:
"""
Getter for the PTP information for every host defined in the config.
Returns:
List[PTPHost]: The list of all hosts.
"""
return self.ptp_hosts
def get_host(self, host_name: str) -> PTPHost:
"""
Getter for the PTP information about the specified host_name.
Args:
host_name (str): Name of the host in the config.
Returns:
PTPHost: PTPHost
"""
for host in self.ptp_hosts:
if host.get_name() == host_name:
return host
raise Exception(f"There is no PTP Host called {host_name} in the PTP config.")

View File

@@ -0,0 +1,70 @@
from typing import Dict, List
from config.ptp.objects.ptp_nic import PTPNic
class PTPHost:
"""
Class to handle PTP-specific information about Hosts and NICs associated with the lab configuration.
"""
def __init__(self, host_name: str, host_dict: Dict[str, Dict]):
"""
Constructor.
Args:
host_name (str): The name of the host associated with this PTP configuration
host_dict (Dict[str, Dict]): The dictionary read from the JSON config file associated with this Host. It contains NIC cards information.
"""
self.name = host_name
self.nics = []
for nic_name in host_dict:
nic = PTPNic(nic_name, host_dict[nic_name])
self.nics.append(nic)
def __str__(self):
"""
String representation override.
Returns (str): String representation of this object.
"""
return f"PTPHost - {self.name}"
def get_name(self) -> str:
"""
Getter for the name of this ptp_host.
Returns (str): The name of this ptp_host
"""
return self.name
def get_all_nics(self) -> List[PTPNic]:
"""
Getter for the NIC information associated with this host.
Returns
List[PTPNic]: All the nics
"""
return self.nics
def get_nic(self, nic_name: str) -> PTPNic:
"""
Getter for the information about the specified NIC.
Args:
nic_name (str): Name of the NIC in the config
Returns:
PTPNic: The NIC object with the specified name.
"""
for nic in self.nics:
if nic.get_name() == nic_name:
return nic
raise Exception(
f"There is no PTP NIC called {nic_name} associated with the host {self.name} in the PTP config."
)

View File

@@ -0,0 +1,194 @@
from typing import Dict
class PTPNic:
"""
Class to handle PTP NIC associated with the lab configuration.
"""
def __init__(self, nic_name: str, nic_dict: Dict[str, str]):
"""
Constructor.
Args:
nic_name (str): The name associated with this nic.
nic_dict (Dict[str, str]): The dictionary read from the JSON config file associated with this NIC.
"""
self.name = nic_name
self.gnss_switch_port = None
self.sma1_to_nic1 = None
self.sma2_to_nic1 = None
self.sma1_to_nic2 = None
self.sma2_to_nic2 = None
self.base_port = None
self.conn_to_ctrl0_nic1 = None
self.conn_to_ctrl0_nic2 = None
self.conn_to_ctrl1_nic1 = None
self.conn_to_ctrl1_nic2 = None
self.conn_to_spirent = None
self.spirent_port = None
if "gnss_switch_port" in nic_dict and nic_dict["gnss_switch_port"]:
self.gnss_switch_port = nic_dict["gnss_switch_port"]
if "sma1_to_nic1" in nic_dict and nic_dict["sma1_to_nic1"]:
self.sma1_to_nic1 = nic_dict["sma1_to_nic1"]
if "sma2_to_nic1" in nic_dict and nic_dict["sma2_to_nic1"]:
self.sma2_to_nic1 = nic_dict["sma2_to_nic1"]
if "sma1_to_nic2" in nic_dict and nic_dict["sma1_to_nic2"]:
self.sma1_to_nic2 = nic_dict["sma1_to_nic2"]
if "sma2_to_nic2" in nic_dict and nic_dict["sma2_to_nic2"]:
self.sma2_to_nic2 = nic_dict["sma2_to_nic2"]
if "base_port" in nic_dict and nic_dict["base_port"]:
self.base_port = nic_dict["base_port"]
if "conn_to_ctrl0_nic1" in nic_dict and nic_dict["conn_to_ctrl0_nic1"]:
self.conn_to_ctrl0_nic1 = nic_dict["conn_to_ctrl0_nic1"]
if "conn_to_ctrl0_nic2" in nic_dict and nic_dict["conn_to_ctrl0_nic2"]:
self.conn_to_ctrl0_nic2 = nic_dict["conn_to_ctrl0_nic2"]
if "conn_to_ctrl1_nic1" in nic_dict and nic_dict["conn_to_ctrl1_nic1"]:
self.conn_to_ctrl1_nic1 = nic_dict["conn_to_ctrl1_nic1"]
if "conn_to_ctrl1_nic2" in nic_dict and nic_dict["conn_to_ctrl1_nic2"]:
self.conn_to_ctrl1_nic2 = nic_dict["conn_to_ctrl1_nic2"]
if "conn_to_spirent" in nic_dict and nic_dict["conn_to_spirent"]:
self.conn_to_spirent = nic_dict["conn_to_spirent"]
if "spirent_port" in nic_dict and nic_dict["spirent_port"]:
self.spirent_port = nic_dict["spirent_port"]
def __str__(self):
"""
String representation of this object.
Returns (str): String representation of this object.
"""
return f"PTPNic - {self.name}"
def get_name(self) -> str:
"""
Gets the Name of this PTP NIC.
Returns (str):
The name of the NIC
"""
return self.name
def get_gnss_switch_port(self) -> str:
"""
Gets the GNSS switch port.
Returns (str):
The GNSS switch port.
"""
return self.gnss_switch_port
def get_sma1_to_nic1(self) -> str:
"""
Gets the SMA1 to NIC1 connection.
Returns (str):
The SMA1 to NIC1 connection.
"""
return self.sma1_to_nic1
def get_sma2_to_nic1(self) -> str:
"""
Gets the SMA2 to NIC1 connection.
Returns (str):
The SMA2 to NIC1 connection.
"""
return self.sma2_to_nic1
def get_sma1_to_nic2(self) -> str:
"""
Gets the SMA1 to NIC2 connection.
Returns (str):
The SMA1 to NIC2 connection.
"""
return self.sma1_to_nic2
def get_sma2_to_nic2(self) -> str:
"""
Gets the SMA2 to NIC2 connection.
Returns (str):
The SMA2 to NIC2 connection.
"""
return self.sma2_to_nic2
def get_base_port(self) -> str:
"""
Gets the base port.
Returns (str):
The base port.
"""
return self.base_port
def get_conn_to_ctrl0_nic1(self) -> str:
"""
Gets the connection to controller 0 NIC1.
Returns (str):
The connection to controller 0 NIC1.
"""
return self.conn_to_ctrl0_nic1
def get_conn_to_ctrl0_nic2(self) -> str:
"""
Gets the connection to controller 0 NIC2.
Returns (str):
The connection to controller 0 NIC2.
"""
return self.conn_to_ctrl0_nic2
def get_conn_to_ctrl1_nic1(self) -> str:
"""
Gets the connection to controller 1 NIC1.
Returns (str):
The connection to controller 1 NIC1.
"""
return self.conn_to_ctrl1_nic1
def get_conn_to_ctrl1_nic2(self) -> str:
"""
Gets the connection to controller 1 NIC2.
Returns (str):
The connection to controller 1 NIC2.
"""
return self.conn_to_ctrl1_nic2
def get_conn_to_spirent(self) -> str:
"""
Gets the connection to Spirent.
Returns (str):
The connection to Spirent.
"""
return self.conn_to_spirent
def get_spirent_port(self) -> str:
"""
Gets the Spirent port.
Returns (str):
The Spirent port.
"""
return self.spirent_port

View File

@@ -4,8 +4,7 @@ from config.configuration_manager import ConfigurationManagerClass
def test_default_k8s_config():
"""
Tests that the default logger configuration is as expected.
Returns:
Tests that the default k8s configuration is as expected.
"""
configuration_manager = ConfigurationManagerClass()

View File

@@ -0,0 +1,22 @@
from config.configuration_file_locations_manager import ConfigurationFileLocationsManager
from config.configuration_manager import ConfigurationManagerClass
def test_default_ptp_config():
"""
Tests that the default ptp configuration is as expected.
"""
configuration_manager = ConfigurationManagerClass()
config_file_locations = ConfigurationFileLocationsManager()
configuration_manager.load_configs(config_file_locations)
default_config = configuration_manager.get_ptp_config()
assert default_config is not None, "Default PTP config wasn't loaded successfully"
assert len(default_config.get_all_hosts()) == 2, "There are two hosts in the PTP config"
config_for_controller_0 = default_config.get_host("controller_0")
assert len(config_for_controller_0.get_all_nics()) == 2, "There are two NIC assigned to controller-0 in the PTP config"
first_nic = config_for_controller_0.get_nic("nic1")
assert first_nic.get_sma1_to_nic2() == "output"