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

Import test doesn't recognize relative imports in a module inside collection #61884

Closed
anshulbehl opened this issue Sep 5, 2019 · 7 comments · Fixed by #63830
Closed

Import test doesn't recognize relative imports in a module inside collection #61884

anshulbehl opened this issue Sep 5, 2019 · 7 comments · Fixed by #63830
Assignees
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection Related to Ansible Collections work has_pr This issue has an associated PR. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.

Comments

@anshulbehl
Copy link
Contributor

SUMMARY

When trying to check support of relative imports in modules inside collections, import sanity test fails giving below error

Running sanity test 'import' with Python 2.7
ERROR: Found 1 import issue(s) on python 2.7 which need to be resolved:
ERROR: plugins/modules/rubrik_managed_volume.py:8:0: ValueError: Attempted relative import in non-package
WARNING: Skipping sanity test 'import' on Python 3.5 due to missing interpreter.
WARNING: Skipping sanity test 'import' on Python 3.6 due to missing interpreter.
Running sanity test 'import' with Python 3.7
ERROR: Found 1 import issue(s) on python 3.7 which need to be resolved:
ERROR: plugins/modules/rubrik_managed_volume.py:8:0: ImportError: attempted relative import with no known parent package
ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible-test sanity import

ANSIBLE VERSION
ansible 2.9.0b1
  config file = /home/abehl/.ansible/collections/ansible_collections/rubrikinc/rubrik/ansible.cfg
  configured module search path = ['/home/abehl/.ansible/collections/ansible_collections/rubrikinc/rubrik/library']
  ansible python module location = /home/abehl/work/src/anshul_ansible/ansible/lib/ansible
  executable location = /home/abehl/work/src/anshul_ansible/ansible/bin/ansible
  python version = 3.7.3 (default, May 11 2019, 00:38:04) [GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]
CONFIGURATION

OS / ENVIRONMENT
STEPS TO REPRODUCE

Create a collection with modules having relative imports
Try running ansible-test sanity on the same module

EXPECTED RESULTS

Relative imports should pass

ACTUAL RESULTS

ansible import tests doesn't recognize relative import


@ansibot
Copy link
Contributor

ansibot commented Sep 5, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Sep 5, 2019

@anshulbehl anshulbehl changed the title Import test doesn't recognize relative imports in a collection Import test doesn't recognize relative imports in a module inside collection Sep 5, 2019
@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Sep 5, 2019
@Akasurde Akasurde added the collection Related to Ansible Collections work label Sep 6, 2019
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Sep 12, 2019
@mattclay mattclay added this to To do in Testing Collections via automation Sep 22, 2019
@AlanCoding
Copy link
Member

I hit the same thing, output was slightly different

ERROR: plugins/modules/tower_host.py:0:0: missing-module-utils-import: Did not find a module_utils import
ERROR: plugins/modules/tower_inventory.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'attempted relative import with no known parent package'
ERROR: plugins/modules/tower_inventory.py:0:0: missing-module-utils-import: Did not find a module_utils import
ERROR: plugins/modules/tower_inventory_source.py:0:0: import-error: Exception attempti

The important thing here is that none of the other errors are reported. So I don't think we can just ignore this particular type of error.

@sivel
Copy link
Member

sivel commented Oct 2, 2019

#62496 is also related

@AlanCoding
Copy link
Member

I tried to hack around this by substituting the package name where we were using .., but that still leads to problems.

ERROR: plugins/modules/tower_credential.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'No module named 'ansible_collections.awx.awx.module_utils''
ERROR: plugins/modules/tower_credential_type.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'No module named 'ansible_collections.awx.awx.module_utils''
ERROR: plugins/modules/tower_credential_type.py:0:0: missing-module-utils-import: Did not find a module_utils import
ERROR: plugins/modules/tower_group.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'No module named 'ansible_collections.awx.awx.module_utils''
ERROR: plugins/modules/tower_group.py:0:0: missing-module-utils-import: Did not find a module_utils import
ERROR: plugins/modules/tower_host.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'No module named 'ansible_collections.awx.awx.module_utils''

Either I'm doing this wrong, or this is a problem general for collections with module_utils.

@mattclay mattclay self-assigned this Oct 15, 2019
@mattclay mattclay moved this from To do to In progress in Testing Collections Oct 15, 2019
@ansibot ansibot added the has_pr This issue has an associated PR. label Oct 15, 2019
mattclay added a commit to mattclay/ansible that referenced this issue Oct 23, 2019
- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves ansible#62723
Resolves ansible#61884
mattclay added a commit to mattclay/ansible that referenced this issue Oct 23, 2019
- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves ansible#62723
Resolves ansible#61884
Testing Collections automation moved this from In progress to Done Oct 23, 2019
mattclay added a commit that referenced this issue Oct 23, 2019
- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves #62723
Resolves #61884
mattclay added a commit to mattclay/ansible that referenced this issue Oct 23, 2019
- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves ansible#62723
Resolves ansible#61884
(cherry picked from commit 92ccdea)

Co-authored-by: Matt Clay <matt@mystile.com>
nitzmahone pushed a commit that referenced this issue Oct 23, 2019
* [stable-2.9] Fix various import sanity test issues.

- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves #62723
Resolves #61884
(cherry picked from commit 92ccdea)

Co-authored-by: Matt Clay <matt@mystile.com>

* Changelog entry for ansible-test sanity fixes.

(cherry picked from commit 0923ed5)
@AlanCoding
Copy link
Member

@nitzmahone some more details in #63084 (comment)

More or less, I don't think this is fixed. In the current devel branch, I get these error types:

ERROR: plugins/modules/tower_workflow_template.py:0:0: import-error: Exception attempting to import module for argument_spec introspection, 'attempted relative import with no known parent package'
ERROR: plugins/modules/tower_workflow_template.py:0:0: missing-module-utils-import: Did not find a module_utils import

I have a script that replaces the relative imports with absolute imports. If I run this, and then run sanity tests, I'm left with:


ERROR: plugins/modules/tower_organization.py:0:0: missing-module-utils-import: Did not find a module_utils import

One of these error describes #62496

However, the error "attempted relative import with no known parent package" with relative imports is this issue, and in current devel it seems to not be fixed.

@mattclay
Copy link
Member

@AlanCoding These are two separate issues. This issue was for the import sanity test. The errors you're referring to are for the validate-modules sanity test, which should be fixed by #63932.

@ansible ansible locked and limited conversation to collaborators Nov 21, 2019
anshulbehl pushed a commit to anshulbehl/ansible that referenced this issue Dec 10, 2019
- Relative imports are now properly recognized.
- Correct script invocation of Ansible modules is used.
- Warnings are now consistently reported as errors.
- Errors are now consistently reported with the file tested.

Resolves ansible#62723
Resolves ansible#61884
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection Related to Ansible Collections work has_pr This issue has an associated PR. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
Development

Successfully merging a pull request may close this issue.

7 participants