diff --git a/locationservice-base/docker/locationservice/locationservicesdk/common/helpers/log_helper.py b/locationservice-base/docker/locationservice/locationservicesdk/common/helpers/log_helper.py index afd2187..3cfbca0 100644 --- a/locationservice-base/docker/locationservice/locationservicesdk/common/helpers/log_helper.py +++ b/locationservice-base/docker/locationservice/locationservicesdk/common/helpers/log_helper.py @@ -1,17 +1,22 @@ -import logging # -# Copyright (c) 2021 Wind River Systems, Inc. +# Copyright (c) 2021-2022 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # +import logging +import sys +import os + + def get_logger(module_name): logger = logging.getLogger(module_name) return config_logger(logger) + def config_logger(logger): - ''' - configure the logger: uncomment following lines for debugging - ''' - # logger.setLevel(level=logging.DEBUG) + logging.basicConfig(stream=sys.stdout, + format='%(asctime)s %(levelname)-8s %(message)s', + datefmt='%Y-%m-%d %H:%M:%S') + logger.setLevel(level=os.environ.get("LOGGING_LEVEL", "INFO")) return logger diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/constants.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/constants.py index 6e55760..6c0c1ef 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/constants.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/constants.py @@ -4,6 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 # +from os import path + # phc states constants FREERUN_PHC_STATE = "Freerun" LOCKED_PHC_STATE = "Locked" @@ -36,10 +38,18 @@ GNSS_DPLL_0 = "DPLL0" GNSS_DPLL_1 = "DPLL1" UTC_OFFSET = "37" -PTP_CONFIG_PATH = "/ptp/ptpinstance/" + +if path.exists('/ptp/linuxptp/ptpinstance'): + LINUXPTP_CONFIG_PATH = '/ptp/linuxptp/ptpinstance/' +elif path.exists('/ptp/ptpinstance'): + LINUXPTP_CONFIG_PATH = '/ptp/ptpinstance/' +else: + LINUXPTP_CONFIG_PATH = '/ptp/' +PTP_CONFIG_PATH = LINUXPTP_CONFIG_PATH +PHC2SYS_CONFIG_PATH = LINUXPTP_CONFIG_PATH +TS2PHC_CONFIG_PATH = LINUXPTP_CONFIG_PATH PHC_CTL_PATH = "/usr/sbin/phc_ctl" -PHC2SYS_DEFAULT_CONFIG = "/ptp/ptpinstance/phc2sys-phc2sys-legacy.conf" -PHC2SYS_CONF_PATH = "/ptp/ptpinstance/" +PHC2SYS_DEFAULT_CONFIG = PHC2SYS_CONFIG_PATH + "phc2sys-phc2sys-legacy.conf" CLOCK_REALTIME = "CLOCK_REALTIME" diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/gnss_monitor.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/gnss_monitor.py index 3ea1ac9..c7af560 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/gnss_monitor.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/gnss_monitor.py @@ -10,6 +10,7 @@ import re from abc import ABC, abstractmethod +from trackingfunctionsdk.common.helpers import constants from trackingfunctionsdk.common.helpers import log_helper from trackingfunctionsdk.common.helpers.cgu_handler import CguHandler from trackingfunctionsdk.model.dto.gnssstate import GnssState @@ -33,18 +34,23 @@ class GnssMonitor(Observer): _state = GnssState() gnss_cgu_handler = None - def __init__(self, config_file, nmea_serialport=None, pci_addr=None, cgu_path=None): + def __init__(self, config_file, nmea_serialport=None, pci_addr=None, + cgu_path=None): self.config_file = config_file try: - pattern = '(?<=/ptp/ptpinstance/ts2phc-).*(?=.conf)' + pattern = '(?<=' + \ + constants.TS2PHC_CONFIG_PATH + \ + 'ts2phc-).*(?=.conf)' match = re.search(pattern, self.config_file) self.ts2phc_service_name = match.group() except AttributeError: - LOG.warning("GnssMonitor: Unable to determine tsphc_service name from %s" - % self.config_file) + LOG.warning( + "GnssMonitor: Unable to determine tsphc_service name from %s" + % self.config_file) # Setup GNSS data - self.gnss_cgu_handler = CguHandler(config_file, nmea_serialport, pci_addr, cgu_path) + self.gnss_cgu_handler = CguHandler(config_file, nmea_serialport, + pci_addr, cgu_path) if self.gnss_cgu_handler.nmea_serialport is None: self.gnss_cgu_handler.get_gnss_nmea_serialport_from_ts2phc_config() @@ -56,8 +62,10 @@ class GnssMonitor(Observer): self.gnss_cgu_handler.read_cgu() self.gnss_cgu_handler.cgu_output_to_dict() - self.dmesg_values_to_check = {'pin': 'GNSS-1PPS', - 'pci_addr': self.gnss_cgu_handler.pci_addr} + self.dmesg_values_to_check = { + 'pin': 'GNSS-1PPS', + 'pci_addr': self.gnss_cgu_handler.pci_addr + } # Initialize status if self.gnss_cgu_handler.cgu_output_parsed['EEC DPLL']['Current reference'] == 'GNSS-1PPS': @@ -72,8 +80,10 @@ class GnssMonitor(Observer): def set_gnss_status(self): # Check that ts2phc is running, else Freerun - if not os.path.isfile('/var/run/ts2phc-%s.pid' % self.ts2phc_service_name): - LOG.warning("TS2PHC instance %s is not running, reporting GNSS unlocked." + if not os.path.isfile('/var/run/ts2phc-%s.pid' + % self.ts2phc_service_name): + LOG.warning("TS2PHC instance %s is not running, " + "reporting GNSS unlocked." % self.ts2phc_service_name) self._state = GnssState.Failure_Nofix return @@ -85,7 +95,8 @@ class GnssMonitor(Observer): self.gnss_pps_state = self.gnss_cgu_handler.cgu_output_parsed['PPS DPLL']['Status'] LOG.debug("GNSS EEC Status is: %s" % self.gnss_eec_state) LOG.debug("GNSS PPS Status is: %s" % self.gnss_pps_state) - if self.gnss_pps_state == 'locked_ho_ack' and self.gnss_eec_state == 'locked_ho_ack': + if self.gnss_pps_state == 'locked_ho_ack' and \ + self.gnss_eec_state == 'locked_ho_ack': self._state = GnssState.Synchronized else: self._state = GnssState.Failure_Nofix @@ -94,7 +105,6 @@ class GnssMonitor(Observer): def get_gnss_status(self, holdover_time, freq, sync_state, event_time): previous_sync_state = sync_state - max_holdover_time = (holdover_time - freq * 2) self.set_gnss_status() @@ -105,4 +115,3 @@ class GnssMonitor(Observer): else: new_event = False return new_event, self._state, event_time - diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/os_clock_monitor.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/os_clock_monitor.py index 6e73b2b..7a47a1e 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/os_clock_monitor.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/os_clock_monitor.py @@ -31,8 +31,8 @@ class OsClockMonitor: self.phc2sys_config = phc2sys_config self.set_phc2sys_instance() - """Normally initialize all fields, but allow these to be skipped to assist with unit testing - or to short-circuit values if required. + """Normally initialize all fields, but allow these to be skipped to + assist with unit testing or to short-circuit values if required. """ if init: self.get_os_clock_time_source() @@ -40,8 +40,8 @@ class OsClockMonitor: self.set_os_clock_state() def set_phc2sys_instance(self): - self.phc2sys_instance = self.phc2sys_config.split(constants.PHC2SYS_CONF_PATH - + "phc2sys-")[1] + self.phc2sys_instance = self.phc2sys_config.split( + constants.PHC2SYS_CONFIG_PATH + "phc2sys-")[1] self.phc2sys_instance = self.phc2sys_instance.split(".")[0] LOG.debug("phc2sys config file: %s" % self.phc2sys_config) LOG.debug("phc2sys instance name: %s" % self.phc2sys_instance) @@ -77,7 +77,8 @@ class OsClockMonitor: phc_interface = cmdline_args[interface_index + 1] if phc_interface == constants.CLOCK_REALTIME: - LOG.info("PHC2SYS is using CLOCK_REALTIME, OS Clock is not being disciplined by a PHC") + LOG.info("PHC2SYS is using CLOCK_REALTIME, OS Clock is not being " + "disciplined by a PHC") return None LOG.debug("PHC interface is %s" % phc_interface) return phc_interface @@ -91,9 +92,10 @@ class OsClockMonitor: # Find the interface value inside the square brackets if re.match(r"^\[.*\]$", line) and line != "[global]": phc_interface = line.strip("[]") + LOG.debug("PHC interface is %s" % phc_interface) + return phc_interface - LOG.debug("PHC interface is %s" % phc_interface) - return phc_interface + return None def _get_interface_phc_device(self): """Determine the phc device for the interface""" @@ -102,11 +104,14 @@ class OsClockMonitor: if len(ptp_device) == 0: # Try the 0th interface instead, required for some NIC types phc_interface_base = self.phc_interface[:-1] + "0" - LOG.error("No ptp device found at %s trying %s instead" % (pattern, phc_interface_base)) - pattern = "/hostsys/class/net/" + phc_interface_base + "/device/ptp/*" + LOG.error("No ptp device found at %s trying %s instead" + % (pattern, phc_interface_base)) + pattern = "/hostsys/class/net/" + phc_interface_base + \ + "/device/ptp/*" ptp_device = glob(pattern) if len(ptp_device) == 0: - LOG.warning("No ptp device found for base interface at %s" % pattern) + LOG.warning("No ptp device found for base interface at %s" + % pattern) return None if len(ptp_device) > 1: LOG.error("More than one ptp device found at %s" % pattern) @@ -117,30 +122,42 @@ class OsClockMonitor: def get_os_clock_offset(self): """Get the os CLOCK_REALTIME offset""" + if self.ptp_device is None: + # This may happen in virtualized environments + LOG.warning("No PTP device. Defaulting offset value to 0.") + self.offset = "0" + return try: ptp_device_path = "/dev/" + self.ptp_device - offset = subprocess.check_output([constants.PHC_CTL_PATH, ptp_device_path, 'cmp'] - ).decode().split()[-1] + offset = subprocess.check_output( + [constants.PHC_CTL_PATH, ptp_device_path, 'cmp'] + ).decode().split()[-1] offset = offset.strip("-ns") LOG.debug("PHC offset is %s" % offset) self.offset = offset except Exception as ex: - # We have seen rare instances where the ptp device cannot be read but then works fine - # on the next attempt. Setting the offset to 0 here will allow the OS clock to move to - # holdover. If there is a real fault, it will stay in holdover and tranition to freerun - # but if it was just a single miss, it will return to locked on the next check. - LOG.warning("Unable to read device offset for %s due to %s" % (ptp_device_path, ex)) - LOG.warning("Check operation of %s. Defaulting offset value to 0." % ptp_device_path) + # We have seen rare instances where the ptp device cannot be read + # but then works fine on the next attempt. Setting the offset to 0 + # here will allow the OS clock to move to holdover. If there is a + # real fault, it will stay in holdover and tranition to freerun but + # if it was just a single miss, it will return to locked on the + # next check. + LOG.warning("Unable to read device offset for %s due to %s" + % (ptp_device_path, ex)) + LOG.warning("Check operation of %s. Defaulting offset value to 0." + % ptp_device_path) self.offset = "0" def set_os_clock_state(self): offset_int = int(self.offset) if offset_int > constants.PHC2SYS_TOLERANCE_HIGH or \ offset_int < constants.PHC2SYS_TOLERANCE_LOW: - LOG.warning("PHC2SYS offset is outside of tolerance, handling state change.") + LOG.warning("PHC2SYS offset is outside of tolerance, " + "handling state change.") self._state = OsClockState.Freerun else: - LOG.info("PHC2SYS offset is within tolerance, OS clock state is LOCKED") + LOG.info("PHC2SYS offset is within tolerance, " + "OS clock state is LOCKED") self._state = OsClockState.Locked def get_os_clock_state(self): @@ -158,14 +175,16 @@ class OsClockMonitor: self.set_os_clock_state() if self.get_os_clock_state() == constants.FREERUN_PHC_STATE: - if previous_sync_state in [constants.UNKNOWN_PHC_STATE, constants.FREERUN_PHC_STATE]: + if previous_sync_state in [constants.UNKNOWN_PHC_STATE, + constants.FREERUN_PHC_STATE]: self._state = constants.FREERUN_PHC_STATE elif previous_sync_state == constants.LOCKED_PHC_STATE: self._state = constants.HOLDOVER_PHC_STATE elif previous_sync_state == constants.HOLDOVER_PHC_STATE and \ time_in_holdover < max_holdover_time: - LOG.debug("OS Clock: Time in holdover is %s Max time in holdover is %s" % ( - time_in_holdover, max_holdover_time)) + LOG.debug("OS Clock: Time in holdover is %s " + "Max time in holdover is %s" + % (time_in_holdover, max_holdover_time)) self._state = constants.HOLDOVER_PHC_STATE else: self._state = constants.FREERUN_PHC_STATE @@ -180,6 +199,6 @@ class OsClockMonitor: if __name__ == "__main__": - # This file can be run in a ptp-notification pod to verify the functionality of - # os_clock_monitor. + # This file can be run in a ptp-notification pod to verify the + # functionality of os_clock_monitor. test_monitor = OsClockMonitor() 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 9149df8..7fe0c10 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptp_monitor.py @@ -13,8 +13,6 @@ # import datetime import logging -import os -import re import sys from trackingfunctionsdk.model.dto.ptpstate import PtpState @@ -43,24 +41,30 @@ class PtpMonitor: ptp_oper_dict = { # [pmc cmd, ptp keywords,...] 1: ["'GET PORT_DATA_SET'", constants.PORT_STATE], - 2: ["'GET TIME_STATUS_NP'", constants.GM_PRESENT, constants.MASTER_OFFSET], - 3: ["'GET PARENT_DATA_SET'", constants.GM_CLOCK_CLASS, constants.GRANDMASTER_IDENTITY], + 2: ["'GET TIME_STATUS_NP'", constants.GM_PRESENT, + constants.MASTER_OFFSET], + 3: ["'GET PARENT_DATA_SET'", constants.GM_CLOCK_CLASS, + constants.GRANDMASTER_IDENTITY], 4: ["'GET TIME_PROPERTIES_DATA_SET'", constants.TIME_TRACEABLE], - 5: ["'GET DEFAULT_DATA_SET'", constants.CLOCK_IDENTITY, constants.CLOCK_CLASS], + 5: ["'GET DEFAULT_DATA_SET'", constants.CLOCK_IDENTITY, + constants.CLOCK_CLASS], } pmc_query_results = {} - def __init__(self, ptp4l_instance, holdover_time, freq, phc2sys_service_name, 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_config = constants.PTP_CONFIG_PATH + ("ptp4l-%s.conf" % + ptp4l_instance) self.ptp4l_service_name = ptp4l_instance 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() - self._clock_class_event_time = datetime.datetime.utcnow().timestamp() + self._clock_class_event_time = \ + datetime.datetime.utcnow().timestamp() self.set_ptp_sync_state() self.set_ptp_clock_class() @@ -74,7 +78,8 @@ class PtpMonitor: self._new_ptp_sync_event = new_ptp_sync_event def get_ptp_sync_state(self): - return self._new_ptp_sync_event, self._ptp_sync_state, self._ptp_event_time + return self._new_ptp_sync_event, self._ptp_sync_state, \ + self._ptp_event_time def set_ptp_clock_class(self): try: @@ -82,11 +87,13 @@ class PtpMonitor: # Reset retry counter upon getting clock class self._clock_class_retry = 3 except KeyError: - LOG.warning("set_ptp_clock_class: Unable to read current clockClass") + LOG.warning( + "set_ptp_clock_class: Unable to read current clockClass") if self._clock_class_retry > 0: self._clock_class_retry -= 1 LOG.warning("Trying to get clockClass %s more time(s) before " - "setting clockClass 248 (FREERUN)" % self._clock_class_retry) + "setting clockClass 248 (FREERUN)" + % self._clock_class_retry) clock_class = self._clock_class else: clock_class = "248" @@ -94,7 +101,8 @@ class PtpMonitor: if clock_class != self._clock_class: self._clock_class = clock_class self._new_clock_class_event = True - self._clock_class_event_time = datetime.datetime.utcnow().timestamp() + self._clock_class_event_time = \ + datetime.datetime.utcnow().timestamp() LOG.debug(self.pmc_query_results) LOG.info("PTP clock class is %s" % self._clock_class) else: @@ -102,7 +110,8 @@ class PtpMonitor: def get_ptp_clock_class(self): self.set_ptp_clock_class() - return self._new_clock_class_event, self._clock_class, self._clock_class_event_time + return self._new_clock_class_event, self._clock_class, \ + self._clock_class_event_time def ptp_status(self): # holdover_time - time phc can maintain clock @@ -123,28 +132,33 @@ class PtpMonitor: # max holdover time is calculated to be in a 'safety' zone max_holdover_time = (self.holdover_time - self.freq * 2) - - pmc, ptp4l, phc2sys, ptp4lconf = utils.check_critical_resources(self.ptp4l_service_name, - self.phc2sys_service_name) + pmc, ptp4l, phc2sys, ptp4lconf = \ + utils.check_critical_resources(self.ptp4l_service_name, + self.phc2sys_service_name) # run pmc command if preconditions met if pmc and ptp4l and phc2sys and ptp4lconf: - self.pmc_query_results, total_ptp_keywords, port_count = self.ptpsync() - sync_state = utils.check_results(self.pmc_query_results, total_ptp_keywords, port_count) + self.pmc_query_results, total_ptp_keywords, port_count = \ + self.ptpsync() + sync_state = utils.check_results(self.pmc_query_results, + total_ptp_keywords, port_count) else: - LOG.warning("Missing critical resource: PMC %s PTP4L %s PHC2SYS %s PTP4LCONF %s" % (pmc, ptp4l, phc2sys, ptp4lconf)) + LOG.warning("Missing critical resource: " + "PMC %s PTP4L %s PHC2SYS %s PTP4LCONF %s" + % (pmc, ptp4l, phc2sys, ptp4lconf)) sync_state = PtpState.Freerun - # determine if transition into holdover mode (cannot be in holdover if system clock is - # not in - # sync) + # determine if transition into holdover mode (cannot be in holdover if + # system clock is not in sync) if sync_state == PtpState.Freerun and phc2sys: - if previous_sync_state in [constants.UNKNOWN_PHC_STATE, PtpState.Freerun]: + if previous_sync_state in [constants.UNKNOWN_PHC_STATE, + PtpState.Freerun]: sync_state = PtpState.Freerun elif previous_sync_state == PtpState.Locked: sync_state = PtpState.Holdover - elif previous_sync_state == PtpState.Holdover and time_in_holdover < \ - max_holdover_time: - LOG.debug("PTP Status: Time in holdover is %s Max time in holdover is %s" % ( - time_in_holdover, max_holdover_time)) + elif previous_sync_state == PtpState.Holdover and \ + time_in_holdover < max_holdover_time: + LOG.debug("PTP Status: Time in holdover is %s " + "Max time in holdover is %s" + % (time_in_holdover, max_holdover_time)) sync_state = PtpState.Holdover else: sync_state = PtpState.Freerun @@ -169,8 +183,8 @@ class PtpMonitor: for key in range(1, len_dic + 1): cmd = ptp_dict_to_use[key][0] - cmd = "pmc -b 0 -u -f /ptp/ptpinstance/ptp4l-" + self.ptp4l_service_name + ".conf " +\ - cmd + cmd = "pmc -b 0 -u -f " + constants.PTP_CONFIG_PATH + \ + "ptp4l-" + self.ptp4l_service_name + ".conf " + cmd ptp_keyword = ptp_dict_to_use[key][1:] total_ptp_keywords += len(ptp_keyword) @@ -198,7 +212,8 @@ class PtpMonitor: if state[0] == item: if item == constants.PORT_STATE: port_count += 1 - result.update({constants.PORT.format(port_count): state[1]}) + result.update( + {constants.PORT.format(port_count): state[1]}) else: state[1] = state[1].replace('\\n', '') state[1] = state[1].replace('\'', '') @@ -213,7 +228,7 @@ class PtpMonitor: if __name__ == "__main__": test_ptp = PtpMonitor() - LOG.debug("PTP sync state for %s is %s" % ( - test_ptp.ptp4l_service_name, test_ptp.get_ptp_sync_state())) - LOG.debug("PTP clock class for %s is %s" % ( - test_ptp.ptp4l_service_name, test_ptp.get_ptp_clock_class())) + LOG.debug("PTP sync state for %s is %s" + % (test_ptp.ptp4l_service_name, test_ptp.get_ptp_sync_state())) + LOG.debug("PTP clock class for %s is %s" + % (test_ptp.ptp4l_service_name, test_ptp.get_ptp_clock_class())) diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptpsync.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptpsync.py index 1e4dcc3..fc3bc1a 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptpsync.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/ptpsync.py @@ -12,12 +12,9 @@ # Sync status provided as: 'Locked', 'Holdover', 'Freerun' # # -import errno, os -import os.path +import os import re -import sys import subprocess -import datetime import logging from trackingfunctionsdk.common.helpers import constants from trackingfunctionsdk.common.helpers import log_helper @@ -53,7 +50,8 @@ def check_critical_resources(ptp4l_service_name, phc2sys_service_name): ptp4l = True if os.path.isfile('/var/run/phc2sys-%s.pid' % phc2sys_service_name): phc2sys = True - if os.path.isfile('/ptp/ptpinstance/ptp4l-%s.conf' % ptp4l_service_name): + if os.path.isfile(constants.PTP_CONFIG_PATH + + ('ptp4l-%s.conf' % ptp4l_service_name)): ptp4lconf = True return pmc, ptp4l, phc2sys, ptp4lconf 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 a10e6b4..e4f9f16 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 @@ -18,15 +18,15 @@ from trackingfunctionsdk.services.daemon import DaemonControl LOG = logging.getLogger(__name__) log_helper.config_logger(LOG) - - THIS_NAMESPACE = os.environ.get("THIS_NAMESPACE", 'notification') THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME", 'controller-0') THIS_POD_IP = os.environ.get("THIS_POD_IP", '127.0.0.1') REGISTRATION_USER = os.environ.get("REGISTRATION_USER", "guest") REGISTRATION_PASS = os.environ.get("REGISTRATION_PASS", "guest") REGISTRATION_PORT = os.environ.get("REGISTRATION_PORT", "5672") -# REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST", 'registration.notification.svc.cluster.local') +# REGISTRATION_HOST = \ +# os.environ.get("REGISTRATION_HOST", +# 'registration.notification.svc.cluster.local') REGISTRATION_HOST = os.environ.get("REGISTRATION_HOST", 'localhost') # 'rabbit://admin:admin@[127.0.0.1]:5672/' @@ -39,7 +39,8 @@ NOTIFICATION_BROKER_PASS = os.environ.get("NOTIFICATIONSERVICE_PASS", "guest") NOTIFICATION_BROKER_PORT = os.environ.get("NOTIFICATIONSERVICE_PORT", "5672") NOTIFICATION_TRANSPORT_ENDPOINT = 'rabbit://{0}:{1}@[{2}]:{3}'.format( - NOTIFICATION_BROKER_USER, NOTIFICATION_BROKER_PASS, THIS_POD_IP, NOTIFICATION_BROKER_PORT) + NOTIFICATION_BROKER_USER, NOTIFICATION_BROKER_PASS, THIS_POD_IP, + NOTIFICATION_BROKER_PORT) PTP_DEVICE_SIMULATED = os.environ.get("PTP_DEVICE_SIMULATED", True) @@ -53,7 +54,9 @@ PHC2SYS_SERVICE_NAME = None if os.environ.get("PHC2SYS_SERVICE_NAME").lower() == "false": LOG.info("OS Clock tracking disabled.") else: - PHC2SYS_CONFIGS = glob.glob("/ptp/ptpinstance/phc2sys-*") + PHC2SYS_CONFIGS = glob.glob(constants.PHC2SYS_CONFIG_PATH + "phc2sys-*") + LOG.debug('Looked for phc2sys configuration file(s) in %s, found %d' + % (constants.PHC2SYS_CONFIG_PATH, len(PHC2SYS_CONFIGS))) if len(PHC2SYS_CONFIGS) == 0: LOG.warning("No phc2sys config found.") else: @@ -61,7 +64,8 @@ else: if len(PHC2SYS_CONFIGS) > 1: LOG.warning("Multiple phc2sys instances found, selecting %s" % PHC2SYS_CONFIG) - pattern = '(?<=/ptp/ptpinstance/phc2sys-).*(?=.conf)' + pattern = '(?<=' + constants.PHC2SYS_CONFIG_PATH + \ + 'phc2sys-).*(?=.conf)' match = re.search(pattern, PHC2SYS_CONFIG) PHC2SYS_SERVICE_NAME = match.group() @@ -70,9 +74,11 @@ 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_CONFIGS = glob.glob(constants.PTP_CONFIG_PATH + "ptp4l-*") + LOG.debug('Looked for ptp4l configuration file(s) in %s, found %d' + % (constants.PTP_CONFIG_PATH, len(PTP4L_CONFIGS))) PTP4L_INSTANCES = [] - pattern = '(?<=/ptp/ptpinstance/ptp4l-).*(?=.conf)' + pattern = '(?<=' + constants.PTP_CONFIG_PATH + 'ptp4l-).*(?=.conf)' for conf in PTP4L_CONFIGS: match = re.search(pattern, conf) PTP4L_INSTANCES.append(match.group()) @@ -82,9 +88,11 @@ 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_CONFIGS = glob.glob(constants.TS2PHC_CONFIG_PATH + "ts2phc-*") + LOG.debug('Looked for ts2phc configuration file(s) in %s, found %d' + % (constants.TS2PHC_CONFIG_PATH, len(GNSS_CONFIGS))) GNSS_INSTANCES = [] - pattern = '(?<=/ptp/ptpinstance/ts2phc-).*(?=.conf)' + pattern = '(?<=' + constants.TS2PHC_CONFIG_PATH + 'ts2phc-).*(?=.conf)' for conf in GNSS_CONFIGS: match = re.search(pattern, conf) GNSS_INSTANCES.append(match.group()) @@ -126,9 +134,7 @@ sqlalchemy_conf = { } LOG.info("PTP tracking service startup context %s" % context) sqlalchemy_conf_json = json.dumps(sqlalchemy_conf) -default_daemoncontrol = DaemonControl(sqlalchemy_conf_json, json.dumps(context)) +default_daemoncontrol = DaemonControl(sqlalchemy_conf_json, + json.dumps(context)) default_daemoncontrol.refresh() - - - diff --git a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml index 87fd0d9..b13dc16 100644 --- a/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml +++ b/stx-ptp-notification-helm/stx-ptp-notification-helm/helm-charts/ptp-notification/templates/daemonset.yaml @@ -84,6 +84,8 @@ spec: value: "{{ .Values.notification.endpoint.pass }}" - name: NOTIFICATIONSERVICE_PORT value: "{{ .Values.notification.endpoint.port }}" + - name: LOGGING_LEVEL + value: "{{ .Values.location.log_level }}" command: ["/bin/bash", "/mnt/locationservice_start.sh"] volumeMounts: @@ -133,8 +135,6 @@ spec: value: "{{ .Values.ptptracking.ptp4lServiceName }}" - name: PHC2SYS_SERVICE_NAME value: "{{ .Values.ptptracking.phc2sysServiceName }}" - - name: PHC2SYS_CONFIG - value: "/ptp/ptpinstance/phc2sys-{{.Values.ptptracking.phc2sysServiceName}}.conf" - name: TS2PHC_SERVICE_NAME value: "{{ .Values.ptptracking.ts2phcServiceName }}" - name: LOGGING_LEVEL 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 2229b0a..c3670d6 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 @@ -59,6 +59,7 @@ notification: - "true" location: + log_level: INFO image: repository: starlingx/locationservice-base tag: stx.5.0-v1.0.1