PaloAltoNetworks / pan-os-python

The PAN-OS SDK for Python is a package to help interact with Palo Alto Networks devices (including physical and virtualized Next-generation Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics the traditional interaction with the device via the GUI or CLI/API.
https://pan-os-python.readthedocs.io
ISC License
340 stars 168 forks source link

SoftwareUpdater.install() method does not handle `load_config` parameter properly #448

Closed FoSix closed 2 years ago

FoSix commented 2 years ago

Describe the bug

When trying to use the any install method from SoftwareUpdater class with load_config parameter request system software installation command invocation fails with the following error message:

INFO:panos.updater.SoftwareUpdater:Device 007257000293805 installing version: 10.1.0
Traceback (most recent call last):
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/base.py", line 3878, in method
    super_method(self, *args, **kwargs)
  File "/Users/lpawlega/Library/Python/3.9/lib/python/site-packages/pan/xapi.py", line 951, in op
    self.__type_op(cmd, vsys, extra_qs)
  File "/Users/lpawlega/Library/Python/3.9/lib/python/site-packages/pan/xapi.py", line 974, in __type_op
    raise PanXapiError(self.status_detail)
pan.xapi.PanXapiError:  request -> system -> software -> install -> load-config is invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/upgrade.py", line 113, in <module>
    main()
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/upgrade.py", line 107, in main
    device.software.upgrade_to_version(args.version, 'fw01_10.0.9.xml', args.dryrun)
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/updater.py", line 348, in upgrade_to_version
    self.download_install_reboot(next_version, load_config=load_config, sync=True)
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/updater.py", line 224, in download_install_reboot
    self.download_install(version, load_config, sync=True)
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/updater.py", line 202, in download_install
    result = self.install(target_version, load_config=load_config, sync=sync)
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/updater.py", line 122, in install
    response = self._op(
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/updater.py", line 38, in _op
    return self.pandevice.xapi.op(cmd, cmd_xml=True)
  File "/Users/lpawlega/Git/vmseries_with_ansible/pan-os-python/examples/../panos/base.py", line 3899, in method
    raise the_exception
panos.errors.PanDeviceXapiError:  request -> system -> software -> install -> load-config is invalid

This is because double quotes around the named config string are missing.

Expected behavior

Command invocation should look like this: request system software install load-config "named_config.xml" version "10.1.2".

Current behavior

The command is invoked like this: request system software install load-config named_config.xml version "10.1.2".

Possible solution

See PR #447

Steps to reproduce

To reproduce the problem you can modify the updater.py file. In SoftwareUpdater.download_install_reboot() method pass the load_config parameter. You can use the upgrade.py example to reproduce the problem.

Screenshots

Context

This specific behaviour does not allow to write an Ansible module to downgrade PanOS version.

Your Environment

welcome-to-palo-alto-networks[bot] commented 2 years ago

:tada: Thanks for opening your first issue here! Welcome to the community!

shinmog commented 2 years ago

This was fixed by #447