From 4b4e1100d439ec71da01ee8dd1c285b8df8cb76e Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 17 Oct 2024 15:59:45 +0100 Subject: [PATCH 1/4] Fix error with DHCP server restore --- .../python/src/grpc_server/dhcp_leases.py | 11 +++--- .../python/src/grpc_server/dhcp_leases.py | 9 +++-- .../network/radius/bin/start_network_service | 2 +- modules/test/baseline/bin/start_test_module | 3 -- modules/test/conn/bin/start_test_module | 2 -- modules/test/conn/conf/module_config.json | 3 +- .../test/conn/python/src/connection_module.py | 36 ++++++++++++++----- modules/test/conn/python/src/dhcp_util.py | 6 +++- modules/test/dns/bin/start_test_module | 3 -- modules/test/ntp/bin/start_test_module | 3 -- modules/test/protocol/bin/start_test_module | 2 -- modules/test/services/bin/start_test_module | 3 -- modules/test/tls/bin/start_test_module | 3 -- testing/unit/report/report_compliant.json | 2 +- testing/unit/report/report_noncompliant.json | 2 +- 15 files changed, 46 insertions(+), 44 deletions(-) diff --git a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py index aa2945759..0a80b7002 100644 --- a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py @@ -57,19 +57,18 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] lease_list_raw = self._get_lease_list() - LOGGER.info('Raw Leases:\n' + str(lease_list_raw) + '\n') + LOGGER.info('Raw leases:\n' + str(lease_list_raw) + '\n') lease_list_start = lease_list_raw.find('=========', 0) - lease_list_start = lease_list_raw.find('\n', lease_list_start) - lease_list = lease_list_raw[lease_list_start + 1:] + lease_list_start = lease_list_raw.find('\n',lease_list_start) + lease_list = lease_list_raw[lease_list_start+1:] lines = lease_list.split('\n') for line in lines: try: lease = DHCPLease(line) leases.append(lease) - except Exception as e: # pylint: disable=W0718 + except Exception: # pylint: disable=W0718 # Let non lease lines file without extra checks - LOGGER.error('Making Lease Error: ' + str(e)) - LOGGER.error('Not a valid lease line: ' + line) + LOGGER.info('Not a valid lease line: ' + line) return leases def delete_lease(self, ip_addr): diff --git a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py index 08e6feabe..d3da4f3d5 100644 --- a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py @@ -57,8 +57,8 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] lease_list_raw = self._get_lease_list() - LOGGER.info('Raw Leases:\n' + str(lease_list_raw) + '\n') - lease_list_start = lease_list_raw.find('=========',0) + LOGGER.info('Raw leases:\n' + str(lease_list_raw) + '\n') + lease_list_start = lease_list_raw.find('=========', 0) lease_list_start = lease_list_raw.find('\n',lease_list_start) lease_list = lease_list_raw[lease_list_start+1:] lines = lease_list.split('\n') @@ -66,10 +66,9 @@ def get_leases(self): try: lease = DHCPLease(line) leases.append(lease) - except Exception as e: # pylint: disable=W0718 + except Exception: # pylint: disable=W0718 # Let non lease lines file without extra checks - LOGGER.error('Making Lease Error: ' + str(e)) - LOGGER.error('Not a valid lease line: ' + line) + LOGGER.info('Not a valid lease line: ' + line) return leases def delete_lease(self, ip_addr): diff --git a/modules/network/radius/bin/start_network_service b/modules/network/radius/bin/start_network_service index d285c20d9..aad840c3a 100644 --- a/modules/network/radius/bin/start_network_service +++ b/modules/network/radius/bin/start_network_service @@ -27,7 +27,7 @@ cp $CONF_DIR/ca.crt /etc/ssl/certs/ca-certificates.crt python3 -u $PYTHON_SRC_DIR/authenticator.py & -#Create and set permissions on the log file +# Create and set permissions on the log file touch $LOG_FILE chown $HOST_USER $LOG_FILE diff --git a/modules/test/baseline/bin/start_test_module b/modules/test/baseline/bin/start_test_module index a529c2fcf..c3209261a 100644 --- a/modules/test/baseline/bin/start_test_module +++ b/modules/test/baseline/bin/start_test_module @@ -41,11 +41,8 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python scrip that will execute the tests for this module diff --git a/modules/test/conn/bin/start_test_module b/modules/test/conn/bin/start_test_module index d85ae7d6b..4cdba0ae9 100644 --- a/modules/test/conn/bin/start_test_module +++ b/modules/test/conn/bin/start_test_module @@ -40,9 +40,7 @@ fi # Create and set permissions on the log files LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python script that will execute the tests for this module diff --git a/modules/test/conn/conf/module_config.json b/modules/test/conn/conf/module_config.json index ca386a5e4..2f5ea7149 100644 --- a/modules/test/conn/conf/module_config.json +++ b/modules/test/conn/conf/module_config.json @@ -44,7 +44,8 @@ "expected_behavior": "The device is not setup with a static IP address. The device accepts an IP address from a DHCP server (RFC 2131) and responds succesfully to an ICMP echo (ping) request.", "recommendations": [ "Enable DHCP", - "Install a DHCP client" + "Install a DHCP client", + "Ensure that your DHCP client renews its lease at the correct time" ] }, { diff --git a/modules/test/conn/python/src/connection_module.py b/modules/test/conn/python/src/connection_module.py index 867d8a3ff..516a83f8f 100644 --- a/modules/test/conn/python/src/connection_module.py +++ b/modules/test/conn/python/src/connection_module.py @@ -146,7 +146,7 @@ def _connection_switch_arp_inspection(self): if no_arp: return None, 'No ARP packets from the device found' - return True, 'Device uses ARP' + return True, 'Device uses ARP correctly' def _connection_switch_dhcp_snooping(self): LOGGER.info('Running connection.switch.dhcp_snooping') @@ -204,8 +204,10 @@ def _connection_dhcp_address(self): LOGGER.info('No IP information found in lease: ' + self._device_mac) return False, 'No IP information found in lease: ' + self._device_mac else: - LOGGER.info('No DHCP lease could be found: ' + self._device_mac) - return False, 'No DHCP lease could be found: ' + self._device_mac + LOGGER.info('No DHCP lease could be found for MAC ' + self._device_mac + + ' at the time of this test') + return (False, 'No DHCP lease could be found for MAC ' + + self._device_mac + ' at the time of this test') def _connection_mac_address(self): LOGGER.info('Running connection.mac_address') @@ -323,8 +325,10 @@ def _connection_ipaddr_ip_change(self, config): else: result = None, 'Failed to create reserved lease for device' else: - LOGGER.info('Device has no current DHCP lease') - result = None, 'Device has no current DHCP lease' + LOGGER.info('Device has no current DHCP lease so ' + + 'this test could not be run') + result = None, ('Device has no current DHCP lease so ' + + 'this test could not be run') # Restore the network self._dhcp_util.restore_failover_dhcp_server() LOGGER.info('Waiting 30 seconds for reserved lease to expire') @@ -377,7 +381,8 @@ def _connection_ipaddr_dhcp_failover(self, config): else: result = False, 'Device did not respond to ping' else: - result = None, 'Device has no current DHCP lease' + result = (None, + 'Device has no current DHCP lease so this test could not be run') else: LOGGER.error('Network is not ready for this test. Skipping') result = None, 'Network is not ready for this test' @@ -683,6 +688,7 @@ def is_ip_in_range(self, ip, start_ip, end_ip): return start_int <= ip_int <= end_int def _run_subnet_test(self, config): + # Resolve the configured dhcp subnet ranges ranges = None if 'ranges' in config: @@ -697,6 +703,7 @@ def _run_subnet_test(self, config): response = self.dhcp1_client.get_dhcp_range() cur_range = {} + if response.code == 200: cur_range['start'] = response.start cur_range['end'] = response.end @@ -709,16 +716,20 @@ def _run_subnet_test(self, config): results = [] dhcp_setup = self.setup_single_dhcp_server() + if dhcp_setup[0]: LOGGER.info(dhcp_setup[1]) lease = self._dhcp_util.get_cur_lease(mac_address=self._device_mac, timeout=self._lease_wait_time_sec) + if lease is not None: if self._dhcp_util.is_lease_active(lease): results = self.test_subnets(ranges) else: - LOGGER.info('Failed to confirm a valid active lease for the device') - return None, 'Failed to confirm a valid active lease for the device' + LOGGER.info('Device has no current DHCP lease ' + + 'so this test could not be run') + return (None, + 'Device has no current DHCP lease so this test could not be run') else: LOGGER.error(dhcp_setup[1]) return None, 'Failed to setup DHCP server for test' @@ -745,10 +756,17 @@ def _run_subnet_test(self, config): # Wait for the current lease to expire lease = self._dhcp_util.get_cur_lease(mac_address=self._device_mac, timeout=self._lease_wait_time_sec) - self._dhcp_util.wait_for_lease_expire(lease, self._lease_wait_time_sec) + + # Check if lease is active + if lease is not None: + self._dhcp_util.wait_for_lease_expire(lease, self._lease_wait_time_sec) + else: + # If not, wait for 30 seconds as a fallback + time.sleep(30) # Wait for a new lease to be provided before exiting test # to prevent other test modules from failing + LOGGER.info('Checking for new lease') # Subnet changes tend to take longer to pick up so we'll allow # for twice the lease wait time diff --git a/modules/test/conn/python/src/dhcp_util.py b/modules/test/conn/python/src/dhcp_util.py index 3654d0401..70195537a 100644 --- a/modules/test/conn/python/src/dhcp_util.py +++ b/modules/test/conn/python/src/dhcp_util.py @@ -256,16 +256,20 @@ def setup_single_dhcp_server(self): return False def wait_for_lease_expire(self, lease, max_wait_time=30): + expiration_utc = datetime.strptime(lease['expires'], '%Y-%m-%d %H:%M:%S') - # lease information stored in UTC so we need to convert to local time + + # Lease information stored in UTC so we need to convert to local time expiration = self.utc_to_local(expiration_utc) time_to_expire = expiration - datetime.now(tz=tz.tzlocal()) + # Wait until the expiration time and padd 5 seconds # If wait time is longer than max_wait_time, only wait # for the max wait time wait_time = min(max_wait_time, time_to_expire.total_seconds() + 5) if time_to_expire.total_seconds() > 0 else 0 + LOGGER.info('Time until lease expiration: ' + str(wait_time)) LOGGER.info('Waiting for current lease to expire: ' + str(expiration)) if wait_time > 0: diff --git a/modules/test/dns/bin/start_test_module b/modules/test/dns/bin/start_test_module index a529c2fcf..c3209261a 100644 --- a/modules/test/dns/bin/start_test_module +++ b/modules/test/dns/bin/start_test_module @@ -41,11 +41,8 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python scrip that will execute the tests for this module diff --git a/modules/test/ntp/bin/start_test_module b/modules/test/ntp/bin/start_test_module index a09349cf9..33b2881f4 100644 --- a/modules/test/ntp/bin/start_test_module +++ b/modules/test/ntp/bin/start_test_module @@ -27,11 +27,8 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python scrip that will execute the tests for this module diff --git a/modules/test/protocol/bin/start_test_module b/modules/test/protocol/bin/start_test_module index d85ae7d6b..646d00270 100644 --- a/modules/test/protocol/bin/start_test_module +++ b/modules/test/protocol/bin/start_test_module @@ -38,9 +38,7 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE diff --git a/modules/test/services/bin/start_test_module b/modules/test/services/bin/start_test_module index d8cede486..a42ee4cf0 100644 --- a/modules/test/services/bin/start_test_module +++ b/modules/test/services/bin/start_test_module @@ -41,11 +41,8 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python scrip that will execute the tests for this module diff --git a/modules/test/tls/bin/start_test_module b/modules/test/tls/bin/start_test_module index d8cede486..a42ee4cf0 100644 --- a/modules/test/tls/bin/start_test_module +++ b/modules/test/tls/bin/start_test_module @@ -41,11 +41,8 @@ else fi # Create and set permissions on the log files -LOG_FILE=/runtime/output/$MODULE_NAME.log RESULT_FILE=/runtime/output/$MODULE_NAME-result.json -touch $LOG_FILE touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python scrip that will execute the tests for this module diff --git a/testing/unit/report/report_compliant.json b/testing/unit/report/report_compliant.json index 17e994d20..08ff585ad 100644 --- a/testing/unit/report/report_compliant.json +++ b/testing/unit/report/report_compliant.json @@ -68,7 +68,7 @@ }, { "name": "connection.switch.arp_inspection", - "description": "Device uses ARP", + "description": "Device uses ARP correctly", "expected_behavior": "Device continues to operate correctly when ARP inspection is enabled on the switch. No functionality is lost with ARP inspection enabled.", "required_result": "Required", "result": "Compliant" diff --git a/testing/unit/report/report_noncompliant.json b/testing/unit/report/report_noncompliant.json index 98fbeb284..b3ba74c0d 100644 --- a/testing/unit/report/report_noncompliant.json +++ b/testing/unit/report/report_noncompliant.json @@ -77,7 +77,7 @@ }, { "name": "connection.switch.arp_inspection", - "description": "Device uses ARP", + "description": "Device uses ARP correctly", "expected_behavior": "Device continues to operate correctly when ARP inspection is enabled on the switch. No functionality is lost with ARP inspection enabled.", "required_result": "Required", "result": "Compliant" From b981a74ca84acb4a1dfd99e64ee5fc53183fd891 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 17 Oct 2024 16:33:20 +0100 Subject: [PATCH 2/4] Remove log dir for test modules --- modules/test/base/python/src/test_module.py | 11 +++-------- modules/test/conn/python/src/connection_module.py | 2 -- modules/test/dns/python/src/dns_module.py | 2 -- modules/test/ntp/python/src/ntp_module.py | 2 -- modules/test/protocol/bin/start_test_module | 1 - modules/test/protocol/python/src/protocol_module.py | 2 +- modules/test/protocol/python/src/run.py | 2 +- modules/test/services/python/src/services_module.py | 2 -- modules/test/tls/python/src/tls_module.py | 2 -- testing/unit/conn/conn_module_test.py | 1 - testing/unit/dns/dns_module_test.py | 2 -- testing/unit/ntp/ntp_module_test.py | 2 -- testing/unit/services/services_module_test.py | 2 -- testing/unit/tls/tls_module_test.py | 3 --- 14 files changed, 5 insertions(+), 31 deletions(-) diff --git a/modules/test/base/python/src/test_module.py b/modules/test/base/python/src/test_module.py index 1487fb786..6b0170ba4 100644 --- a/modules/test/base/python/src/test_module.py +++ b/modules/test/base/python/src/test_module.py @@ -32,7 +32,6 @@ class TestModule: def __init__(self, module_name, log_name, - log_dir=None, conf_file=CONF_FILE, results_dir=RESULTS_DIR): self._module_name = module_name @@ -42,19 +41,15 @@ def __init__(self, self._ipv4_subnet = os.environ.get('IPV4_SUBNET', '') self._ipv6_subnet = os.environ.get('IPV6_SUBNET', '') self._dev_iface_mac = os.environ.get('DEV_IFACE_MAC', '') - self._add_logger(log_name=log_name, - module_name=module_name, - log_dir=log_dir) + self._add_logger(log_name=log_name) self._config = self._read_config( conf_file=conf_file if conf_file is not None else CONF_FILE) self._device_ipv4_addr = None self._device_ipv6_addr = None - def _add_logger(self, log_name, module_name, log_dir=None): + def _add_logger(self, log_name): global LOGGER - LOGGER = logger.get_logger(name=log_name, # pylint: disable=E1123 - log_file=module_name, - log_dir=log_dir) + LOGGER = logger.get_logger(name=log_name) def generate_module_report(self): pass diff --git a/modules/test/conn/python/src/connection_module.py b/modules/test/conn/python/src/connection_module.py index 516a83f8f..13ebaaf04 100644 --- a/modules/test/conn/python/src/connection_module.py +++ b/modules/test/conn/python/src/connection_module.py @@ -43,7 +43,6 @@ class ConnectionModule(TestModule): def __init__(self, module, - log_dir=None, conf_file=None, results_dir=None, startup_capture_file=STARTUP_CAPTURE_FILE, @@ -51,7 +50,6 @@ def __init__(self, super().__init__(module_name=module, log_name=LOG_NAME, - log_dir=log_dir, conf_file=conf_file, results_dir=results_dir) global LOGGER diff --git a/modules/test/dns/python/src/dns_module.py b/modules/test/dns/python/src/dns_module.py index 9aac9374d..9dd1de951 100644 --- a/modules/test/dns/python/src/dns_module.py +++ b/modules/test/dns/python/src/dns_module.py @@ -31,7 +31,6 @@ class DNSModule(TestModule): def __init__(self, module, - log_dir=None, conf_file=None, results_dir=None, dns_server_capture_file=DNS_SERVER_CAPTURE_FILE, @@ -39,7 +38,6 @@ def __init__(self, monitor_capture_file=MONITOR_CAPTURE_FILE): super().__init__(module_name=module, log_name=LOG_NAME, - log_dir=log_dir, conf_file=conf_file, results_dir=results_dir) self.dns_server_capture_file = dns_server_capture_file diff --git a/modules/test/ntp/python/src/ntp_module.py b/modules/test/ntp/python/src/ntp_module.py index f82240ff1..67e2a3c92 100644 --- a/modules/test/ntp/python/src/ntp_module.py +++ b/modules/test/ntp/python/src/ntp_module.py @@ -30,7 +30,6 @@ class NTPModule(TestModule): def __init__(self, module, - log_dir=None, conf_file=None, results_dir=None, ntp_server_capture_file=NTP_SERVER_CAPTURE_FILE, @@ -38,7 +37,6 @@ def __init__(self, monitor_capture_file=MONITOR_CAPTURE_FILE): super().__init__(module_name=module, log_name=LOG_NAME, - log_dir=log_dir, conf_file=conf_file, results_dir=results_dir) self.ntp_server_capture_file = ntp_server_capture_file diff --git a/modules/test/protocol/bin/start_test_module b/modules/test/protocol/bin/start_test_module index 646d00270..e51fdb7ed 100644 --- a/modules/test/protocol/bin/start_test_module +++ b/modules/test/protocol/bin/start_test_module @@ -40,7 +40,6 @@ fi # Create and set permissions on the log files RESULT_FILE=/runtime/output/$MODULE_NAME-result.json touch $RESULT_FILE -chown $HOST_USER $LOG_FILE chown $HOST_USER $RESULT_FILE # Run the python script that will execute the tests for this module diff --git a/modules/test/protocol/python/src/protocol_module.py b/modules/test/protocol/python/src/protocol_module.py index 4f7c1a7e7..9d99c91bd 100644 --- a/modules/test/protocol/python/src/protocol_module.py +++ b/modules/test/protocol/python/src/protocol_module.py @@ -22,7 +22,7 @@ class ProtocolModule(TestModule): - """Protocol Test module""" + """Protocol test module""" def __init__(self, module): self._supports_bacnet = False diff --git a/modules/test/protocol/python/src/run.py b/modules/test/protocol/python/src/run.py index d47c81cb6..a2788c833 100644 --- a/modules/test/protocol/python/src/run.py +++ b/modules/test/protocol/python/src/run.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Run Baseline module""" +"""Run protocol module""" import argparse import signal import sys diff --git a/modules/test/services/python/src/services_module.py b/modules/test/services/python/src/services_module.py index a96d47bc0..094eb8eb5 100644 --- a/modules/test/services/python/src/services_module.py +++ b/modules/test/services/python/src/services_module.py @@ -31,14 +31,12 @@ class ServicesModule(TestModule): def __init__(self, module, - log_dir=None, conf_file=None, results_dir=None, run=True, nmap_scan_results_path=None): super().__init__(module_name=module, log_name=LOG_NAME, - log_dir=log_dir, conf_file=conf_file, results_dir=results_dir) self._scan_tcp_results = None diff --git a/modules/test/tls/python/src/tls_module.py b/modules/test/tls/python/src/tls_module.py index 186766b17..89882ab84 100644 --- a/modules/test/tls/python/src/tls_module.py +++ b/modules/test/tls/python/src/tls_module.py @@ -32,7 +32,6 @@ class TLSModule(TestModule): def __init__(self, module, - log_dir=None, conf_file=None, results_dir=None, startup_capture_file=STARTUP_CAPTURE_FILE, @@ -40,7 +39,6 @@ def __init__(self, tls_capture_file=TLS_CAPTURE_FILE): super().__init__(module_name=module, log_name=LOG_NAME, - log_dir=log_dir, conf_file=conf_file, results_dir=results_dir) self.startup_capture_file = startup_capture_file diff --git a/testing/unit/conn/conn_module_test.py b/testing/unit/conn/conn_module_test.py index 0687fc1a6..f53490d7f 100644 --- a/testing/unit/conn/conn_module_test.py +++ b/testing/unit/conn/conn_module_test.py @@ -133,7 +133,6 @@ def connection_port_speed_autonegotiation_fail_test(self): def connection_switch_dhcp_snooping_icmp_test(self): LOGGER.info('connection_switch_dhcp_snooping_icmp_test') conn_module = ConnectionModule(module=MODULE, - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, startup_capture_file=STARTUP_CAPTURE_FILE, monitor_capture_file=MONITOR_CAPTURE_FILE) diff --git a/testing/unit/dns/dns_module_test.py b/testing/unit/dns/dns_module_test.py index 5c100cbf9..d530498dd 100644 --- a/testing/unit/dns/dns_module_test.py +++ b/testing/unit/dns/dns_module_test.py @@ -49,7 +49,6 @@ def setUpClass(cls): # Test the module report generation def dns_module_report_test(self): dns_module = DNSModule(module=MODULE, - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, dns_server_capture_file=DNS_SERVER_CAPTURE_FILE, startup_capture_file=STARTUP_CAPTURE_FILE, @@ -98,7 +97,6 @@ def dns_module_report_no_dns_test(self): wrpcap(monitor_cap_file, packets_monitor) dns_module = DNSModule(module='dns', - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, dns_server_capture_file=dns_server_cap_file, startup_capture_file=startup_cap_file, diff --git a/testing/unit/ntp/ntp_module_test.py b/testing/unit/ntp/ntp_module_test.py index af74722f1..ed5934048 100644 --- a/testing/unit/ntp/ntp_module_test.py +++ b/testing/unit/ntp/ntp_module_test.py @@ -47,7 +47,6 @@ def setUpClass(cls): # Test the module report generation def ntp_module_report_test(self): ntp_module = NTPModule(module=MODULE, - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, ntp_server_capture_file=NTP_SERVER_CAPTURE_FILE, startup_capture_file=STARTUP_CAPTURE_FILE, @@ -96,7 +95,6 @@ def ntp_module_report_no_ntp_test(self): wrpcap(monitor_cap_file, packets_monitor) ntp_module = NTPModule(module='dns', - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, ntp_server_capture_file=ntp_server_cap_file, startup_capture_file=startup_cap_file, diff --git a/testing/unit/services/services_module_test.py b/testing/unit/services/services_module_test.py index 08091e452..ccd4b730e 100644 --- a/testing/unit/services/services_module_test.py +++ b/testing/unit/services/services_module_test.py @@ -49,7 +49,6 @@ def services_module_ports_open_report_test(self): shutil.copy(src_scan_results_path, dst_scan_results_path) services_module = ServicesModule(module=MODULE, - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, run=False, nmap_scan_results_path=OUTPUT_DIR) @@ -75,7 +74,6 @@ def services_module_report_all_closed_test(self): shutil.copy(src_scan_results_path, dst_scan_results_path) services_module = ServicesModule(module=MODULE, - log_dir=OUTPUT_DIR, results_dir=OUTPUT_DIR, run=False, nmap_scan_results_path=OUTPUT_DIR) diff --git a/testing/unit/tls/tls_module_test.py b/testing/unit/tls/tls_module_test.py index fc37ade40..fc7153aef 100644 --- a/testing/unit/tls/tls_module_test.py +++ b/testing/unit/tls/tls_module_test.py @@ -325,7 +325,6 @@ def security_tls_client_allowed_protocols_test(self): # os.environ['DEVICE_MAC'] = '38:d1:35:01:17:fe' # pcap_file = os.path.join(CAPTURES_DIR, 'tls.pcap') # tls = TLSModule(module=MODULE, - # log_dir=OUTPUT_DIR, # conf_file=CONF_FILE, # results_dir=OUTPUT_DIR, # startup_capture_file=pcap_file, @@ -348,7 +347,6 @@ def security_tls_client_allowed_protocols_test(self): # os.environ['DEVICE_MAC'] = '28:29:86:27:d6:05' # pcap_file = os.path.join(CAPTURES_DIR, 'tls_ext.pcap') # tls = TLSModule(module=MODULE, - # log_dir=OUTPUT_DIR, # conf_file=CONF_FILE, # results_dir=OUTPUT_DIR, # startup_capture_file=pcap_file, @@ -372,7 +370,6 @@ def security_tls_client_allowed_protocols_test(self): # os.environ['DEVICE_MAC'] = '' # pcap_file = os.path.join(CAPTURES_DIR, 'tls_ext.pcap') # tls = TLSModule(module=MODULE, - # log_dir=OUTPUT_DIR, # conf_file=CONF_FILE, # results_dir=OUTPUT_DIR, # startup_capture_file=pcap_file, From 1b48a4f94bfa7e310e2ed8c2b5f16ce008ba0010 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Thu, 17 Oct 2024 17:12:38 +0100 Subject: [PATCH 3/4] Change get leases method --- .../dhcp-1/python/src/grpc_server/dhcp_leases.py | 12 +++++++----- .../dhcp-2/python/src/grpc_server/dhcp_leases.py | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py index 0a80b7002..3ae73eb63 100644 --- a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py @@ -56,13 +56,15 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] - lease_list_raw = self._get_lease_list() - LOGGER.info('Raw leases:\n' + str(lease_list_raw) + '\n') - lease_list_start = lease_list_raw.find('=========', 0) - lease_list_start = lease_list_raw.find('\n',lease_list_start) - lease_list = lease_list_raw[lease_list_start+1:] + lease_list = self._get_lease_list() + LOGGER.info('Raw leases:\n' + str(lease_list) + '\n') lines = lease_list.split('\n') for line in lines: + + # Ignore non-lease lines + if line.contains('Reading leases from') or line.contains('==='): + continue + try: lease = DHCPLease(line) leases.append(lease) diff --git a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py index d3da4f3d5..9ef0901a6 100644 --- a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py @@ -56,13 +56,15 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] - lease_list_raw = self._get_lease_list() - LOGGER.info('Raw leases:\n' + str(lease_list_raw) + '\n') - lease_list_start = lease_list_raw.find('=========', 0) - lease_list_start = lease_list_raw.find('\n',lease_list_start) - lease_list = lease_list_raw[lease_list_start+1:] + lease_list = self._get_lease_list() + LOGGER.info('Raw leases:\n' + str(lease_list) + '\n') lines = lease_list.split('\n') for line in lines: + + # Ignore non-lease lines + if line.contains('Reading leases from') or line.contains('==='): + continue + try: lease = DHCPLease(line) leases.append(lease) From 72b5488e68402b51deaed5fb49a63538dd27cd99 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 18 Oct 2024 13:55:53 +0100 Subject: [PATCH 4/4] Revert removal of error print --- .../dhcp-1/python/src/grpc_server/dhcp_leases.py | 15 +++++++-------- .../dhcp-2/python/src/grpc_server/dhcp_leases.py | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py index 3ae73eb63..e2318ac02 100644 --- a/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py @@ -56,21 +56,20 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] - lease_list = self._get_lease_list() - LOGGER.info('Raw leases:\n' + str(lease_list) + '\n') + lease_list_raw = self._get_lease_list() + LOGGER.info('Raw Leases:\n' + str(lease_list_raw) + '\n') + lease_list_start = lease_list_raw.find('=========', 0) + lease_list_start = lease_list_raw.find('\n', lease_list_start) + lease_list = lease_list_raw[lease_list_start + 1:] lines = lease_list.split('\n') for line in lines: - - # Ignore non-lease lines - if line.contains('Reading leases from') or line.contains('==='): - continue - try: lease = DHCPLease(line) leases.append(lease) - except Exception: # pylint: disable=W0718 + except Exception as e: # pylint: disable=W0718 # Let non lease lines file without extra checks LOGGER.info('Not a valid lease line: ' + line) + LOGGER.error('Get lease error: ' + str(e)) return leases def delete_lease(self, ip_addr): diff --git a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py index 9ef0901a6..f6db83094 100644 --- a/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py +++ b/modules/network/dhcp-2/python/src/grpc_server/dhcp_leases.py @@ -56,21 +56,20 @@ def get_lease(self, hw_addr): def get_leases(self): leases = [] - lease_list = self._get_lease_list() - LOGGER.info('Raw leases:\n' + str(lease_list) + '\n') + lease_list_raw = self._get_lease_list() + LOGGER.info('Raw Leases:\n' + str(lease_list_raw) + '\n') + lease_list_start = lease_list_raw.find('=========', 0) + lease_list_start = lease_list_raw.find('\n', lease_list_start) + lease_list = lease_list_raw[lease_list_start + 1:] lines = lease_list.split('\n') for line in lines: - - # Ignore non-lease lines - if line.contains('Reading leases from') or line.contains('==='): - continue - try: lease = DHCPLease(line) leases.append(lease) - except Exception: # pylint: disable=W0718 + except Exception as e: # pylint: disable=W0718 # Let non lease lines file without extra checks LOGGER.info('Not a valid lease line: ' + line) + LOGGER.error('Get lease error: ' + str(e)) return leases def delete_lease(self, ip_addr):