[PTP] Automatically determine list of services to monitor

Issue: Deploying ptp-notification on multiple nodes does not work
properly when each node has different ptp-instance names configured.

This change allows the ptp-notification pod to discover the ptp services
on each node that it is running on and generate a list of service names
to monitor. This also removes the requirement for users to supply an
override with a list of service names.

A given monitoring type can be disabled by supplying an override value
of "False" and ptp-notification will not track it.

Test plan:
PASS: Build and deploy ptp-notification
PASS: Automatically monitor all configured instances
PASS: Disable each instance type independently

Story: 2010056
Task: 46356

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: Ieb3ee26b9431e7ac15a7599a69ce9846dce78328
This commit is contained in:
Cole Walker 2022-09-16 10:26:58 -04:00
parent 9f34e8951d
commit fd72678e1f
4 changed files with 47 additions and 23 deletions

View File

@ -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()

View File

@ -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):

View File

@ -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,

View File

@ -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