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

fix for #12 - panos_admpwd hangs with python3 #21

Merged
merged 1 commit into from
Apr 13, 2020

Conversation

nembery
Copy link
Member

@nembery nembery commented Apr 9, 2020

panos_admpwd hangs or crashes when using with python3

Description

underlying paramiko library returns bytes instead of str when used in python3 vs python2. The panos_admpwd expects only str to be returned. This patch uses the Ansible recommended to_text function to switch handle bytes vs str return data as documented here:

https://docs.ansible.com/ansible/latest/dev_guide/developing_python_3.html#unicode-sandwich-common-borders-places-to-convert-bytes-to-text-in-controller-code

Motivation and Context

Launching instances in AWS when using python3 should work as expected.

Fixes issue #12

Launching with ansible-playbook -vvv eventually shows the following stack trace:

    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/modules/panos_admpwd.py\", line 196, in main\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/modules/panos_admpwd.py\", line 119, in set_panwfw_password\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/modules/panos_admpwd.py\", line 95, in wait_with_timeout\nTypeError: can only concatenate str (not \"bytes\") to str\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1586444632.0132165-220542648731622/AnsiballZ_panos_admpwd.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1586444632.0132165-220542648731622/AnsiballZ_panos_admpwd.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1586444632.0132165-220542648731622/AnsiballZ_panos_admpwd.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.panos_admpwd', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/local/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/modules/panos_admpwd.py\", line 204, in <module>\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/modules/panos_admpwd.py\", line 200, in main\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/module_utils/basic.py\", line 2092, in fail_json\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/module_utils/basic.py\", line 2064, in _return_formatted\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/module_utils/basic.py\", line 418, in remove_values\n  File \"/tmp/ansible_panos_admpwd_payload_g3f1ms1g/ansible_panos_admpwd_payload.zip/ansible/module_utils/basic.py\", line 401, in _remove_values_conditions\nTypeError: Value of unknown type: <class 'TypeError'>, can only concatenate str (not \"bytes\") to str\n",

How Has This Been Tested?

tested with both python3 and python2 environments on panorama instances launched in AWS.

Screenshots (if appropriate)

Types of changes

Introduce a new library into the panos_admpwd module:

from ansible.module_utils._text import to_text

Then wraps the call to

shell.recv(_PROMPTBUFF) with to_text(shell.recv(_PROMPTBUFF))

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes if appropriate.
  • All new and existing tests passed.

Copy link
Collaborator

@shinmog shinmog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@shinmog shinmog merged commit d101f34 into PaloAltoNetworks:develop Apr 13, 2020
@nembery nembery deleted the fix-issue-12 branch April 14, 2020 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants