From 0a4b3f9204ec93be22dc25960679058d8bdcb065 Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 9 Feb 2024 08:39:43 +0000 Subject: [PATCH 1/3] Re-enable protocol tests --- modules/test/protocol/conf/module_config.json | 6 ++--- .../protocol/python/src/protocol_bacnet.py | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/modules/test/protocol/conf/module_config.json b/modules/test/protocol/conf/module_config.json index 0fa83afb8..a51a3603b 100644 --- a/modules/test/protocol/conf/module_config.json +++ b/modules/test/protocol/conf/module_config.json @@ -1,6 +1,6 @@ { "config": { - "enabled": false, + "enabled": true, "meta": { "name": "protocol", "display_name": "Protocol", @@ -17,13 +17,13 @@ "name": "protocol.valid_bacnet", "test_description": "Can valid BACnet traffic be seen", "expected_behavior": "BACnet traffic can be seen on the network and packets are valid and not malformed", - "required_result": "Required" + "required_result": "Recommended" }, { "name": "protocol.valid_modbus", "test_description": "Can valid Modbus traffic be seen", "expected_behavior": "Any Modbus functionality works as expected and valid modbus traffic can be observed", - "required_result": "Required", + "required_result": "Recommended", "config":{ "port": 502, "device_id": 1, diff --git a/modules/test/protocol/python/src/protocol_bacnet.py b/modules/test/protocol/python/src/protocol_bacnet.py index 557dcdfb9..c23061c51 100644 --- a/modules/test/protocol/python/src/protocol_bacnet.py +++ b/modules/test/protocol/python/src/protocol_bacnet.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -"""Module run all the BACnet related methods for testing""" +"""Module to run all the BACnet related methods for testing""" import BAC0 import logging @@ -28,39 +28,41 @@ def __init__(self, log): LOGGER = log # Setup the BAC0 Log - BAC0.log_level(log_file=logging.DEBUG, stdout=logging.INFO, stderr=logging.CRITICAL) - + BAC0.log_level(log_file=logging.DEBUG, + stdout=logging.INFO, + stderr=logging.CRITICAL) + self.devices = [] def discover(self, local_ip=None): - LOGGER.info("Performing BACnet discovery...") + LOGGER.info('Performing BACnet discovery...') bacnet = BAC0.lite(local_ip) - LOGGER.info("Local BACnet object: " + str(bacnet)) + LOGGER.info('Local BACnet object: ' + str(bacnet)) try: bacnet.discover(global_broadcast=True) except Exception as e: LOGGER.error(e) - LOGGER.info("BACnet discovery complete") + LOGGER.info('BACnet discovery complete') with open(BAC0_LOG,'r',encoding='utf-8') as f: bac0_log = f.read() - LOGGER.info("BAC0 Log:\n" + bac0_log) + LOGGER.info('BAC0 Log:\n' + bac0_log) self.devices = bacnet.devices # Check if the device being tested is in the discovered devices list def validate_device(self, local_ip, device_ip): result = None - LOGGER.info("Validating BACnet device: " + device_ip) + LOGGER.info('Validating BACnet device: ' + device_ip) self.discover(local_ip + '/24') - LOGGER.info("BACnet Devices Found: " + str(len(self.devices))) + LOGGER.info('BACnet Devices Found: ' + str(len(self.devices))) if len(self.devices) > 0: # Load a fail result initially and pass only # if we can validate it's the right device responding result = False, ( - f'Could not confirm discovered BACnet device is the ' + + 'Could not confirm discovered BACnet device is the ' + 'same as device being tested') for device in self.devices: - name, vendor, address, device_id = device - LOGGER.info("Checking Device: " + str(device)) + address = device[2] + LOGGER.info('Checking device: ' + str(device)) if device_ip in address: result = True, 'Device IP matches discovered device' break From bba91e8c491828b623bf9dd03fc47f359761d3f3 Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Wed, 28 Feb 2024 09:58:39 -0700 Subject: [PATCH 2/3] Reorder protocol module run order --- framework/python/src/test_orc/test_orchestrator.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/python/src/test_orc/test_orchestrator.py b/framework/python/src/test_orc/test_orchestrator.py index a81fca4fd..311e57316 100644 --- a/framework/python/src/test_orc/test_orchestrator.py +++ b/framework/python/src/test_orc/test_orchestrator.py @@ -462,7 +462,14 @@ def _load_test_modules(self): loaded_modules = "Loaded the following test modules: " test_modules_dir = os.path.join(self._path, TEST_MODULES_DIR) - for module_dir in os.listdir(test_modules_dir): + module_dirs = os.listdir(test_modules_dir) + # Check if the directory protocol exists and move it to the beginning + # protocol should always be run first so BACnet binding doesn't get + # corrupted during DHCP changes in the conn module + if 'protocol' in module_dirs: + module_dirs.insert(0, module_dirs.pop(module_dirs.index('protocol'))) + + for module_dir in module_dirs: if self._get_test_module(module_dir) is None: loaded_module = self._load_test_module(module_dir) From 0d299bad884bf24f00994257a059c005fced835a Mon Sep 17 00:00:00 2001 From: jhughesbiot Date: Thu, 29 Feb 2024 14:04:42 -0700 Subject: [PATCH 3/3] Add protocol display name to report --- framework/python/src/common/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/python/src/common/util.py b/framework/python/src/common/util.py index ebc3d3d70..d40571481 100644 --- a/framework/python/src/common/util.py +++ b/framework/python/src/common/util.py @@ -103,7 +103,8 @@ def get_module_display_name(search): 'dns': 'DNS', 'connection': 'Connection', 'nmap': 'Services', - 'tls': 'TLS' + 'tls': 'TLS', + 'protocol': 'Protocol' } for module in modules.items():