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

Move module_utils out of subdir #26

Merged
merged 2 commits into from
Jun 11, 2020

Conversation

flowerysong
Copy link
Contributor

@flowerysong flowerysong commented Apr 5, 2020

SUMMARY

The migration script preserved the separation of (most of) our util files into an aws subdirectory in module_utils; it would be nice to get rid of this naming redundancy/inconsistency before the collection has a stable release and starts being widely used.

The split repos make this complicated to do without breaking CI. This PR creates the new files and adjusts all of the imports on this side. ansible-collections/community.aws#23 will theoretically pass once this is merged, and then it will be possible to remove the old files in a third PR.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

@flowerysong flowerysong force-pushed the flatten-module-utils branch 2 times, most recently from bbccfba to 768f353 Compare April 6, 2020 13:35
@flowerysong flowerysong changed the title [WIP] Move module_utils out of subdir Move module_utils out of subdir Apr 6, 2020
@jillr jillr self-assigned this Apr 6, 2020
Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This largely looks good, I want to pull this and the community PR down and do a bunch of extra testing to be safe though.

plugins/modules/aws_az_info.py Outdated Show resolved Hide resolved
@bcoca
Copy link

bcoca commented Apr 15, 2020

just to note, that ansible-base "routing" will include module_utils for backwards compatibility with 2.9, I would test/ensure that it works with this relocation. Worst case scenario you might be able to just make the old locations symlinks (as long as the internals are also not rearranged).

@flowerysong
Copy link
Contributor Author

@bcoca Redirection of module_utils is pretty broken right now, and I don't think this PR introduces any new concerns.

I was able to get ansible/ansible#67684 working for from ansible.module_utils.ec2 import HAS_BOTO3 by updating routing.yml, but from ansible.module_utils.aws.s3 import HAS_MD5 always resulted in an error regardless of where I tried to point it.

routing.yml diff:

       redirect: amazon.aws.iam
     rds:
       redirect: amazon.aws.rds
+    # Try pointing at a destination we know loads correctly
     s3:
-      redirect: amazon.aws.s3
+      redirect: ansible_collections.amazon.aws.plugins.module_utils.ec2
     waf:
       redirect: amazon.aws.waf
     waiters:
       redirect: amazon.aws.waiters
     ec2:
-      redirect: amazon.aws.ec2
+      redirect: ansible_collections.amazon.aws.plugins.module_utils.ec2
     ipaddress:
       redirect: f5networks.f5_modules.ipaddress
     network:

Error:

TASK [test_ping] ***************************************************************
task path: /home/ec2-user/testing/test.yml:3
The full traceback is:
Traceback (most recent call last):
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/task_executor.py", line 146, in run
    res = self._execute()
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/task_executor.py", line 645, in _execute
    result = self._handler.run(task_vars=variables)
  File "/home/ec2-user/testing/ansible/lib/ansible/plugins/action/normal.py", line 46, in run
    result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
  File "/home/ec2-user/testing/ansible/lib/ansible/plugins/action/__init__.py", line 822, in _execute_module
    (module_style, shebang, module_data, module_path) = self._configure_module(module_name=module_name, module_args=module_args, task_vars=task_vars)
  File "/home/ec2-user/testing/ansible/lib/ansible/plugins/action/__init__.py", line 216, in _configure_module
    **become_kwargs)
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/module_common.py", line 1287, in modify_module
    environment=environment)
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/module_common.py", line 1124, in _find_module_utils
    py_module_cache, zf)
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/module_common.py", line 871, in recursive_finder
    [os.path.join(p, *relative_module_utils[:-1]) for p in module_utils_paths])
  File "/home/ec2-user/testing/ansible/lib/ansible/executor/module_common.py", line 612, in __init__
    raise ImportError("No module named '%s'" % name)
ImportError: No module named '__init__'
fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

Adding an empty lib/ansible/module_utils/aws/__init__.py fixes this and then redirection works more or less as I would expect, though the use of bare filenames as the routing key means that ansible.module_utils.ec2, ansible.module_utils.aws.ec2, ansible.module_utils.common.ec2 etc. can all be successfully imported.

@bcoca
Copy link

bcoca commented Apr 15, 2020

^ @nitzmahone as the person that can 'unbreak' the redirection issues

@tremble
Copy link
Contributor

tremble commented Apr 26, 2020

@flowerysong thanks for this, I think this is definitely the right move now that we have our own namespace to use.

@jillr
Copy link
Collaborator

jillr commented May 5, 2020

@flowerysong I haven't forgotten about this PR, just waiting on 67684

@tremble
Copy link
Contributor

tremble commented May 13, 2020

@flowerysong I've split off the unit test fix so that we can get that in without the rest of this change.

Given we'll need to coordinate this change across the two repos I don't know how long it'll take to get the module_util migrations into place, we should at least get these unit tests fixed up.

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jillr @s-hertel Some follow up questions:

Since @flowerysong has taken the time to clean up the imports and the ordering how would you feel about sanity tests for:

  1. import order
  2. unused imports
  3. multiple imports on a single line

plugins/modules/ec2_vpc_net.py Outdated Show resolved Hide resolved
@jillr
Copy link
Collaborator

jillr commented May 13, 2020

@tremble I'm +1 unused imports, less so the others. I'd prefer not to get too strict on formatting via sanity tests without a much larger conversation and documented guidelines as I think that could increase contributor friction without a ton of benefit.

The network team is using black for their collections so there's a model there we could work from but we'll need to do more than just turning on sanity tests for it.

* Use relative imports
* Always get dict transformations from their canonical home
* Split imports by line to match tremble's other refactoring
* Make import order more consistent
@flowerysong flowerysong force-pushed the flatten-module-utils branch from bcd3389 to 4facc8d Compare May 14, 2020 15:43
@jillr
Copy link
Collaborator

jillr commented Jun 9, 2020

67684 has merged, additional local testing on devel and 2.9 LGTM. What do you think @tremble @s-hertel ?

@tremble
Copy link
Contributor

tremble commented Jun 10, 2020

+1 from my side.

@s-hertel
Copy link
Collaborator

Also +1

Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this work @flowerysong!

@jillr jillr merged commit d362475 into ansible-collections:master Jun 11, 2020
jillr pushed a commit to jillr/amazon.aws that referenced this pull request Jun 18, 2020
* Move module_utils out of subdir and update imports

* Use relative imports
* Always get dict transformations from their canonical home
* Split imports by line to match tremble's other refactoring
* Make import order more consistent

* Temporarily restore legacy module_utils files
alinabuzachis pushed a commit that referenced this pull request Aug 25, 2021
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit that referenced this pull request Aug 25, 2021
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit that referenced this pull request Aug 26, 2021
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit that referenced this pull request Aug 26, 2021
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit that referenced this pull request Aug 26, 2021
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 26, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 26, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 26, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
jillr pushed a commit to jillr/amazon.aws that referenced this pull request Aug 26, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
jillr pushed a commit to jillr/amazon.aws that referenced this pull request Aug 27, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
jillr pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 27, 2021
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
goneri pushed a commit that referenced this pull request Sep 20, 2022
…r(e) or e.me… (#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
GomathiselviS pushed a commit to GomathiselviS/amazon.aws that referenced this pull request Sep 20, 2022
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Sep 22, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Sep 22, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 2, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 6, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 11, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 16, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 24, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Oct 24, 2024
…r(e) or e.me… (ansible-collections#26)

* Py3 compat error handling: use to_native(e) instead of str(e) or e.message
* PR comment changes, use fail_json_aws and is_boto3_error_code

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@ffe14f9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants