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

Intermittent UnicodeDecodeError when running 'show jobs all' command using panos_op module #578

Open
appandya84 opened this issue Aug 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@appandya84
Copy link

Describe the bug

We have seen this intermittent issue for some firewalls where when we collect running jobs from firewalls by running 'show jobs all' command using panos_op module, it fails with UnicodeDecodeError. It seems some of the characters panos_op module doesn't like it. Some parsing enhancement in this panos.py script where it handles such unicode would be helpful

  • name: "{{ request_id }}: Collect jobs on firewall {{ ansible_host }} (show jobs all)"
    vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    panos_op:
    provider: '{{ provider }}'
    cmd: 'show jobs all'
    register: show_jobs_all_info

Expected behavior

it should collect all jobs from firewall and store in variable

Current behavior

Traceback (most recent call last):
File "/users/netengauto/.ansible/tmp/ansible-tmp-1723333918.359651-3106-167098343267774/AnsiballZ_panos_op.py", line 102, in
_ansiballz_main()
File "/users/netengauto/.ansible/tmp/ansible-tmp-1723333918.359651-3106-167098343267774/AnsiballZ_panos_op.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/users/netengauto/.ansible/tmp/ansible-tmp-1723333918.359651-3106-167098343267774/AnsiballZ_panos_op.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_op', init_globals=None, run_name='main', alter_sys=True)
File "/opt/python/3.7.3/lib64/python3.7/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/opt/python/3.7.3/lib64/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/opt/python/3.7.3/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_panos_op_payload_if6a328e/ansible_panos_op_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_op.py", line 170, in
File "/tmp/ansible_panos_op_payload_if6a328e/ansible_panos_op_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_op.py", line 144, in main
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/panos/firewall.py", line 243, in op
cmd, vsys, xml, cmd_xml, extra_qs, retry_on_peer
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/panos/base.py", line 4031, in op
element = self.xapi.op(cmd, vsys, False, extra_qs, retry_on_peer=retry_on_peer)
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/panos/base.py", line 3862, in method
super_method(self, *args, **kwargs)
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/pan/xapi.py", line 951, in op
self.__type_op(cmd, vsys, extra_qs)
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/pan/xapi.py", line 973, in __type_op
if not self.__set_response(response):
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/pan/xapi.py", line 257, in __set_response
return self.__set_xml_response(message_body)
File "/opt/ansible/3.7.3/lib64/python3.7/site-packages/pan/xapi.py", line 305, in __set_xml_response
self.xml_document = message_body.decode(_encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 13926: invalid start byte

Possible solution

is it possible to detect this error within the moduel and re-run using utf-8 instead of throwing an error and fail. Not sure if this is the right solution but just a proposal

Steps to reproduce

  • Collection: paloaltonetworks-panos-2.9.0
  • Python: 3.7.3
  • Ansible: 2.9.22
  • PAN-OS Python Library & version (e.g. pandevice 0.14.0, pan-os-python 1.0.2): pan-os-python==1.7.0 pan-python==0.16.0

Run below task in playbook. Please note I have also tried running using xml command too and gives same error.

CLI version:

  • name: "{{ request_id }}: Collect jobs on firewall {{ ansible_host }} (show jobs all)"
    vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    panos_op:
    provider: '{{ provider }}'
    cmd: 'show jobs all'
    register: show_jobs_all_info

XML version:

  • name: "{{ request_id }}: Collect jobs on firewall {{ ansible_host }} (show jobs all)"
    vars:
    ansible_python_interpreter: "{{ ansible_playbook_python }}"
    panos_op:
    provider: "{{ provider }}"
    cmd: ""
    cmd_is_xml: true
    register: show_jobs_all_info

Screenshots

image

Context

We are using this command prior to software upgrade to make sure no other jobs are running on firewall then we perform an upgrade on firewall. Affecting our prod firewall upgrade currently.

Your Environment

  • Collection: paloaltonetworks-panos-2.9.0
  • Python: 3.7.3
  • Ansible: 2.9.22
  • PAN-OS Python Library & version (e.g. pandevice 0.14.0, pan-os-python 1.0.2): pan-os-python==1.7.0 pan-python==0.16.0
@appandya84 appandya84 added the bug Something isn't working label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant