From 9f34e8951d4d61de5882796c7401ce5c48105bb1 Mon Sep 17 00:00:00 2001 From: Cole Walker Date: Thu, 15 Sep 2022 13:25:26 -0400 Subject: [PATCH] [PTP] Handle NICs with a single PHC device Issue: The logic to determine the path for the PHC device does not work properly when a NIC has only one PHC device. The way to determine the OS clock accuracy/offest uses the phc_ctl command to read the difference between the PHC and the OS clock. In order to do this from the container, we need the path for the PHC device. Added logic to try the 0th interface of the NIC if there is no device found on the initial phc_interface. Some NICs with a single PHC only present it on the base interface. Test plan: PASS: Build and deploy notificationservice-base container image PASS: Monitor OS clock offset using the non-0th interface and verify PHC device is still found Story: 2010056 Task: 46323 Change-Id: Idf77f9abd73e6096c832d2905b26103061104f4d --- .../common/helpers/os_clock_monitor.py | 11 ++++++++--- .../tests/test_os_clock_monitor.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) 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 169701a..9c3b533 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 @@ -100,12 +100,17 @@ class OsClockMonitor: pattern = "/hostsys/class/net/" + self.phc_interface + "/device/ptp/*" ptp_device = glob(pattern) if len(ptp_device) == 0: - LOG.error("No ptp device found at %s" % pattern) - return None + # 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/*" + ptp_device = glob(pattern) + if len(ptp_device) == 0: + 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) return None - ptp_device = os.path.basename(ptp_device[0]) LOG.debug("Found ptp device %s at %s" % (ptp_device, pattern)) return ptp_device diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_os_clock_monitor.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_os_clock_monitor.py index 6682c58..805796b 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_os_clock_monitor.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_os_clock_monitor.py @@ -52,6 +52,7 @@ class OsClockMonitorTests(unittest.TestCase): side_effect=[['/hostsys/class/net/ens1f0/device/ptp/ptp0'], ['/hostsys/class/net/ens1f0/device/ptp/ptp0', '/hostsys/class/net/ens1f0/device/ptp/ptp1'], + [], [] ]) def test_get_interface_phc_device(self, glob_patched):