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_elb module Python 3 Compat #50367

Closed
wants to merge 1 commit into from
Closed

ec2_elb module Python 3 Compat #50367

wants to merge 1 commit into from

Conversation

kepeket
Copy link

@kepeket kepeket commented Dec 28, 2018

Python 3 sort() does not benefits automatic
typecast of objects into a string (as Python27
does).

Use a lambda to help the function sort the list
with __repr__

SUMMARY

When using this module on python3, it fails to sort() the LB objects that boto returns.

On python2, the automatic type casting was used during cmp was calling __repr__ to cast as a string, then using __lt__ to perform the operator comparison

I'm proposing to ensure compatibility between the two python versions by passing a lambda in kwargs. It uses the __repr__ to fallback to string comparison.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_elb

ADDITIONAL INFORMATION

1/ have an ASG or two in you AWS account
2/ try to unregister an instance from it using ec2_elb module (https://docs.ansible.com/ansible/latest/modules/ec2_elb_module.html#id5 example here)
3/ enjoy failure (TypeError: '<' not supported between instances of 'LoadBalancer' and 'LoadBalancer')

@ansibot
Copy link
Contributor

ansibot commented Dec 28, 2018

cc @jarv
click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Dec 28, 2018

@kepeket, just so you are aware we have a dedicated Working Group for aws.
You can find other people interested in this in #ansible-aws on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 aws bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. python3 small_patch support:community This issue/PR relates to code supported by the Ansible community. labels Dec 28, 2018
@ansibot
Copy link
Contributor

ansibot commented Dec 28, 2018

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:0: syntax-error Generator expression must be parenthesized if not sole argument (&lt;unknown&gt;, line 277)

The test ansible-test sanity --test ansible-doc --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 2.7 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.5 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.7 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test docs-build [explain] failed with the error:

Command "/usr/bin/python test/sanity/code-smell/docs-build.py" returned exit status 1.
>>> Standard Error
Command 'make singlehtmldocs' failed with status code: 2
--> Standard Output
cat _themes/srtd/static/css/theme.css | sed -e 's/^[ 	]*//g; s/[ 	]*$//g; s/\([:{;,]\) /\1/g; s/ {/{/g; s/\/\*.*\*\///g; /^$/d' | sed -e :a -e '$!N; s/\n\(.\)/\1/; ta' > _themes/srtd/static/css/theme.min.css
PYTHONPATH=../../lib ../bin/dump_config.py --template-file=../templates/config.rst.j2 --output-dir=rst/reference_appendices/ -d ../../lib/ansible/config/base.yml
mkdir -p rst/cli
PYTHONPATH=../../lib ../bin/generate_man.py --template-file=../templates/cli_rst.j2 --output-dir=rst/cli/ --output-format rst ../../lib/ansible/cli/*.py
PYTHONPATH=../../lib ../bin/dump_keywords.py --template-dir=../templates --output-dir=rst/reference_appendices/ -d ./keyword_desc.yml
PYTHONPATH=../../lib ../bin/plugin_formatter.py -t rst --template-dir=../templates --module-dir=../../lib/ansible/modules -o rst/modules/ 
Evaluating module files...
Makefile:93: recipe for target 'modules' failed
--> Standard Error
Traceback (most recent call last):
  File "../bin/plugin_formatter.py", line 754, in <module>
    main()
  File "../bin/plugin_formatter.py", line 709, in main
    plugin_info, categories = get_plugin_info(options.module_dir, limit_to=options.limit_to, verbose=(options.verbosity > 0))
  File "../bin/plugin_formatter.py", line 294, in get_plugin_info
    doc, examples, returndocs, metadata = plugin_docs.get_docstring(module_path, fragment_loader, verbose=verbose)
  File "/root/ansible/lib/ansible/utils/plugin_docs.py", line 103, in get_docstring
    data = read_docstring(filename, verbose=verbose, ignore_errors=ignore_errors)
  File "/root/ansible/lib/ansible/parsing/plugin_docs.py", line 40, in read_docstring
    M = ast.parse(b_module_data.read())
  File "/usr/lib/python3.6/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 277
SyntaxError: Generator expression must be parenthesized if not sole argument
make: *** [modules] Error 1

The test ansible-test sanity --test import --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:0: SyntaxError: Generator expression must be parenthesized if not sole argument

The test ansible-test sanity --test import --python 2.7 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:0: SyntaxError: Generator expression must be parenthesized if not sole argument

The test ansible-test sanity --test import --python 3.5 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:25: SyntaxError: Generator expression must be parenthesized if not sole argument

The test ansible-test sanity --test import --python 3.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:25: SyntaxError: Generator expression must be parenthesized if not sole argument

The test ansible-test sanity --test import --python 3.7 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:25: SyntaxError: Generator expression must be parenthesized

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

lib/ansible/modules/cloud/amazon/ec2_elb.py:0:0: E401 Python SyntaxError while parsing module
test/sanity/validate-modules/ignore.txt:31:1: A102 Remove since "lib/ansible/modules/cloud/amazon/ec2_elb.py" passes "E326" test

The test ansible-test sanity --test yamllint [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_elb.py:277:25: python-syntax-error Generator expression must be parenthesized if not sole argument (<unknown>, line 277)

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Dec 28, 2018
@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 Jan 5, 2019
Python 3 sort() doest not benefits automatic
type cast of objects into string (as Python27
does).

Use a lambda to help the function sort the list
with __repr__
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 7, 2019
@kepeket
Copy link
Author

kepeket commented Jan 7, 2019

Thanks @bbayszczak

@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 Jan 15, 2019
@stevenscg
Copy link
Contributor

I have run into this issue myself now with ansible 2.7.10.

@stevenscg
Copy link
Contributor

FYI. I was able to workaround this issue by setting the interpreter just for the plays that call this module. Not a great solution, but it works for now.

- name: Register instances with the load balancer(s)
  local_action: ec2_elb
  args:
    ....
  vars:
    ansible_python_interpreter: /usr/bin/python2.7

@ansibot
Copy link
Contributor

ansibot commented Jan 26, 2020

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Mar 30, 2020
@ansibot ansibot added collection Related to Ansible Collections work collection:community.aws needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 16, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this Aug 16, 2020
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Aug 17, 2020
@ansible ansible locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 aws bot_closed bug This issue/PR relates to a bug. cloud collection:community.aws collection Related to Ansible Collections work module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. python3 small_patch 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants