Files
test/keywords/ptp/pmc/pmc_keywords.py
Guntaka Umashankar Reddy 3758f1758b Added pmc, phc_ctl and ip link set keywords
Change-Id: Ie456750985f4d50ccd76f18d6c8da558dbcb65e9
Signed-off-by: Guntaka Umashankar Reddy <umashankarguntaka.reddy@windriver.com>
2025-02-21 09:53:50 +00:00

166 lines
7.8 KiB
Python

from framework.ssh.ssh_connection import SSHConnection
from keywords.base_keyword import BaseKeyword
from keywords.ptp.pmc.objects.pmc_get_current_data_set_output import PMCGetCurrentDataSetOutput
from keywords.ptp.pmc.objects.pmc_get_default_data_set_output import PMCGetDefaultDataSetOutput
from keywords.ptp.pmc.objects.pmc_get_domain_output import PMCGetDomainOutput
from keywords.ptp.pmc.objects.pmc_get_grandmaster_settings_np_output import PMCGetGrandmasterSettingsNpOutput
from keywords.ptp.pmc.objects.pmc_get_parent_data_set_output import PMCGetParentDataSetOutput
from keywords.ptp.pmc.objects.pmc_get_time_properties_data_set_output import PMCGetTimePropertiesDataSetOutput
from keywords.ptp.pmc.objects.pmc_get_time_status_np_output import PMCGetTimeStatusNpOutput
class PMCKeywords(BaseKeyword):
"""
Class for PMC Keywords
"""
def __init__(self, ssh_connection: SSHConnection):
self.ssh_connection = ssh_connection
def pmc_get_time_status_np(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetTimeStatusNpOutput:
"""
Gets the TIME_STATUS_NP
Args:
config_file (): the config file
socket_file (): the socket file
unicast (): true to use unicast
boundry_clock (): the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_time_status_np('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET TIME_STATUS_NP'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_time_status_np_output = PMCGetTimeStatusNpOutput(output)
return pmc_get_time_status_np_output
def pmc_get_current_data_set(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetCurrentDataSetOutput:
"""
Gets the CURRENT_DATA_SET
Args:
config_file (): the config file
socket_file (): the socket file
unicast (): true to use unicast
boundry_clock (): the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_current_data_set('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET CURRENT_DATA_SET'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_current_data_set_output = PMCGetCurrentDataSetOutput(output)
return pmc_get_current_data_set_output
def pmc_set_grandmaster_settings_np(self, config_file: str, socket_file: str, clock_class: int, time_traceable: int) -> PMCGetGrandmasterSettingsNpOutput:
"""
SET GRANDMASTER_SETTINGS_NP
Args:
config_file : the config file
socket_file : the socket file
clock_class : clockClass of ptp
time_traceable : timeTraceable of ptp
Example: PMCKeywords(ssh_connection).pmc_set_grandmaster_settings_np('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', '/var/run/ptp4l-ptp5', 7, 1)
"""
cmd = f"pmc -u -b 0 -f {config_file} -s {socket_file} 'SET GRANDMASTER_SETTINGS_NP clockClass {clock_class} clockAccuracy 0xfe offsetScaledLogVariance 0xffff currentUtcOffset 37 leap61 0 leap59 0 currentUtcOffsetValid 0 ptpTimescale 1 timeTraceable {time_traceable} frequencyTraceable 0 timeSource 0xa0'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_set_grandmaster_settings_np_output = PMCGetGrandmasterSettingsNpOutput(output)
return pmc_set_grandmaster_settings_np_output
def pmc_get_grandmaster_settings_np(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetGrandmasterSettingsNpOutput:
"""
Gets the grandmaster_settings_np
Args:
config_file : the config file
socket_file : the socket file
unicast : true to use unicast
boundry_clock : the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_grandmaster_settings_np('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET GRANDMASTER_SETTINGS_NP'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_grandmaster_settings_np_output = PMCGetGrandmasterSettingsNpOutput(output)
return pmc_get_grandmaster_settings_np_output
def pmc_get_time_properties_data_set(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetTimePropertiesDataSetOutput:
"""
Gets the time_properties_data_set_object
Args:
config_file : the config file
socket_file : the socket file
unicast : true to use unicast
boundry_clock : the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_time_properties_data_set('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET TIME_PROPERTIES_DATA_SET'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_time_properties_data_set_output = PMCGetTimePropertiesDataSetOutput(output)
return pmc_get_time_properties_data_set_output
def pmc_get_default_data_set(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetDefaultDataSetOutput:
"""
Gets the default data et
Args:
config_file (): the config file
socket_file (): the socket file
unicast (): true to use unicast
boundry_clock (): the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_default_data_set('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET DEFAULT_DATA_SET'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_default_data_set_output = PMCGetDefaultDataSetOutput(output)
return pmc_get_default_data_set_output
def pmc_get_domain(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetDomainOutput:
"""
Gets the domain
Args:
config_file (): the config file
socket_file (): the socket file
unicast (): true to use unicast
boundry_clock (): the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_domain('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', ' /var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET DOMAIN'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_domain_output = PMCGetDomainOutput(output)
return pmc_get_domain_output
def pmc_get_parent_data_set(self, config_file: str, socket_file: str, unicast: bool = True, boundry_clock: int = 0) -> PMCGetParentDataSetOutput:
"""
Gets the parent data set
Args:
config_file (): the config file
socket_file (): the socket file
unicast (): true to use unicast
boundry_clock (): the boundry clock
Example: PMCKeywords(ssh_connection).pmc_get_parent_data_set('/etc/linuxptp/ptpinstance/ptp4l-ptp5.conf', '/var/run/ptp4l-ptp5')
"""
cmd = f"pmc {'-u' if unicast else ''} -b {boundry_clock} -f {config_file} -s {socket_file} 'GET PARENT_DATA_SET'"
output = self.ssh_connection.send_as_sudo(cmd)
pmc_get_parent_data_set_output = PMCGetParentDataSetOutput(output)
return pmc_get_parent_data_set_output