Skip to content

Commit

Permalink
Add check for requests module
Browse files Browse the repository at this point in the history
Fix adds check for requests Python module and suggests user to install,
if no requests module installation found.

Fixes: ansible#27643

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored and abadger committed Aug 3, 2017
1 parent 31b4ae2 commit 748fa5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/ansible/modules/messaging/rabbitmq_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@
'''

import json
import requests
import urllib

try:
import requests
HAS_REQUESTS = True
except ImportError as e:
HAS_REQUESTS = False

from ansible.module_utils.basic import AnsibleModule


Expand All @@ -127,6 +132,9 @@ def main():
supports_check_mode = True
)

if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")

if module.params['destination_type'] == "queue":
dest_type="q"
else:
Expand Down
9 changes: 8 additions & 1 deletion lib/ansible/modules/messaging/rabbitmq_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
'''

import json
import requests
try:
import requests
HAS_REQUESTS = True
except ImportError as e:
HAS_REQUESTS = False
import urllib

from ansible.module_utils.basic import AnsibleModule
Expand Down Expand Up @@ -137,6 +141,9 @@ def main():
urllib.quote(module.params['name'],'')
)

if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")

# Check if exchange already exists
r = requests.get( url, auth=(module.params['login_user'],module.params['login_password']))

Expand Down
9 changes: 8 additions & 1 deletion lib/ansible/modules/messaging/rabbitmq_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@
'''

import json
import requests
try:
import requests
HAS_REQUESTS = True
except ImportError as e:
HAS_REQUESTS = False
import urllib

from ansible.module_utils.basic import AnsibleModule
Expand Down Expand Up @@ -155,6 +159,9 @@ def main():
module.params['name']
)

if not HAS_REQUESTS:
module.fail_json(msg="requests library is required for this module. To install, use `pip install requests`")

# Check if queue already exists
r = requests.get( url, auth=(module.params['login_user'],module.params['login_password']))

Expand Down

0 comments on commit 748fa5d

Please sign in to comment.