From 73affeb17c61e869a159882ef39c2e4e9e46b048 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 19 Dec 2024 10:30:34 +0000 Subject: [PATCH 1/2] Check if ntp.pcap exists before loading --- modules/test/ntp/python/src/ntp_module.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/test/ntp/python/src/ntp_module.py b/modules/test/ntp/python/src/ntp_module.py index 22fbf40ed..1a35d5dd5 100644 --- a/modules/test/ntp/python/src/ntp_module.py +++ b/modules/test/ntp/python/src/ntp_module.py @@ -14,6 +14,7 @@ """NTP test module""" from test_module import TestModule from scapy.all import rdpcap, IP, IPv6, NTP, UDP, Ether +from scapy.error import Scapy_Exception import os from collections import defaultdict @@ -185,8 +186,12 @@ def extract_ntp_data(self): # Read the pcap files packets = (rdpcap(self.startup_capture_file) + - rdpcap(self.monitor_capture_file) + - rdpcap(self.ntp_server_capture_file)) + rdpcap(self.monitor_capture_file)) + + try: + packets += rdpcap(self.ntp_server_capture_file) + except (FileNotFoundError, Scapy_Exception): + LOGGER.error('ntp.pcap not found or empty, ignoring') # Iterate through NTP packets for packet in packets: From c5e6bf6460b27ee77a72ccddb9da268cddf11c00 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 19 Dec 2024 11:27:36 +0000 Subject: [PATCH 2/2] Use in other tests too --- modules/test/ntp/python/src/ntp_module.py | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/modules/test/ntp/python/src/ntp_module.py b/modules/test/ntp/python/src/ntp_module.py index 1a35d5dd5..33729a8d1 100644 --- a/modules/test/ntp/python/src/ntp_module.py +++ b/modules/test/ntp/python/src/ntp_module.py @@ -243,9 +243,15 @@ def extract_ntp_data(self): def _ntp_network_ntp_support(self): LOGGER.info('Running ntp.network.ntp_support') - packet_capture = (rdpcap(STARTUP_CAPTURE_FILE) + - rdpcap(MONITOR_CAPTURE_FILE) + - rdpcap(NTP_SERVER_CAPTURE_FILE)) + + # Read the pcap files + packet_capture = (rdpcap(self.startup_capture_file) + + rdpcap(self.monitor_capture_file)) + + try: + packet_capture += rdpcap(self.ntp_server_capture_file) + except (FileNotFoundError, Scapy_Exception): + LOGGER.error('ntp.pcap not found or empty, ignoring') device_sends_ntp4 = False device_sends_ntp3 = False @@ -281,9 +287,15 @@ def _ntp_network_ntp_support(self): def _ntp_network_ntp_dhcp(self): LOGGER.info('Running ntp.network.ntp_dhcp') - packet_capture = (rdpcap(STARTUP_CAPTURE_FILE) + - rdpcap(MONITOR_CAPTURE_FILE) + - rdpcap(NTP_SERVER_CAPTURE_FILE)) + + # Read the pcap files + packet_capture = (rdpcap(self.startup_capture_file) + + rdpcap(self.monitor_capture_file)) + + try: + packet_capture += rdpcap(self.ntp_server_capture_file) + except (FileNotFoundError, Scapy_Exception): + LOGGER.error('ntp.pcap not found or empty, ignoring') device_sends_ntp = False ntp_to_local = False