From 916f9da1126cc308a75d9856a111b147dec142d2 Mon Sep 17 00:00:00 2001 From: Cole Walker Date: Thu, 17 Nov 2022 14:24:04 -0500 Subject: [PATCH] [PTP] Update cgu parser for Logan Beach NIC Intel Logan Beach NICs have additional fields in the cgu output, resulting in failures when converting it into a dict. Updated the logic for cgu_output_to_dict() to find the start and end of the "input" table. Once the start and end lines of the table are identified, then the other required fields can be located based on the known offset from the table. This also allows any future lines added to the table to handled without requiring additional code changes. Updated the unit tests to cover both the Logan Beach and Westport Channel cgu output formats. Test plan: PASS: Unit tests passing PASS: Build notificationservice-base image and test on both NIC types. Story: 2010270 Task: 46870 Signed-off-by: Cole Walker Change-Id: Ib6716f38ea3c64a68e7162bb5d4f2154fa399a8c --- .../common/helpers/cgu_handler.py | 29 +++++++--- .../tests/test_cgu_handler.py | 56 ++++++++++++++----- .../mock_cgu_output_logan_beach | 25 +++++++++ ...utput => mock_cgu_output_westport_channel} | 0 4 files changed, 90 insertions(+), 20 deletions(-) create mode 100644 notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_logan_beach rename notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/{mock_cgu_output => mock_cgu_output_westport_channel} (100%) diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/cgu_handler.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/cgu_handler.py index d04e724..a3088dc 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/cgu_handler.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/common/helpers/cgu_handler.py @@ -95,9 +95,17 @@ class CguHandler: 'Phase offset': '' } } + # Get the input state table start and end lines + # Can vary in length depending on NIC types + for index, line in enumerate(cgu_output): + if "input (idx)" in line: + table_start = index + 2 + if "EEC DPLL:" in line: + dpll_start = index + table_end = index - 1 - for line in cgu_output[7:14]: - # Build a dict out of the 7 line table + for line in cgu_output[table_start:table_end]: + # Build a dict out of the table dict_to_insert = { re.split(' +', line)[1]: { 'state': re.split(' +', line)[4], @@ -110,13 +118,20 @@ class CguHandler: cgu_dict['input'].update(dict_to_insert) # Add the DPLL data below the table + # Set the line offsets for each item we want + eec_current_ref = dpll_start + 1 + eec_status = dpll_start + 2 + pps_current_ref = dpll_start + 5 + pps_status = dpll_start + 6 + pps_phase_offset = dpll_start + 7 + cgu_dict['EEC DPLL']['Current reference'] = \ - re.split('[ \t]+', cgu_output[16])[3] - cgu_dict['EEC DPLL']['Status'] = re.split('[ \t]+', cgu_output[17])[2] + re.split('[ \t]+', cgu_output[eec_current_ref])[-1] + cgu_dict['EEC DPLL']['Status'] = re.split('[ \t]+', cgu_output[eec_status])[-1] cgu_dict['PPS DPLL']['Current reference'] = \ - re.split('[ \t]+', cgu_output[20])[3] - cgu_dict['PPS DPLL']['Status'] = re.split('[ \t]+', cgu_output[21])[2] + re.split('[ \t]+', cgu_output[pps_current_ref])[-1] + cgu_dict['PPS DPLL']['Status'] = re.split('[ \t]+', cgu_output[pps_status])[-1] cgu_dict['PPS DPLL']['Phase offset'] = \ - re.split('[ \t]+', cgu_output[22])[3] + re.split('[ \t]+', cgu_output[pps_phase_offset])[-1] self.cgu_output_parsed = cgu_dict diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_cgu_handler.py b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_cgu_handler.py index 514e631..ddb7e3c 100644 --- a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_cgu_handler.py +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_cgu_handler.py @@ -57,21 +57,51 @@ class CguHandlerTests(unittest.TestCase): with self.assertRaises(FileNotFoundError): self.testCguHandler.get_cgu_path_from_pci_addr() - def test_cgu_output_to_dict(self): + 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'}}, - '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'}} + "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" + 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) diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_logan_beach b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_logan_beach new file mode 100644 index 0000000..2590022 --- /dev/null +++ b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_logan_beach @@ -0,0 +1,25 @@ +Found ZL80032 CGU +DPLL Config ver: 1.3.0.1 + +CGU Input status: + | | priority | | + input (idx) | state | EEC (0) | PPS (1) | ESync fail | + ---------------------------------------------------------------- + CVL-SDP22 (0) | invalid | 8 | 8 | N/A | + CVL-SDP20 (1) | invalid | 15 | 3 | N/A | + C827_0-RCLKA (2) | invalid | 4 | 4 | N/A | + C827_0-RCLKB (3) | invalid | 5 | 5 | N/A | + C827_1-RCLKA (4) | invalid | 6 | 6 | N/A | + C827_1-RCLKB (5) | invalid | 7 | 7 | N/A | + SMA1 (6) | invalid | 1 | 1 | N/A | + SMA2/U.FL2 (7) | invalid | 2 | 2 | N/A | + GNSS-1PPS (8) | valid | 0 | 0 | N/A | + +EEC DPLL: + Current reference: GNSS-1PPS + Status: locked_ho_acq + +PPS DPLL: + Current reference: GNSS-1PPS + Status: locked_ho_acq + Phase offset [ns]: -86 diff --git a/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output b/notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_westport_channel similarity index 100% rename from notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output rename to notificationservice-base/docker/ptptrackingfunction/trackingfunctionsdk/tests/test_input_files/mock_cgu_output_westport_channel