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

Erroring out when trying to the upgrade of the firewalls #136

Open d945028 opened 3 months ago

d945028 commented 3 months ago

Describe the bug A clear and concise description of what the bug is. The Error message is a 'TypeError: 'NoneType' object does not support the context manager protocol'.

To Reproduce Steps to reproduce the behavior:

  1. Go to folder for the repo pan-os-upgrade
  2. Run the command ' pan-os-upgrade firewall'
  3. Enter the firewall details
  4. See error: TypeError: 'NoneType' object does not support the context manager protocol

Expected behavior The script should successfully upgrade the firewall to the target OS version

Screenshots and text from the script: [admin@spopvcladcaph01 pan-os-upgrade]$ pan-os-upgrade firewall Firewall hostname or IP: 10.52.184.49 Firewall username: axxxx Firewall password: Target version: 10.2.6-h1 Dry Run? [Y/n]: Y

Welcome to the PAN-OS upgrade tool

This script software is provided on an 'as-is' basis with no warranties, and no support provided.

The selected firewall subcommand will upgrade a single Firewall appliance.

Settings: No settings.yaml file was found, default values will be used. You can create a settings.yaml file with 'pan-os-upgrade settings' command.

🚀 10.52.184.49: Connection to the appliance successful. 📝 N1122322R-exh-pan-b: 015354000084294 10.52.184.49 📝 N1122322R-exh-pan-b: HA mode: passive 📝 N1122322R-exh-pan-b: Local state: passive, Local version: 10.1.10, Peer version: 10.1.10 ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/admin/.local/lib/python3.11/site-packages/pan_os_upgrade/main.py:245 in firewall │ │ │ │ 242 │ ) │ │ 243 │ │ │ 244 │ # Perform upgrade │ │ ❱ 245 │ upgrade_firewall( │ │ 246 │ │ dry_run=dry_run, │ │ 247 │ │ firewall=device, │ │ 248 │ │ settings_file=SETTINGS_FILE, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ banner = '\x1b[1;33m===============================================================… │ │ │ │ device = <Firewall '015354000084294' None at 0x7f3ea7894a10> │ │ │ │ dry_run = True │ │ │ │ hostname = '10.52.184.49' │ │ │ │ password = 'IPvas2.0' │ │ │ │ target_version = '10.2.6-h1' │ │ │ │ username = 'admin' │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/admin/.local/lib/python3.11/site-packages/pan_os_upgrade/components/upgrade.py:669 in │ │ upgrade_firewall │ │ │ │ 666 │ │ │ 667 │ # If firewall is part of HA pair, determine if it's active or passive │ │ 668 │ if ha_details: │ │ ❱ 669 │ │ proceed_with_upgrade, peer_firewall = handle_firewall_ha( │ │ 670 │ │ │ dry_run=dry_run, │ │ 671 │ │ │ hostname=hostname, │ │ 672 │ │ │ settings_file=settings_file, │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ deploy_info = 'passive' │ │ │ │ dry_run = True │ │ │ │ firewall = <Firewall '015354000084294' None at 0x7f3ea7894a10> │ │ │ │ firewall_details = <SystemSettings 0x7f3ea78a2d50> │ │ │ │ ha_details = { │ │ │ │ │ 'result': { │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ 'group': { │ │ │ │ │ │ │ 'mode': 'Active-Passive', │ │ │ │ │ │ │ 'local-info': { │ │ │ │ │ │ │ │ 'url-compat': 'Match', │ │ │ │ │ │ │ │ 'app-version': '8811-8573', │ │ │ │ │ │ │ │ 'gpclient-version': 'Not Installed', │ │ │ │ │ │ │ │ 'build-rel': '10.1.10', │ │ │ │ │ │ │ │ 'ha2-port': 'ethernet1/5', │ │ │ │ │ │ │ │ 'av-version': '0', │ │ │ │ │ │ │ │ 'url-version': '0000.00.00.000', │ │ │ │ │ │ │ │ 'ha1-backup-ipaddr': '192.168.10.12/29', │ │ │ │ │ │ │ │ 'active-passive': { │ │ │ │ │ │ │ │ │ 'passive-link-state': 'auto', │ │ │ │ │ │ │ │ │ 'monitor-fail-holddown': '1' │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ 'platform-model': 'PA-VM', │ │ │ │ │ │ │ │ ... +49 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'peer-info': { │ │ │ │ │ │ │ │ 'app-version': '8811-8573', │ │ │ │ │ │ │ │ 'gpclient-version': 'Not Installed', │ │ │ │ │ │ │ │ 'VMS': '2.1.10', │ │ │ │ │ │ │ │ 'url-version': '0000.00.00.000', │ │ │ │ │ │ │ │ 'ha1-backup-ipaddr': '192.168.10.11', │ │ │ │ │ │ │ │ 'av-version': '0', │ │ │ │ │ │ │ │ 'platform-model': 'PA-VM', │ │ │ │ │ │ │ │ 'ha2-ipaddr': '192.168.11.3', │ │ │ │ │ │ │ │ 'ha1-ipaddr': '192.168.10.3', │ │ │ │ │ │ │ │ 'ha2-backup-ipaddr': '192.168.11.11', │ │ │ │ │ │ │ │ ... +26 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'link-monitoring': { │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ 'groups': {} │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'path-monitoring': { │ │ │ │ │ │ │ │ 'virtual-wire': {}, │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ 'vlan': {}, │ │ │ │ │ │ │ │ 'virtual-router': { │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ │ │ │ 'name': 'trust-vr', │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ 'ping-interval': '6000', │ │ │ │ │ │ │ │ │ │ │ 'ping-count': '10', │ │ │ │ │ │ │ │ │ │ │ 'destination-groups': { │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'dest-ip': { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'status': 'up', │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'addr': │ │ │ │ '203.48.105.145' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'name': 'trust-vr' │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'all', │ │ │ │ │ │ │ │ │ │ │ 'name': 'untrust-vr', │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ 'ping-interval': '6000', │ │ │ │ │ │ │ │ │ │ │ 'ping-count': '10', │ │ │ │ │ │ │ │ │ │ │ 'destination-groups': { │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'dest-ip': { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'status': 'up', │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'addr': │ │ │ │ '203.42.188.169' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'all', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'name': │ │ │ │ 'untrust-vr' │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'running-sync': 'synchronized', │ │ │ │ │ │ │ 'running-sync-enabled': 'yes' │ │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ } │ │ │ │ hostname = 'N1122322R-exh-pan-b' │ │ │ │ settings_file = <dynaconf.base.LazySettings object at 0x7f3eaf77f490> │ │ │ │ settings_file_path = PosixPath('/home/admin/pan-os-upgrade/settings.yaml') │ │ │ │ target_devices_to_revisit = None │ │ │ │ target_devices_to_revisit_lock = None │ │ │ │ target_version = '10.2.6-h1' │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ /home/admin/.local/lib/python3.11/site-packages/pan_os_upgrade/components/ha.py:248 in │ │ handle_firewall_ha │ │ │ │ 245 │ ) │ │ 246 │ │ │ 247 │ # Check if the firewall is in the revisit list │ │ ❱ 248 │ with target_devices_to_revisit_lock: │ │ 249 │ │ is_device_to_revisit = target_device in target_devices_to_revisit │ │ 250 │ │ │ 251 │ if is_device_to_revisit: │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ deploy_info = 'passive' │ │ │ │ dry_run = True │ │ │ │ ha_details = { │ │ │ │ │ 'result': { │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ 'group': { │ │ │ │ │ │ │ 'mode': 'Active-Passive', │ │ │ │ │ │ │ 'local-info': { │ │ │ │ │ │ │ │ 'url-compat': 'Match', │ │ │ │ │ │ │ │ 'app-version': '8811-8573', │ │ │ │ │ │ │ │ 'gpclient-version': 'Not Installed', │ │ │ │ │ │ │ │ 'build-rel': '10.1.10', │ │ │ │ │ │ │ │ 'ha2-port': 'ethernet1/5', │ │ │ │ │ │ │ │ 'av-version': '0', │ │ │ │ │ │ │ │ 'url-version': '0000.00.00.000', │ │ │ │ │ │ │ │ 'ha1-backup-ipaddr': '192.168.10.12/29', │ │ │ │ │ │ │ │ 'active-passive': { │ │ │ │ │ │ │ │ │ 'passive-link-state': 'auto', │ │ │ │ │ │ │ │ │ 'monitor-fail-holddown': '1' │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ 'platform-model': 'PA-VM', │ │ │ │ │ │ │ │ ... +49 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'peer-info': { │ │ │ │ │ │ │ │ 'app-version': '8811-8573', │ │ │ │ │ │ │ │ 'gpclient-version': 'Not Installed', │ │ │ │ │ │ │ │ 'VMS': '2.1.10', │ │ │ │ │ │ │ │ 'url-version': '0000.00.00.000', │ │ │ │ │ │ │ │ 'ha1-backup-ipaddr': '192.168.10.11', │ │ │ │ │ │ │ │ 'av-version': '0', │ │ │ │ │ │ │ │ 'platform-model': 'PA-VM', │ │ │ │ │ │ │ │ 'ha2-ipaddr': '192.168.11.3', │ │ │ │ │ │ │ │ 'ha1-ipaddr': '192.168.10.3', │ │ │ │ │ │ │ │ 'ha2-backup-ipaddr': '192.168.11.11', │ │ │ │ │ │ │ │ ... +26 │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'link-monitoring': { │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ 'groups': {} │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'path-monitoring': { │ │ │ │ │ │ │ │ 'virtual-wire': {}, │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ 'vlan': {}, │ │ │ │ │ │ │ │ 'virtual-router': { │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ │ │ │ 'name': 'trust-vr', │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ 'ping-interval': '6000', │ │ │ │ │ │ │ │ │ │ │ 'ping-count': '10', │ │ │ │ │ │ │ │ │ │ │ 'destination-groups': { │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'dest-ip': { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'status': 'up', │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'addr': │ │ │ │ '203.48.105.145' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'any', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'name': 'trust-vr' │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'all', │ │ │ │ │ │ │ │ │ │ │ 'name': 'untrust-vr', │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ 'ping-interval': '6000', │ │ │ │ │ │ │ │ │ │ │ 'ping-count': '10', │ │ │ │ │ │ │ │ │ │ │ 'destination-groups': { │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'dest-ip': { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'entry': [ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ { │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'status': 'up', │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'addr': │ │ │ │ '203.42.188.169' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'failure-condition': 'all', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'enabled': 'yes', │ │ │ │ │ │ │ │ │ │ │ │ │ │ 'name': │ │ │ │ 'untrust-vr' │ │ │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ │ │ ] │ │ │ │ │ │ │ │ } │ │ │ │ │ │ │ }, │ │ │ │ │ │ │ 'running-sync': 'synchronized', │ │ │ │ │ │ │ 'running-sync-enabled': 'yes' │ │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ } │ │ │ │ hostname = 'N1122322R-exh-pan-b' │ │ │ │ local_state = 'passive' │ │ │ │ local_version = '10.1.10' │ │ │ │ peer_version = '10.1.10' │ │ │ │ settings_file = <dynaconf.base.LazySettings object at 0x7f3eaf77f490> │ │ │ │ settings_file_path = PosixPath('/home/admin/pan-os-upgrade/settings.yaml') │ │ │ │ target_device = <Firewall '015354000084294' None at 0x7f3ea7894a10> │ │ │ │ target_devices_to_revisit = None │ │ │ │ target_devices_to_revisit_lock = None │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: 'NoneType' object does not support the context manager protocol

Screenshots:

Pan-01 Pan-02

Desktop (please complete the following information):

alperenkose commented 3 months ago

Hi,

I couldn't replicate the issue. Could you please confirm you are using the latest version of the tool ( which should be 1.3.10 ) as of now. You may check this with the poetry version command.

If you are using the latest version could you please provide the following details:

Thanks,

d945028 commented 3 months ago

Hi ,

The upgrade of the pan-os module to 1.3.10 fixed the issue.

  1. Yes, would like to use the script essentially for to upgrade HA pairs.
  2. Will enable debug logging.

Regards Asmita

General

From: Alp Eren Kose @.> Sent: Tuesday, April 23, 2024 5:23 PM To: cdot65/pan-os-upgrade @.> Cc: Paul, Asmita @.>; Author @.> Subject: Re: [cdot65/pan-os-upgrade] Erroring out when trying to the upgrade of the firewalls (Issue #136)

You don't often get email from @.*** Learn why this is importanthttps://aka.ms/LearnAboutSenderIdentification

[External Email] This email was sent from outside the organisation – be cautious, particularly with links and attachments.

Hi,

I couldn't replicate the issue. Could you please confirm you are using the latest version of the tool ( which should be 1.3.10 ) as of now. You may check this with the poetry version command.

If you are using the latest version could you please provide the following details:

Thanks,

— Reply to this email directly, view it on GitHubhttps://github.com/cdot65/pan-os-upgrade/issues/136#issuecomment-2071606617, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOSXWI7XIV5E5EJW42B66MDY6YD6FAVCNFSM6AAAAABF7TH6Z6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZRGYYDMNRRG4. You are receiving this because you authored the thread.Message ID: @.***>

alperenkose commented 3 months ago

Hi, Thanks for confirmation. So I will close the issue if you don't have the problem anymore?