cdot65 / pan-os-upgrade

An efficient tool to execute configuration backups, network state snapshots, system readiness checks, and operating system upgrades of Palo Alto Networks firewalls and Panorama appliances.
https://cdot65.github.io/pan-os-upgrade/
Apache License 2.0
39 stars 7 forks source link

Introduce create_firewall_mapping Function to Fix Firewall Object Mapping #86

Closed cdot65 closed 6 months ago

cdot65 commented 6 months ago

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:

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.

cdot65 commented 6 months ago

Whoops, I accidentally pushed my changes into main instead of this branch. Check out commit #1595fbab1a7b60024579bb42d0cb74be15a33f2b