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

ec2 inventory: python 3.7 compatibility #43716

Merged
merged 1 commit into from Sep 4, 2018
Merged

ec2 inventory: python 3.7 compatibility #43716

merged 1 commit into from Sep 4, 2018

Conversation

siwyd
Copy link
Contributor

@siwyd siwyd commented Aug 6, 2018

SUMMARY

ec2 inventory script was throwing errors when using Python 3.7:

❯ ./ec2.py --list  
Traceback (most recent call last):
  File "./ec2.py", line 1711, in <module>
    Ec2Inventory()
  File "./ec2.py", line 267, in __init__
    self.read_settings()
  File "./ec2.py", line 321, in read_settings
    config = configparser.ConfigParser(DEFAULTS)
  File "/usr/lib/python3.7/configparser.py", line 638, in __init__
    self._read_defaults(defaults)
  File "/usr/lib/python3.7/configparser.py", line 1216, in _read_defaults
    self.read_dict({self.default_section: defaults})
  File "/usr/lib/python3.7/configparser.py", line 753, in read_dict
    self.set(section, key, value)
  File "/usr/lib/python3.7/configparser.py", line 1197, in set
    self._validate_value_types(option=option, value=value)
  File "/usr/lib/python3.7/configparser.py", line 1182, in _validate_value_types
    raise TypeError("option values must be strings")
TypeError: option values must be strings

This changes the ConfigParser options that hava a None value to empty strings instead.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

contrib ec2 dynamic inventory

ANSIBLE VERSION
ansible 2.6.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/hb/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.0 (default, Jul 15 2018, 10:44:58) [GCC 8.1.1 20180531]
ADDITIONAL INFORMATION

N/A

ec2 inventory script was throwing errors when using Python 3.7:

TypeError: option values must be strings

This changes the None ConfigParser options to empty strings instead.
@ansibot
Copy link
Contributor

ansibot commented Aug 6, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 aws bug This issue/PR relates to a bug. c:inventory/contrib_script cloud inventory Inventory category needs_triage Needs a first human triage before being processed. python3 support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Aug 6, 2018
@ryansb ryansb requested a review from willthames August 6, 2018 14:34
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Aug 6, 2018
@Jackyjjc
Copy link
Contributor

What about adding allow_no_value=True to the constructor of ConfigParser? Then we can keep the None values

@siwyd
Copy link
Contributor Author

siwyd commented Aug 10, 2018

Sure, that can work too I guess. Although I see now that there was already a mix of empty strings and None, for instance:

'route53_excluded_zones': '',
'route53_hostnames': None,

So maybe best to pick one or the other and make it consistent?

@siwyd
Copy link
Contributor Author

siwyd commented Aug 15, 2018

Any feedback on this?

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 15, 2018
@bqbn
Copy link
Contributor

bqbn commented Aug 26, 2018

We ran into the same issue today.

Can we fix this please?

@madhead
Copy link

madhead commented Sep 4, 2018

Until the fix is available, try replacing:

if six.PY3:
    config = configparser.ConfigParser(DEFAULTS)
else:
    config = configparser.SafeConfigParser(DEFAULTS)

with

if six.PY3:
    config = configparser.ConfigParser(DEFAULTS, allow_no_value=True)
else:
    config = configparser.SafeConfigParser(DEFAULTS, allow_no_value=True)

in ec2.py

@siwyd
Copy link
Contributor Author

siwyd commented Sep 4, 2018

Happy to finish this PR one way or another, but need some feedback from somebody that has magic merge powers... @dagwieers I'm sure you're still lurking about somewhere? :)

@dagwieers
Copy link
Contributor

Well, I wouldn't know if this is the right fix, or if @madhead 's suggestion is a better idea, honestly.

@willthames willthames merged commit 505ce6c into ansible:devel Sep 4, 2018
@willthames
Copy link
Contributor

Merged, thanks for the fix (and apology for the delay reviewing/merging)

willthames pushed a commit to willthames/ansible that referenced this pull request Sep 5, 2018
ec2 inventory script was throwing errors when using Python 3.7:

TypeError: option values must be strings

This changes the None ConfigParser options to empty strings instead.

(cherry picked from commit 505ce6c)
@willthames
Copy link
Contributor

Raised a backport request to get this into upcoming 2.7 release (otherwise it would wait until 2.8)

abadger pushed a commit that referenced this pull request Sep 6, 2018
ec2 inventory script was throwing errors when using Python 3.7:

TypeError: option values must be strings

This changes the None ConfigParser options to empty strings instead.

(cherry picked from commit 505ce6c)
@siwyd siwyd deleted the fix-ec2-inventory-py3.7 branch September 14, 2018 11:39
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 aws bug This issue/PR relates to a bug. c:inventory/contrib_script cloud inventory Inventory category python3 stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants