Cole Walker 76d515c290 Handle missing sysfs path for in-tree ice driver
The in-tree ice driver version 6.6.40-stx.2 does not provide the debugfs
path used for monitoring the GNSS state. This commit provides the
following changes to support this driver:

1: Update the k8s daemonset to mount the /sys/kernel/debug path instead
   of /sys/kernel/debug/ice. The "ice" directory is not present using
   the in-tree driver, so mounting the parent directory allows the
   containers to be properly started and can then check if the "ice"
   directory is present at runtime
2: Update the startup script for the v2 container to check for the
   existence of the ice debugfs directory. If it is not present, disable
   GNSS tracking in ptp-notification
3: Update the path used by GNSS monitoring to match the changed mount
   path in the daemonset so that GNSS monitoring can proceed when the
   path is present

Currently, GNSS time sources and monitoring cannot be used with the
in-tree driver. GNSS time sources require configuring the system to use
the out-of-tree ice driver.

Test plan:
Pass: Verify helm chart and container build
Pass: Verify ptp-notification deployment using the in-tree ice driver,
ensure that GNSS tracking is automatically disabled when debugfs is not
present
Pass: Verify ptp-notification deployment using the out-of-tree ice
driver, ensure that GNSS tracking is operational when debugfs is present

Story: 2011056
Task: 50940

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: I73859408cf5655b58ebe2a1a78f407496c3380dd
2024-08-30 13:43:13 -04:00

112 lines
5.4 KiB
Python

#
# Copyright (c) 2022-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import unittest
import mock
from trackingfunctionsdk.common.helpers.cgu_handler import CguHandler
import os
testpath = os.environ.get("TESTPATH", "")
class CguHandlerTests(unittest.TestCase):
testCguHandler = CguHandler(testpath + "test_input_files/ts2phc_valid.conf")
missingCguHandler = CguHandler("./no_such_file.conf")
invalidCguHandler = CguHandler(testpath + "test_input_files/ts2phc_invalid.conf")
def test_get_gnss_nmea_serialport(self):
# Test success path
self.testCguHandler.get_gnss_nmea_serialport_from_ts2phc_config()
self.assertEqual(self.testCguHandler.nmea_serialport, "/dev/gnss0")
# Test missing / incorrect config file path
with self.assertRaises(FileNotFoundError):
self.missingCguHandler.get_gnss_nmea_serialport_from_ts2phc_config()
# Test missing nmea_serialport in config
self.invalidCguHandler.get_gnss_nmea_serialport_from_ts2phc_config()
self.assertEqual(self.invalidCguHandler.nmea_serialport,
None)
def test_convert_nmea_serialport_to_pci_addr(self):
# Test success path
self.testCguHandler.get_gnss_nmea_serialport_from_ts2phc_config()
with mock.patch('trackingfunctionsdk.common.helpers.cgu_handler.open',
new_callable=mock.mock_open,
read_data='PCI_SLOT_NAME=0000:18:00.0') as mock_open:
self.testCguHandler.convert_nmea_serialport_to_pci_addr()
mock_open.assert_called_with('/sys/class/gnss/gnss0/device/uevent', 'r')
self.assertEqual(self.testCguHandler.pci_addr, "0000:18:00.0")
# Test pci address not found
self.testCguHandler.nmea_serialport = "/dev/not_present"
self.testCguHandler.convert_nmea_serialport_to_pci_addr()
self.assertEqual(self.testCguHandler.pci_addr, None)
@mock.patch('trackingfunctionsdk.common.helpers.cgu_handler.os.path')
def test_get_cgu_path_from_pci_addr(self, mock_path):
# Setup mock
mock_path.exists.return_value = True
self.testCguHandler.get_gnss_nmea_serialport_from_ts2phc_config()
with mock.patch('trackingfunctionsdk.common.helpers.cgu_handler.open',
new_callable=mock.mock_open,
read_data='PCI_SLOT_NAME=0000:18:00.0') as mock_open:
self.testCguHandler.convert_nmea_serialport_to_pci_addr()
self.testCguHandler.get_cgu_path_from_pci_addr()
self.assertEqual(self.testCguHandler.cgu_path, "/ice/ice/0000:18:00.0/cgu")
mock_path.exists.return_value = False
with self.assertRaises(FileNotFoundError):
self.testCguHandler.get_cgu_path_from_pci_addr()
def test_cgu_output_to_dict_logan_beach(self):
reference_dict = {
"input": {
"CVL-SDP22": {"state": "invalid", "priority": {"EEC": "8", "PPS": "8"}},
"CVL-SDP20": {"state": "invalid", "priority": {"EEC": "15", "PPS": "3"}},
"C827_0-RCLKA": {"state": "invalid", "priority": {"EEC": "4", "PPS": "4"}},
"C827_0-RCLKB": {"state": "invalid", "priority": {"EEC": "5", "PPS": "5"}},
"C827_1-RCLKA": {"state": "invalid", "priority": {"EEC": "6", "PPS": "6"}},
"C827_1-RCLKB": {"state": "invalid", "priority": {"EEC": "7", "PPS": "7"}},
"SMA1": {"state": "invalid", "priority": {"EEC": "1", "PPS": "1"}},
"SMA2/U.FL2": {"state": "invalid", "priority": {"EEC": "2", "PPS": "2"}},
"GNSS-1PPS": {"state": "valid", "priority": {"EEC": "0", "PPS": "0"}},
},
"EEC DPLL": {"Current reference": "GNSS-1PPS", "Status": "locked_ho_acq"},
"PPS DPLL": {
"Current reference": "GNSS-1PPS",
"Status": "locked_ho_acq",
"Phase offset": "-86",
},
}
self.testCguHandler.cgu_path = testpath + "test_input_files/mock_cgu_output_logan_beach"
self.testCguHandler.read_cgu()
self.testCguHandler.cgu_output_to_dict()
self.assertDictEqual(self.testCguHandler.cgu_output_parsed, reference_dict)
def test_cgu_output_to_dict_westport_channel(self):
reference_dict = {
"input": {
"CVL-SDP22": {"state": "invalid", "priority": {"EEC": "8", "PPS": "8"}},
"CVL-SDP20": {"state": "invalid", "priority": {"EEC": "15", "PPS": "3"}},
"C827_0-RCLKA": {"state": "invalid", "priority": {"EEC": "4", "PPS": "4"}},
"C827_0-RCLKB": {"state": "invalid", "priority": {"EEC": "5", "PPS": "5"}},
"SMA1": {"state": "invalid", "priority": {"EEC": "1", "PPS": "1"}},
"SMA2/U.FL2": {"state": "invalid", "priority": {"EEC": "2", "PPS": "2"}},
"GNSS-1PPS": {"state": "valid", "priority": {"EEC": "0", "PPS": "0"}},
},
"EEC DPLL": {"Current reference": "GNSS-1PPS", "Status": "locked_ho_ack"},
"PPS DPLL": {
"Current reference": "GNSS-1PPS",
"Status": "locked_ho_ack",
"Phase offset": "295",
},
}
self.testCguHandler.cgu_path = testpath + "test_input_files/mock_cgu_output_westport_channel"
self.testCguHandler.read_cgu()
self.testCguHandler.cgu_output_to_dict()
self.assertDictEqual(self.testCguHandler.cgu_output_parsed, reference_dict)