mirror of
https://github.com/ansible/ansible.git
synced 2026-02-03 20:40:24 -05:00
ansible-galaxy - Change error to warning when no paths exist (#86341)
* ansible-galaxy - Change error to warning when no paths exist When listing collections, a warning is much more appropriate than an error for missing paths.
This commit is contained in:
parent
2cedaa24b6
commit
d16aaec92d
4 changed files with 11 additions and 10 deletions
2
changelogs/fragments/86341-galaxy-list-warn.yml
Normal file
2
changelogs/fragments/86341-galaxy-list-warn.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- ansible-galaxy - warn instead of raising an error when no valid role or collections paths exist (https://github.com/ansible/ansible/pull/86341)
|
||||
|
|
@ -1610,8 +1610,8 @@ class GalaxyCLI(CLI):
|
|||
display.warning(w)
|
||||
|
||||
if not path_found:
|
||||
raise AnsibleOptionsError(
|
||||
"- None of the provided paths were usable. Please specify a valid path with --{0}s-path".format(context.CLIARGS['type'])
|
||||
display.warning(
|
||||
"None of the provided paths were usable. Please specify a valid path with --{0}s-path.".format(context.CLIARGS['type'])
|
||||
)
|
||||
|
||||
return 0
|
||||
|
|
@ -1695,8 +1695,8 @@ class GalaxyCLI(CLI):
|
|||
display.warning(w)
|
||||
|
||||
if not collections and not path_found:
|
||||
raise AnsibleOptionsError(
|
||||
"- None of the provided paths were usable. Please specify a valid path with --{0}s-path".format(context.CLIARGS['type'])
|
||||
display.warning(
|
||||
"None of the provided paths were usable. Please specify a valid path with --{0}s-path.".format(context.CLIARGS['type'])
|
||||
)
|
||||
|
||||
if output_format == 'json':
|
||||
|
|
|
|||
|
|
@ -152,14 +152,13 @@
|
|||
- name: test that no json is emitted when no collection paths are usable
|
||||
command: "ansible-galaxy collection list --format json"
|
||||
register: list_result_error
|
||||
ignore_errors: True
|
||||
environment:
|
||||
ANSIBLE_COLLECTIONS_PATH: "i_dont_exist"
|
||||
|
||||
- name: Ensure we get the expected error
|
||||
- name: Ensure we get the expected warning
|
||||
assert:
|
||||
that:
|
||||
- "'{}' not in list_result_error.stdout"
|
||||
- "'{}' in list_result_error.stdout"
|
||||
- "'None of the provided paths were usable' in list_result_error.stderr"
|
||||
|
||||
- name: install an artifact to the second collections path
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import pytest
|
|||
from ansible import constants as C
|
||||
from ansible import context
|
||||
from ansible.cli.galaxy import GalaxyCLI
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.galaxy import collection
|
||||
from ansible.galaxy.dependency_resolution.dataclasses import Requirement
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
|
|
@ -201,12 +201,12 @@ def test_execute_list_collection_no_valid_paths(mocker, capsys, tmp_path_factory
|
|||
tmp_path = tmp_path_factory.mktemp('test-ÅÑŚÌβŁÈ Collections')
|
||||
concrete_artifact_cm = collection.concrete_artifact_manager.ConcreteArtifactsManager(tmp_path, validate_certs=False)
|
||||
|
||||
with pytest.raises(AnsibleOptionsError, match=r'None of the provided paths were usable.'):
|
||||
gc.execute_list_collection(artifacts_manager=concrete_artifact_cm)
|
||||
gc.execute_list_collection(artifacts_manager=concrete_artifact_cm)
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
|
||||
assert '[WARNING]: - the configured path' in err
|
||||
assert '[WARNING]: None of the provided paths were usable' in err
|
||||
assert 'exists, but it is not a directory.' in err
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue