ansible/ansible — pull request #3149 by blandonnimrat (2013-06-07 18:31:14+00:00)
Title: added error checking on connect_to_region() in ec2.py

if a bad region name is placed in ec2.ini for the ec2.py external inventory module the current code fails with a

AttributeError: 'NoneType' object has no attribute 'get_all_instances'

exception, because the connection object returned by Boto is of type None.

This pull request adds basic error checking around this to make a poorly formatted name easier to diagnose. Tried to follow error checking examples from elsewhere in the project.

error before

[jclaybaugh@ansible1 ansible]$ ./ec2-test.py
Traceback (most recent call last):
File "./ec2-test.py", line 512, in
Ec2Inventory()
File "./ec2-test.py", line 146, in __init__
self.do_api_calls_update_cache()
File "./ec2-test.py", line 230, in do_api_calls_update_cache
self.get_instances_by_region(region)
File "./ec2-test.py", line 249, in get_instances_by_region
reservations = conn.get_all_instances()
AttributeError: 'NoneType' object has no attribute 'get_all_instances'

error after

[jclaybaugh@ansible1 ansible]$ ./ec2.py --list
region name: 'all' likely not supported. connection to region failed.
make tests pass

My first pull request and I am not sure if this goes to the Ansible project or the original submitter of the ec2 inventory module.

thanks
Jonathan