Introduce create_firewall_mapping Function to Fix Firewall Object Mapping #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a dedicated function,
create_firewall_mapping
, designed to accurately map firewall hostnames to their corresponding Firewall objects and details. The new function replaces the previous use of zip in the batch subcommand, which led to issues with firewall objects not being properly associated with their details due to misalignment in the lists.Problem
The existing implementation used
zip(all_firewalls, firewalls_info)
to combine lists of Firewall objects and their information. However, this approach assumed that the order and length of both lists would always align, which was not guaranteed, especially after introducing multithreading for fetching firewall information. This led to incorrect mappings, where firewall details were associated with the wrong Firewall objects.Solution
To address this issue, we implemented the create_firewall_mapping function. This function constructs a dictionary where each key is a firewall hostname, and the value is another dictionary containing the corresponding Firewall object and its detailed information. The mapping is based on the serial number of the firewalls, ensuring that the details are correctly associated even if the order of objects or information changes.
Benefits
Changes Made:
create_firewall_mapping
function.create_firewall_mapping
.Testing
Added unit tests for the
create_firewall_mapping
function to cover various scenarios, including mismatched lists and missing items.Manually tested the batch subcommand to ensure that firewall details are correctly associated with their Firewall objects.
This change resolves the issue of incorrect firewall object mapping and improves the overall robustness and maintainability of the script.