-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate inventory from CLI early (#1307)
* Handle logging early in init_runner() * Fix pylint error for cmdline() * Validate inventory from command line * Add documentation for --inventory
- Loading branch information
Showing
6 changed files
with
159 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from ansible_runner.__main__ import valid_inventory | ||
|
||
|
||
def test_valid_inventory_file_in_inventory(tmp_path): | ||
""" | ||
Test a relative file name within inventory subdir. | ||
""" | ||
data_dir = tmp_path / "datadir" | ||
inv_dir = data_dir / "inventory" | ||
inv_dir.mkdir(parents=True) | ||
|
||
hosts = inv_dir / "hosts.xyz" | ||
hosts.touch() | ||
|
||
assert valid_inventory(str(data_dir), "hosts.xyz") == str(hosts.absolute()) | ||
|
||
|
||
def test_valid_inventory_absolute_path_to_file(tmp_path): | ||
""" | ||
Test an absolute path to a file outside of data dir. | ||
""" | ||
data_dir = tmp_path / "datadir" | ||
inv_dir = data_dir / "inventory" | ||
inv_dir.mkdir(parents=True) | ||
|
||
(tmp_path / "otherdir").mkdir() | ||
hosts = tmp_path / "otherdir" / "hosts.xyz" | ||
hosts.touch() | ||
|
||
assert valid_inventory(str(data_dir), str(hosts.absolute())) == str(hosts.absolute()) | ||
|
||
|
||
def test_valid_inventory_absolute_path_to_directory(tmp_path): | ||
""" | ||
Test an absolute path to a directory outside of data dir. | ||
""" | ||
data_dir = tmp_path / "datadir" | ||
inv_dir = data_dir / "inventory" | ||
inv_dir.mkdir(parents=True) | ||
|
||
(tmp_path / "otherdir").mkdir() | ||
hosts = tmp_path / "otherdir" | ||
hosts.touch() | ||
|
||
assert valid_inventory(str(data_dir), str(hosts.absolute())) == str(hosts.absolute()) | ||
|
||
|
||
def test_valid_inventory_doesnotexist(tmp_path): | ||
""" | ||
Test that a bad inventory path returns False. | ||
""" | ||
assert valid_inventory(str(tmp_path), "doesNotExist") is None |