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

Correcting exception call for UnexpectedResponse #57975

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
3 participants
@itblaked
Copy link

commented Jun 18, 2019

SUMMARY

Resubmitting PR#41796 as it's gone stale and not maintained.

Using the snow_record.py module with an incorrect parameters will always return a generic error, or will not execute at all and fail with a generic error:

in run_module\n except pysnow.UnexpectedResponse as e:\nAttributeError: 'module' object has no attribute 'UnexpectedResponse'\n",

This is because the pysnow python modules exception is named UnexpectedResponseFormat:

grep Unexpected /usr/lib/python2.7/site-packages/pysnow/exceptions.py
class UnexpectedResponseFormat(Exception):

Additionally, the exception call leaves out the 'exceptions' class. This code corrects these issues, and now the module will run playbooks correctly, as well as fail with the proper HTTP response codes.

Thanks to @syspimp and Robert Washington for finding the code and testing the fix.

Fixes: #41796 (Stale PR)

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

snow_record

ANSIBLE VERSION
ansible 2.8.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/bdouglas/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bdouglas/.local/lib/python2.7/site-packages/ansible
  executable location = /home/bdouglas/.local/bin/ansible
  python version = 2.7.16 (default, Apr 30 2019, 15:54:43) [GCC 9.0.1 20190312 (Red Hat 9.0.1-0.10)]
ADDITIONAL INFORMATION

before

ansible localhost -m snow_record -a 'instance=dev62503 username=admin password=x@RTAsQ4Lj@x5vk\!*epp table=incident state=present number=INC0010006'
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'module' object has no attribute 'UnexpectedResponse'
localhost | FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/bdouglas/.ansible/tmp/ansible-tmp-1560821317.48-213892535099470/AnsiballZ_snow_record.py\", line 114, in <module>\n    _ansiballz_main()\n  File \"/home/bdouglas/.ansible/tmp/ansible-tmp-1560821317.48-213892535099470/AnsiballZ_snow_record.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/bdouglas/.ansible/tmp/ansible-tmp-1560821317.48-213892535099470/AnsiballZ_snow_record.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_snow_record_payload_Lh_5cF/__main__.py\", line 334, in <module>\n  File \"/tmp/ansible_snow_record_payload_Lh_5cF/__main__.py\", line 330, in main\n  File \"/tmp/ansible_snow_record_payload_Lh_5cF/__main__.py\", line 319, in run_module\nAttributeError: 'module' object has no attribute 'UnexpectedResponse'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

after

ansible localhost -m snow_record -a 'instance=dev62503 username=admin password=**** table=incident state=present number=INC0010006'         
localhost | FAILED! => {
    "changed": false, 
    "instance": "dev62503", 
    "lookup_field": "number", 
    "msg": "Failed to update record: Unexpected HTTP GET response code. Expected 200, got 401", 
    "number": "INC0010006", 
    "table": "incident"

@itblaked itblaked changed the title WIP Correcting exception call for UnexpectedResponse Correcting exception call for UnexpectedResponse Jun 18, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

@itblaked this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

Correcting exception call for UnexpectedResponse
Correcting call to pysnow.exceptions.UnexpectedFormatResponse, bad call masked true api errors.

@itblaked itblaked force-pushed the itblaked:devel branch from eda512c to f46dab4 Jun 18, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

@itblaked

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

ready_for_review

@itblaked

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

!component =lib/ansible/modules/notification/snow_record.py

@itblaked

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

bot_status

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

Components

lib/ansible/modules/notification/snow_record.py
support: community
maintainers: garbled1

Metadata

waiting_on: maintainer
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 0
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 0
shipit_actors (maintainer or core team member): []
shipit_actors_other: []
automerge: automerge shipit test failed

click here for bot help

@jhg03a

This comment has been minimized.

Copy link

commented Jul 11, 2019

This patch allows me to get more useful error messages in Ansible 2.8.0

@jhg03a

This comment has been minimized.

Copy link

commented Jul 11, 2019

It appears these same patches got made in #58410

@itblaked

This comment has been minimized.

Copy link
Author

commented Jul 11, 2019

resolved_by_pr #58410

@itblaked

This comment has been minimized.

Copy link
Author

commented Jul 11, 2019

It appears these same patches got made in #58410

Thanks @jhg03a for the heads up

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.