diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py index c4fddcf..e9f4851 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py @@ -50,12 +50,12 @@ class PtpMonitor: pmc_query_results = {} - def __init__(self, ptp4l_instance, holdover_time, freq, init=True): + def __init__(self, ptp4l_instance, holdover_time, freq, phc2sys_service_name, init=True): if init: self.ptp4l_config = "/ptp/ptpinstance/ptp4l-%s.conf" % ptp4l_instance self.ptp4l_service_name = ptp4l_instance - self.phc2sys_service_name = os.environ.get('PHC2SYS_SERVICE_NAME', 'phc2sys') + self.phc2sys_service_name = phc2sys_service_name self.holdover_time = int(holdover_time) self.freq = int(freq) self._ptp_event_time = datetime.datetime.utcnow().timestamp() diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py index 62101a2..cd3144a 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/services/daemon.py @@ -332,7 +332,8 @@ class PtpWatcherDefault: # Setup PTP Monitor(s) self.ptp_monitor_list = [ PtpMonitor(config, self.ptptracker_context[config]['holdover_seconds'], - self.ptptracker_context[config]['poll_freq_seconds']) for config in + self.ptptracker_context[config]['poll_freq_seconds'], + self.daemon_context['PHC2SYS_SERVICE_NAME']) for config in self.daemon_context['PTP4L_INSTANCES']] def signal_ptp_event(self): diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.py b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.py index 5d21185..3ba47cb 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.py +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/resources/scripts/init/ptptracking_start.py @@ -5,10 +5,11 @@ # #!/usr/bin/python3 # -*- coding: UTF-8 -*- -import logging -import re -import os +import glob import json +import logging +import os +import re from trackingfunctionsdk.common.helpers import log_helper from trackingfunctionsdk.common.helpers import constants @@ -54,21 +55,44 @@ OS_CLOCK_POLL_FREQ_SECONDS = os.environ.get("OS_CLOCK_POLL_FREQ_SECONDS", 2) OVERALL_HOLDOVER_SECONDS = os.environ.get("OVERALL_HOLDOVER_SECONDS", 30) OVERALL_POLL_FREQ_SECONDS = os.environ.get("OVERALL_POLL_FREQ_SECONDS", 2) -PHC2SYS_CONFIG = "/ptp/ptpinstance/phc2sys-%s.conf" % os.environ.get("PHC2SYS_SERVICE_NAME", "phc2sys-legacy") +if os.environ.get("PHC2SYS_SERVICE_NAME").lower() == "false": + LOG.info("OS Clock tracking disabled.") + PHC2SYS_CONFIG = None +else: + PHC2SYS_CONFIG = glob.glob("/ptp/ptpinstance/phc2sys-*") + if len(PHC2SYS_CONFIG) == 0: + LOG.warning("No phc2sys config found.") + PHC2SYS_CONFIG = None + elif len(PHC2SYS_CONFIG) > 1: + LOG.warning("Multiple phc2sys instances found, selecting %s" % PHC2SYS_CONFIG[0]) + PHC2SYS_CONFIG = PHC2SYS_CONFIG[0] + pattern = '(?<=/ptp/ptpinstance/phc2sys-).*(?=.conf)' + match = re.search(pattern, PHC2SYS_CONFIG) + PHC2SYS_SERVICE_NAME = match.group() -PTP4L_INSTANCES = os.environ.get("PTP4L_SERVICE_NAME", "ptp4l-legacy") -PTP4L_INSTANCES = str(PTP4L_INSTANCES).replace('[','').replace(']','') -PTP4L_INSTANCES = PTP4L_INSTANCES.split() PTP4L_CONFIGS = [] -for item in PTP4L_INSTANCES: - PTP4L_CONFIGS.append("/ptp/ptpinstance/ptp4l-%s.conf" % item) +PTP4L_INSTANCES = [] +if os.environ.get("PTP4L_SERVICE_NAME").lower() == "false": + LOG.info("PTP4L instance tracking disabled.") +else: + PTP4L_CONFIGS = glob.glob("/ptp/ptpinstance/ptp4l-*") + PTP4L_INSTANCES = [] + pattern = '(?<=/ptp/ptpinstance/ptp4l-).*(?=.conf)' + for conf in PTP4L_CONFIGS: + match = re.search(pattern, conf) + PTP4L_INSTANCES.append(match.group()) -GNSS_INSTANCES = os.environ.get("TS2PHC_SERVICE_NAME", None) -GNSS_INSTANCES = str(GNSS_INSTANCES).replace('[','').replace(']','') -GNSS_INSTANCES = GNSS_INSTANCES.split() GNSS_CONFIGS = [] -for item in GNSS_INSTANCES: - GNSS_CONFIGS.append("/ptp/ptpinstance/ts2phc-%s.conf" % item) +GNSS_INSTANCES = [] +if os.environ.get("TS2PHC_SERVICE_NAME").lower() == "false": + LOG.info("GNSS instance tracking disabled.") +else: + GNSS_CONFIGS = glob.glob("/ptp/ptpinstance/ts2phc-*") + GNSS_INSTANCES = [] + pattern = '(?<=/ptp/ptpinstance/ts2phc-).*(?=.conf)' + for conf in GNSS_CONFIGS: + match = re.search(pattern, conf) + GNSS_INSTANCES.append(match.group()) context = { 'THIS_NAMESPACE': THIS_NAMESPACE, @@ -78,7 +102,8 @@ context = { 'NOTIFICATION_TRANSPORT_ENDPOINT': NOTIFICATION_TRANSPORT_ENDPOINT, 'GNSS_CONFIGS': GNSS_CONFIGS, 'PHC2SYS_CONFIG': PHC2SYS_CONFIG, - 'PTP4L_CONFIGS' : PTP4L_CONFIGS, + 'PHC2SYS_SERVICE_NAME': PHC2SYS_SERVICE_NAME, + 'PTP4L_CONFIGS': PTP4L_CONFIGS, 'GNSS_INSTANCES': GNSS_INSTANCES, 'PTP4L_INSTANCES': PTP4L_INSTANCES, diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml index 60de44c..b35be4c 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/values.yaml @@ -67,11 +67,9 @@ location: ptptracking: imagePullSecrets: default-registry-key ptp4lSocket: /var/run/ptp4l-ptp4l-legacy - ptp4lServiceName: - - ptp1 - - ptp2 - phc2sysServiceName: phc2sys-legacy - ts2phcServiceName: ts2phc-legacy + ptp4lServiceName: True + phc2sysServiceName: True + ts2phcServiceName: True log_level: INFO image: repository: starlingx/notificationservice-base