Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antoinekh opened this issue Jul 1, 2024 · 5 comments
Open

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

antoinekh opened this issue Jul 1, 2024 · 5 comments
Labels

Comments

@antoinekh
Copy link

antoinekh commented Jul 1, 2024

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
@antoinekh antoinekh added the bug label Jul 1, 2024
@antoinekh
Copy link
Author

Maybe similar to #471

@antoinekh antoinekh changed the title 11.0.5 - Issue when commit is not required Issue when commit is not required, reponse None Jul 1, 2024
@antoinekh antoinekh changed the title Issue when commit is not required, reponse None Issue when commit is not required, response None Jul 1, 2024
@antoinekh
Copy link
Author

I have tried with success to add the following lines and this fix the issue

L4906 on base.py

    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)

@antoinekh
Copy link
Author

antoinekh commented Jul 2, 2024

the problem has been added here #493 the 07/02/2024

@antoinekh antoinekh changed the title Issue when commit is not required, response None Issue with #493 when commit is not required, response None Jul 2, 2024
@antoinekh
Copy link
Author

Pull request #557

@antoinekh
Copy link
Author

I can confirm that it works in pan-os-python 1.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant