[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
This commit is contained in:
Cole Walker 2022-09-15 13:25:26 -04:00
parent 51c321afb7
commit 9f34e8951d
2 changed files with 9 additions and 3 deletions

View File

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

View File

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