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

Check for existence of object attr login_handle #53821

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
3 participants
@movinalot
Copy link
Contributor

movinalot commented Mar 14, 2019

SUMMARY

module_utils/remote_management/ucs.py

On deconstruction of UCS Manager login session, UCSModule object will throw the unhandled exception AttributeError: 'UCSModule' object has no attribute 'login_handle' if the login credentials are incorrect or if the UCS Manager is unreachable. In either case, the UCSModule object attempts to access a nonexistent attribute login_handle. The attribute will not exist in these cases because a successful login did not take place.

Playbook running of the module masks the exception, local testing with an args.json file shows the unhandled exception.

The fix checks for the existence of the login_handle attribute before attempting

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

module_utils/remote_management/ucs.py

ADDITIONAL INFORMATION
(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ ansible --version
ansible 2.8.0.dev0
  config file = /Users/jomcdono/.ansible.cfg
  configured module search path = ['/Users/jomcdono/Documents/src/ucs/ansible/lib/ansible/modules/remote_management/ucs']
  ansible python module location = /Users/jomcdono/Desktop/sxsw/ansible/lib/ansible
  executable location = /Users/jomcdono/Desktop/sxsw/ansible/bin/ansible
  python version = 3.7.2 (default, Feb 12 2019, 08:15:36) [Clang 10.0.0 (clang-1000.11.45.5)]

BEFORE - INVALID UCS MANAGER IP/HOST
(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ python ucs_org.py args.json 

{"msg": "<urlopen error [Errno 51] Network is unreachable>", "failed": true, "invocation": {"module_args": {"hostname": "10.201.0.5", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "org_name": "test", "description": "Testing org", "state": "present", "delegate_to": "localhost", "use_ssl": true, "use_proxy": true, "parent_org_path": "root", "port": null, "proxy": null}}}
Exception ignored in: <function UCSModule.__del__ at 0x10c921d90>
Traceback (most recent call last):
  File "/Users/jomcdono/Desktop/sxsw/ansible/lib/ansible/module_utils/remote_management/ucs.py", line 63, in __del__
    self.logout()
  File "/Users/jomcdono/Desktop/sxsw/ansible/lib/ansible/module_utils/remote_management/ucs.py", line 94, in logout
    if self.login_handle:
AttributeError: 'UCSModule' object has no attribute 'login_handle'
AFTER - INVALID UCS MANAGER IP/HOST

(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ python ucs_org.py args.json 

{"msg": "<urlopen error [Errno 60] Operation timed out>", "failed": true, "invocation": {"module_args": {"hostname": "10.201.0.5", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "org_name": "test", "description": "Testing org", "state": "present", "delegate_to": "localhost", "use_ssl": true, "use_proxy": true, "parent_org_path": "root", "port": null, "proxy": null}}}

BEFORE - INVALID CREDENTIALS
(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ python ucs_org.py args.json 

{"msg": "[ErrorCode]: 551[ErrorDescription]: Authentication failed", "failed": true, "invocation": {"module_args": {"hostname": "10.200.0.5", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "org_name": "test", "description": "Testing org", "state": "present", "delegate_to": "localhost", "use_ssl": true, "use_proxy": true, "parent_org_path": "root", "port": null, "proxy": null}}}
Exception ignored in: <function UCSModule.__del__ at 0x110470e18>
Traceback (most recent call last):
  File "/Users/jomcdono/Desktop/sxsw/ansible/lib/ansible/module_utils/remote_management/ucs.py", line 63, in __del__
    self.logout()
  File "/Users/jomcdono/Desktop/sxsw/ansible/lib/ansible/module_utils/remote_management/ucs.py", line 94, in logout
    if self.login_handle:
AttributeError: 'UCSModule' object has no attribute 'login_handle'

AFTER - INVALID CREDENTIALS
(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ python ucs_org.py args.json 

{"msg": "[ErrorCode]: 551[ErrorDescription]: Authentication failed", "failed": true, "invocation": {"module_args": {"hostname": "10.200.0.5", "username": "admin", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "org_name": "test", "description": "Testing org", "state": "present", "delegate_to": "localhost", "use_ssl": true, "use_proxy": true, "parent_org_path": "root", "port": null, "proxy": null}}}
(venv) JOMCDONO-M-P1AL:ucsm-ansible jomcdono$ python ucs_org.py args.json
@ansibot

This comment has been minimized.

@dsoper2
Copy link
Contributor

dsoper2 left a comment

shipit

@ansibot ansibot removed the needs_triage label Mar 15, 2019

@ansibot ansibot added shipit and removed community_review labels Mar 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.