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

ansible-test --help reports an error if cwd is not a collection path #64523

Closed
rrey opened this issue Nov 6, 2019 · 12 comments · Fixed by #76866
Closed

ansible-test --help reports an error if cwd is not a collection path #64523

rrey opened this issue Nov 6, 2019 · 12 comments · Fixed by #76866
Labels
affects_2.9 This issue/PR affects Ansible v2.9 affects_2.13 feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@rrey
Copy link
Contributor

rrey commented Nov 6, 2019

SUMMARY

The ansible-test --help command will fail with an error if you are not inside a collection path.
It's a bit hard as an introduction :) We should be able to get help from anywhere.

ISSUE TYPE

Feature Idea

COMPONENT NAME

ansible-test

ANSIBLE VERSION
ansible 2.9.0
  config file = None
  configured module search path = ['/Users/remi.rey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/remi.rey/.virtualenvs/ansible/lib/python3.7/site-packages/ansible
  executable location = /Users/remi.rey/.virtualenvs/ansible/bin/ansible
  python version = 3.7.4 (default, Sep  7 2019, 18:27:02) [Clang 10.0.1 (clang-1001.0.46.4)]
CONFIGURATION
N/A
OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
$ pip install ansible==2.9
$ ansible-test --help
EXPECTED RESULTS
$ ansible-test --help
usage: ansible-test [-h] COMMAND ...

positional arguments:
  COMMAND
    integration        posix integration tests
    network-integration
                       network integration tests
    windows-integration
                       windows integration tests
    units              unit tests
    sanity             sanity tests
    shell              open an interactive shell
    coverage           code coverage management and reporting
    env                show information about the test environment

optional arguments:
  -h, --help           show this help message and exit

Install the "argcomplete" python package to enable tab completion.
ACTUAL RESULTS
$ ansible-test --help
ERROR: The current working directory must be at or below:

 - an Ansible collection: {...}/ansible_collections/{namespace}/{collection}/

Current working directory: /Users/remi.rey
@ansibot
Copy link
Contributor

ansibot commented Nov 6, 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 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. labels Nov 6, 2019
@webknjaz
Copy link
Member

webknjaz commented Nov 6, 2019

Hey @rrey,
have you tried checking the latest devel version? (from Git)

@rrey
Copy link
Contributor Author

rrey commented Nov 6, 2019

Hi @webknjaz !

No I didn't.
But I checked out the tag v2.9.0 and tried ansible-test --help and had no error.
maybe the source hacking/env-setup is setting things properly ?

@sivel
Copy link
Member

sivel commented Nov 6, 2019

I believe it is still an issue in devel.

If you are outside of the ansible git clone, and not in a collection you get that error.

It is due to the first data_context() call that is done before argument parsing.

@rrey
Copy link
Contributor Author

rrey commented Nov 7, 2019

I tried to see if I could make a patch but it is beyond my understanding of the code.
The data_context() is made during the argument parsing during the add_environments() call.

@sivel
Copy link
Member

sivel commented Nov 7, 2019

I'll need to defer to @mattclay as I am unsure what problems could arise by trying to move the call until after arguments have been parsed.

@mattclay
Copy link
Member

mattclay commented Nov 7, 2019

The --help output is of course dependent on what options are available. The available options are different depending on the working directory, which is why help is currently unavailable if not in a supported directory.

In order to support help in any directory we first will need to decide what limited subset of help would be useful, to see if it's practical to support it.

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Nov 7, 2019
@mattclay mattclay added this to To do in Testing Collections via automation Nov 7, 2019
@mattclay mattclay added feature This issue/PR relates to a feature request. and removed bug This issue/PR relates to a bug. labels Nov 19, 2019
@mattclay
Copy link
Member

I've changed this issue from a bug to a feature request, since the current behavior is expected.

@kareemhageali
Copy link

I noticed that this was unassigned and was wondering if I could work on this. @mattclay

@mattclay
Copy link
Member

@kareemhageali Before any work is done on this we need to figure out what help information should be available when outside a collection directory. Do you have any thoughts on that?

@ram-ibm
Copy link

ram-ibm commented Nov 16, 2020

Currently we are building the collection, uploading to ansible-galaxy and then installing it on a server before we can run ansible-test. Hoping that this issue will get worked on so we can run it from our local git repository that we develop out of please? Thanks.

@rrey
Copy link
Contributor Author

rrey commented Nov 16, 2020

@ram-ibm there are ways to work around this issue see the checkout performed here https://github.com/ansible-collections/community.grafana/blob/main/.github/workflows/ansible-test.yml

We force the tree to something expected by Ansible-test.
Other scm provides ways to do the same

mattclay added a commit to mattclay/ansible that referenced this issue Jan 27, 2022
* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
mattclay added a commit to mattclay/ansible that referenced this issue Jan 27, 2022
* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
mattclay added a commit to mattclay/ansible that referenced this issue Jan 27, 2022
* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
@ansibot ansibot added the has_pr This issue has an associated PR. label Jan 27, 2022
Testing Collections automation moved this from To do to Done Jan 27, 2022
mattclay added a commit that referenced this issue Jan 27, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves #64523
Resolves #67551
briantist pushed a commit to briantist/ansible that referenced this issue Feb 1, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
konstruktoid pushed a commit to konstruktoid/ansible-upstream that referenced this issue Feb 2, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
bcoca pushed a commit to bcoca/ansible that referenced this issue Feb 7, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551
@ansible ansible locked and limited conversation to collaborators Feb 10, 2022
mattclay added a commit to mattclay/ansible that referenced this issue Dec 16, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551

(cherry picked from commit de5f60e)
mattclay added a commit to mattclay/ansible that referenced this issue Dec 16, 2022
* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves ansible#64523
Resolves ansible#67551

(cherry picked from commit de5f60e)
mattclay added a commit that referenced this issue Dec 16, 2022
* ansible-test: Set max number of open files in containers to 10240 (#75498)

(cherry picked from commit e50ad6f)

* ansible-test - Add RHEL 9 support. (#76217)

* Move RHEL pip package install into function.
* Add RHEL 9 support to bootstrap script.
* ansible-test - Add RHEL 9 support.
* Add install and uninstall instructions for RHEL9 to paramiko tests
* Skip incidental_inventory_docker_swarm on RHEL 9.
* Update dnf tests for rhel9
* Fix prepare_http_tests on RHEL 9.
* fix RHEL9 Python discovery tests to match distro map
* Skip subversion test on RHEL 9.0b.

Co-authored-by: Matt Martz <matt@sivel.net>
Co-authored-by: Matt Davis <mrd@redhat.com>
(cherry picked from commit 730194e)

* fix support containers under podman (#76292)

* `podman inspect` falls back to a same-named image if the named container is not present; since eg `http-test-container` is both the name of the image and container, it wasn't working properly under podman in many instances. Switching to `docker|podman container inspect` limits the query to containers only for both podman and docker, allowing the support container detection/creation to work properly.

(cherry picked from commit abac141)

* ansible-test - Code cleanup. (#76540)

* Add missing typing imports.
* Remove unnecessary non-capturing group.
* Whitespace.
* Add type hints.
* Ignore PyCharm false positives.
* Remove Python 2.x plugin loading logic.
* Remove Python 2.x exception handling.
* Remove Python 2.x display logic.
* Add changelog.

(cherry picked from commit 4e70156)

* ansible-test - Fix type hints.

(cherry picked from commit d2daa67)

* ansible-test - Fix plugin loading.

This fixes a traceback when loading plugins that use dataclasses.

(cherry picked from commit 7e814dd)

* ansible-test - Remove AIX provisioning support. (#76747)

* ansible-test - Remove AIX provisioning support.
* Remove `skip/aix` integration test aliases.
* Remove build for AIX binary module.

(cherry picked from commit 3a89182)

* ansible-test: fix typo in validate-modules (#76765)

The correct error strategy for the to_text method is surrogate_or_strict

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
(cherry picked from commit a0f6747)

* ansible-test - Improve help for unsupported cwd. (#76866)

* ansible-test - Improve help for unsupported cwd.

* The `--help` option is now available when an unsupported cwd is in use.
* The `--help` output now shows the same instructions about cwd as would be shown in error messages if the cwd is unsupported.
* Add `--version` support to show the ansible-core version.
* The explanation about cwd usage has been improved to explain more clearly what is required.

Resolves #64523
Resolves #67551

(cherry picked from commit de5f60e)

* ansible-test - Validate collection ns and name.

Resolves #62079

(cherry picked from commit 26b43f4)

* ansible-test - Add default for Windows remotes.

(cherry picked from commit 18ed2c6)

* ansible-test - Clean up future boilerplate. (#76874)

* ansible-test - Clarify need for empty __init__.py
* ansible-test - Update code-smell boilerplate.
* Update code-smell boilerplate for core.
* Update future boilerplate test for ansible-test.

All ansible-test code (except for targets) and core-specific sanity tests now use the same boilerplate.

The test also checks for unwanted `__future__` and `metaclass` boilerplate.

* Relocate target tools to the correct directory.

Several tools used on target Python versions were incorrectly placed in the controller directory.

(cherry picked from commit d19b506)

* ansible-test - Remove obsolete display of MAXFD.

Use of ``subprocess.MAXFD`` only worked on Python 2.x, which is no longer supported.

(cherry picked from commit dc6b0d4)

* ansible-test - Code cleanup and refactoring. (#77169)

* Remove unnecessary PyCharm ignores.
* Ignore intentional undefined attribute usage.
* Add missing type hints. Fix existing type hints.
* Fix docstrings and comments.
* Use function to register completion handler.
* Pass strings to display functions.
* Fix CompositeAction handling of dest argument.
* Use consistent types in expressions/assignments.
* Use custom function to keep linters happy.
* Add missing raise for custom exception.
* Clean up key/value type handling in cloud plugins.
* Use dataclass instead of dict for results.
* Add custom type_guard function to check lists.
* Ignore return type that can't be checked (yet).
* Avoid changing types on local variables.

(cherry picked from commit a06fa49)

* ansible-test - Simplify type hints.

(cherry picked from commit af2b136)

* Support podman-remote in ansible-test (#75753)

(cherry picked from commit 7cb581e)

* docker_util: Handle error in JSON parsing (#77298)

While getting hostname from container, podman command
fails to return JSON so wrap exception and return
hostname as 'None'

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 1100289)

* ansible-test - Remove RHEL 9.0b support.

Support can be restored once RHEL 9 has been released.

(cherry picked from commit 55f90ba)

* ansible-test - Don't fail if network cannot be disconnected (#77472)

* Don't fail if network cannot be disconnected

* add clog frag

(cherry picked from commit 66c5844)

* ansible-test - Backport `InternalError`

NOTE: This is a partial backport, including only one new class.

(cherry picked from commit b960641)

* ansible-test - Fix subprocess management. (#77641)

* Run code-smell sanity tests in UTF-8 Mode.
* Update subprocess use in sanity test programs.
* Use raw_command instead of run_command with always=True set.
* Add more capture=True usage.
* Don't expose stdin to subprocesses.
* Capture more output. Warn on retry.
* Add more captures.
* Capture coverage cli output.
* Capture windows and network host checks.
* Be explicit about interactive usage.
* Use a shell for non-captured, non-interactive subprocesses.
* Add integration test to assert no TTY.
* Add unit test to assert no TTY.
* Require blocking stdin/stdout/stderr.
* Use subprocess.run in ansible-core sanity tests.
* Remove unused arg.
* Be explicit with subprocess.run check=False.
* Add changelog.
* Use a Python subprocess instead of a shell.
* Use InternalError instead of Exception.
* Require capture argument.
* Check for invalid raw_command arguments.
* Removed pointless communicate=True usage.
* Relocate stdout w/o capture check.
* Use threads instead of a subprocess for IO.

(cherry picked from commit 5c2d830)

* ansible-test - Add support for remote Ubuntu VMs.

(cherry picked from commit 6513453)

* ansible-test - Fix remote completion validation.

(cherry picked from commit e2200e8)

* ansible-test - Add multi-arch remote support.

(cherry picked from commit 2cc74b0)

* ansible-test - Enhance the shell command. (#77734)

* ansible-test - Add shell --export option.

* ansible-test - Support cmd args for shell command.

Also allow shell to be used without a valid layout if no delegation is required.

* ansible-test - Improve stderr/stdout consistency.

By default all output goes to stdout only, with the exception of a fatal error.

When using any of the following, all output defaults to stderr instead:

* sanity with the `--lint` option -- sanity messages to stdout
* coverage analyze -- output to stdout if the output file is `/dev/stdout`
* shell -- shell output to stdout

This fixes issues two main issues:

* Unpredictable output order when using both info and error/warning messages.
* Mixing of lint/command/shell output with bootstrapping messages on stdout.

* ansible-test - Add changelog fragment.

(cherry picked from commit fe349a1)

* ansible-test - Fix remote args restriction.

The platform-specific and global fallbacks were not working with the `--remote` option.

This regression was introduced by #77711

(cherry picked from commit 76ead1e)

* ansible-test - Fix shell target options handling.

(cherry picked from commit f933314)

* Refactor ansible-test integration tests. (#78168)

* Relocate update-ignore.py for easier re-use.

* Add script to ease collection testing.

* Skip ignore rewrite if file does not exist.

* Add integration test for the shebang sanity test.

* Fix ansible-test-no-tty integration test.

Previously the test only verified a TTY was not used if a TTY already existed.
This prevented the test from verifying behavior when run in CI.
Now the test creates a PTY before invoking ansible-test.

* Clean up ansible-test-docker integration test.

(cherry picked from commit f70cc2f)

* ansible-test - Fix TTY and output handling. (#78350)

(cherry picked from commit a3c90dd)

* ansible-test - Parse content config only once. (#78418)

(cherry picked from commit f2abfc4)

* ansible-test - Fix self-test change handling. (#78521)

(cherry picked from commit 9901665)

* ansible-test - Fix integration test target filter. (#78862)

- Allow disabled, unsupported, unstable and destructive integration test targets to be selected using their respective prefixes.
- Allow unstable tests to run when targeted changes are made and the ``--allow-unstable-changed`` option is specified (resolves #74213).

(cherry picked from commit d3d7785)

* [stable-2.13] ansible-test - Improve container management. (#79538)

* ansible-test - More flexible become support.

(cherry picked from commit 5666c6d)

* ansible-test - Add support for more remotes.

(cherry picked from commit 24d91f5)

* ansible-test - Enable ACLs on FreeBSD remotes.

This allows integration tests to switch from one unprivileged user
to another, sharing files between the users using ACLs.

(cherry picked from commit b63812b)

* ansible-test - Enable ACL support on more remotes. (#78299)

(cherry picked from commit 8bb20fe)

* ansible-test - Install `acl` on Alpine remotes. (#78303)

(cherry picked from commit 8565dea)

* ansible-test - Use sudo for all remotes. (#78310)

(cherry picked from commit f3f4ad9)

* ansible-test - Fix Ubuntu 20.04 bootstrapping. (#78551)

(cherry picked from commit d683c5b)

* ansible-test - Verify executables are executable. (#78606)

(cherry picked from commit ece85ab)

* ansible-test - Use --tmpfs to run containers. (#78605)

(cherry picked from commit 4187707)

* ansible-test - Remove Fedora 35 support. (#78720)

(cherry picked from commit 38a82a5)

* ansible-test - Fix container error handling. (#78739)

(cherry picked from commit 79f67ed)

* ansible-test - Improve container management. (#78550)

See changelogs/fragments/ansible-test-container-management.yml for details.

(cherry picked from commit cda16cc)

* ansible-test - Fix container detection. (#79530)

(cherry picked from commit 80d2f8d)

* Update test matrix symlinks. (#78737)

* Add remote platform symlinks.

These were already supported by ansible-test.
This change adds the symlinks for use in the CI test matrix.

* Remove obsolete AIX test symlink.

AIX was already removed from ansible-test.

(cherry picked from commit 62221a3)

* Use patched containers without VOLUME instruction.

* Make test suite compatible with older ansible.

* Fix compatibility with Python 3.8.

(cherry picked from commit 1d74369)

* ansible-test - fix warning to include image name (#79560)

(cherry picked from commit 0a12d8a)

* ansible-test - Fix target PyPI proxy config.

(cherry picked from commit dcc08ee)

* ansible-test - Fix `--prime-containers` and `--explain` (#79581)

* Remove unused code.
* Fix explain errors.
* Fix `--prime-containers` with docker on cgroup v2.

(cherry picked from commit da3b1d3)

* ansible-test - Support RSA SHA-1 for SSH clients.

(cherry picked from commit 75b60b1)

* ansible-test - Limit paramiko to < 2.9.0

(cherry picked from commit d658829)

* Add more retries to ansible-test-container test.

(cherry picked from commit f6c0e22)

* ansible-test - Improve container startup handling.

Also improve the ansible-test-container integration test:

 - Add coverage for the no-probe code path.
 - Add work-arounds for centos6 containers (to support backporting).
 - Avoid systemd debug when the container doesn't use cgroup.

(cherry picked from commit 04fc98c)

* Fix shebang test.

A false positive is generated by the test and a fix was never backported to stable-2.12.

Co-authored-by: Andrew Klychkov <aklychko@redhat.com>
Co-authored-by: Matt Davis <nitzmahone@users.noreply.github.com>
Co-authored-by: Dimitri Savineau <dsavinea@redhat.com>
Co-authored-by: Matt Martz <matt@sivel.net>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Martin Krizek <martin.krizek@gmail.com>
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 affects_2.13 feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
Development

Successfully merging a pull request may close this issue.

10 participants