PaloAltoNetworks / PaloAltoNetworks/pan-os-python

Issue with #493 when commit is not required, response None

Open
#569 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
400
Forks
199
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Was OK before 02/2024

With Ansible, when I commit to Panorama I have this issue. This is related to the pan-os-python as

The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/panos/base.py", line 4899, in _commit
    jobid = commit_response.find("./result/job").text
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'text'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_commit_panorama', init_globals=dict(_module_fqn='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_commit_panorama', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/ansible_paloaltonetworks.panos.panos_commit_panorama_payload_p38osrq0/ansible_paloaltonetworks.panos.panos_commit_panorama_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_commit_panorama.py", line 222, in <module>
  File "/tmp/ansible_paloaltonetworks.panos.panos_commit_panorama_payload_p38osrq0/ansible_paloaltonetworks.panos.panos_commit_panorama_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_commit_panorama.py", line 200, in main
  File "/usr/local/lib/python3.11/site-packages/panos/base.py", line 4803, in commit
    return self._commit(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/panos/base.py", line 4906, in _commit
    commit_response_msg = commit_response.find("./msg/line").text
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'text'
fatal: [oppano21s.net.meshcore.net]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.11/site-packages/panos/base.py\", line 4899, in _commit\n    jobid = commit_response.find(\"./result/job\").text\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'NoneType' object has no attribute 'text'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1719845283.5125809-203-3565473327147/AnsiballZ_panos_commit_panorama.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_commit_panorama', init_globals=dict(_module_fqn='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_commit_panorama', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_commit_panorama_payload_p38osrq0/ansible_paloaltonetworks.panos.panos_commit_panorama_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_commit_panorama.py\", line 222, in <module>\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_commit_panorama_payload_p38osrq0/ansible_paloaltonetworks.panos.panos_commit_panorama_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_commit_panorama.py\", line 200, in main\n  File \"/usr/local/lib/python3.11/site-packages/panos/base.py\", line 4803, in commit\n    return self._commit(\n           ^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/site-packages/panos/base.py\", line 4906, in _commit\n    commit_response_msg = commit_response.find(\"./msg/line\").text\n                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'NoneType' object has no attribute 'text'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Expected behavior

It should work with a message Commit not needed
No issues when modification are there to commit to the device.

Current behavior

Python error

 commit_response_msg = commit_response.find(\"./msg/line\").text\nAttributeError: 'NoneType' object has no attribute 'text'\n",

Possible solution

Change line on /panos/base.py (https://github.com/PaloAltoNetworks/pan-os-python/blob/62bcff3bca86a5ff745eae3e92635d109673963a/panos/base.py#L4906C1-L4906C78)

to add a try except

                try:
                    commit_response_msg = commit_response.find("./msg/line").text
                except AttributeError:
                    commit_response_msg = "No message in commit response"
                self._logger.debug("No job id. Msg: " + commit_response_msg)

Steps to reproduce

  1. Commit without changes

Screenshots

Context

Issue is with last version of ansible, and pan-os-python

Your Environment

antoinekh# ansible --version
ansible [core 2.17.1]
  config file = /home/w132231/w132231/ansible_performance/ansible.cfg
  configured module search path = ['/home/w132231/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/w132231/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/w132231/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/w132231/.local/bin/ansible
  python version = 3.10.13 (main, Aug 25 2023, 13:20:03) [GCC 9.4.0] (/usr/bin/python3.10)
  jinja version = 3.1.2
  libyaml = True

antoinekh# pip3 freeze                   
pan-os-python==1.12.1
pan-python==0.17.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in panos/base.py at _commit around the commit_response.find("./msg/line") call. Reproduce by committing without changes through the Ansible panos_commit_panorama module, then verify the no-change response is handled without an AttributeError and reports that no commit is needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.