Commit graph

11125 commits

Author SHA1 Message Date
Brian Coca 35ff4ea95b
warn on walking through pathing issues (#74514)
* warn show pathing issues when wallking through provided paths

  moved issues from msg to actual warnings AND a specific return field

  fixes #25314

Co-authored-by: Sam Doran <sdoran@redhat.com>
2021-05-06 16:14:33 -04:00
Sam Doran 55b401a3e7
pause - ensure control characters are always set appropriately (#74568)
* pause - ensure control characters are always set appropriately

On some systems, curses.tigetstr() returns None, which does not work as a control character.

* Add unit tests

* Sort imports

* Skip on older Python

This is an action plugin and only runs on the controller, so no need to test of Python 2. Making
the import hackery work on Python 2 would required some more work which I am not sure is
worth it since we are moving away from Python 2 support on the controller.

* Make the tests work on Python 2 and 3
2021-05-06 15:09:26 -04:00
Matt Clay 07fb6f7547 Fix imports for the previous commit.
Also add a changelog entry.
2021-05-05 18:56:29 -07:00
Matt Clay 92c40f6365 Relocate change classification files. 2021-05-05 18:56:29 -07:00
Matt Clay 5dfc7ee078 Remove Shippable CI provider from ansible-test. 2021-05-05 17:42:13 -07:00
Matt Clay c48f80d062 Rename hacking/shippable to hacking/azp.
References to Shippable were changed to Azure Pipelines.

Also remove rebalance.py as it does not work with Azure Pipelines due to the required data not being present.
2021-05-05 17:21:14 -07:00
Matt Clay df2ae06d46 Fix ansible-test imports and paths after refactor.
Also include a changelog entry covering this commit and the previous.
2021-05-05 16:20:15 -07:00
Matt Clay bb3904d299 Reorganize command implementations.
This commit only renames existing files.

Changes to adapt imports will occur in a follow-up commit.
2021-05-05 16:20:15 -07:00
Abhijeet Kasurde 38dd49eb00
ansible-inventory: Handle exception in toml parsing (#74486)
Handle stacktrace raise while parsing inventory in toml format

Fixes: #74404

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-05-05 14:12:52 +05:30
Matt Clay 68e9e1c999
Switch incidental OS X tests to macOS. (#74564)
* Switch incidental OS X tests to macOS.
* Rename incidental osx.sh to macos.sh.
2021-05-04 11:46:46 -07:00
David Shrewsbury c6fda9fc1a
[coverage] improve test coverage for together lookup (#74549) 2021-05-04 11:41:22 -04:00
David Shrewsbury 4f0a9488bb
[coverage] improve test coverage for indexed_items lookup (#74548) 2021-05-04 11:41:02 -04:00
David Shrewsbury 244bf9c640
[coverage] improve test coverage for vars lookup (#74546) 2021-05-04 11:39:04 -04:00
Brian Coca 30912b6a47
dont specify default for port, allow ssh/config (#74526)
* dont specify default for port, allow ssh/config

 also added general note on how defaults work.

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Sam Doran <sdoran@redhat.com>
2021-05-04 11:09:05 -04:00
Ruairidh MacLeod d101009688
facts - set correct OS family for Rocky Linux (#74530) 2021-05-04 10:14:13 -04:00
Sam Doran 728e43bc59 callback_default test - Reduce sleep time to correct CI failures
For unknown reasons, these tests started failing recently because the results
from testhost11 are being returned before testhost10, but only when coverage is
enabled.

Setting the initial host sleep time to 0 fixes this failure.

ci_coverage
2021-05-03 17:55:10 -07:00
Matt Clay fb0d5609cb
Code cleanup in ansible-test. (#74529)
* Fix get_available_python_versions calls.
* Make run_playbook vars optional.
* Use ansible_pipelining in inventory.
* Fix type hint.
* Fix order of conditional evaluation.
* Remove unused ibmi platform.
* Add changelog fragment.
2021-04-30 18:50:00 -07:00
Matt Clay ca507ff477 Integration test fixes. 2021-04-30 17:59:28 -07:00
Harm Geerts 9bd70045c9
Fix BaseFileCacheModule#keys to respect prefix (#72789)
* Fix BaseFileCacheModule#keys to respect prefix

Change:
- Previously BaseFileCacheModule#keys would return keys with the cache
  prefix. These keys are impossible to retrieve from the cache without
  removing the prefix or using the cache without a prefix.
  Now it removes the prefix from the key and only returns keys that
  share the same prefix as the cache.

Test Plan:
- New unit tests

* Add explicit BaseFileCacheModule#keys test

Test that files that do not match the cache prefix are ignored.
Test that the prefix is removed from the cache key.
2021-04-30 15:28:28 -04:00
Rick Elrod d8c20a73a4
[ansible-test] Add Fedora 34, update Fedora 33 (#74506)
Change:
- Added Fedora 34 container image to docker.txt
- Dropped Fedora 32 from CI
- Added Fedora 34 to CI
- Updated Fedora 32 and 33 containers for ssh-related fixes
- Move cron fix from 698eae3f3d into
  cron_setup and make it more generic; it can affect modern distros too.

Test Plan:
- ci_complete

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-30 11:35:12 -05:00
Maxim Masiutin 6ea81b84ed
apt_key - correct error message about the failure to import a 'gpg' (#74476) 2021-04-30 12:06:38 -04:00
Maxim Masiutin d147c1ef1f
apt_key test - Change the URL of the GPG key to S3 and remove it from the repo (#74483) 2021-04-30 10:44:50 -04:00
Matt Clay a30c55f68a Remove deprecated common.removed module_util.
Tests have been updated to reflect its removal as well.
2021-04-29 16:07:56 -07:00
Abhijeet Kasurde 1a7923e318
pip: Idempotency tests (#74473)
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: David Moreau Simard <dmsimard@redhat.com>
2021-04-29 15:14:18 -04:00
David Shrewsbury f1a5c411d9
Fix sequence lookup message and add tests (#74472)
* add test for bad kv arg value
* add simple form parsing tests and make error messages the same
* add changelog
2021-04-29 15:12:23 -04:00
Sam Doran 74b2add460
paramiko_ssh - mark connection as connected when successful (#74459)
* Remove unused import from test
2021-04-29 15:11:02 -04:00
Matt Clay baa371e7b5 Add comments to keep collection loader in sync. 2021-04-28 17:45:42 -07:00
Brian Coca 3cff54d69b
Fix missing delegate display (#74370)
* dont rely on vars, task already gives us info
* ensure we always display delegation in host label
* also added parens with ansible_host to show  target host vs resolved host
* delegating to self is not delegating
* delegated vars restoration for backwards compat
* tests need mock task with delegate_to
2021-04-28 13:24:38 -04:00
Maxim Masiutin 3bc2e7783c
Binary GnuPG keys downloaded via URLs by the 'ansible.builtin.apt_key' module were corrupted so 'gpg' could not import them (https://github.com/ansible/ansible/issues/74424) (#74474) 2021-04-28 10:41:14 -04:00
Anatoly Pugachev 04e57d28e3
[facts] add hpux fc info, refactor aix and solaris code (#57406)
* correctly parse device from string
* check for command presence before running them
* check for command presence and return code for solaris and aix as well
* add changelog
2021-04-28 10:17:19 -04:00
Logistic Bot 7099657dd7
Basic: don't call lstat when check_mode (#64279)
While mode is specified in check_mode, don't call lstat.
Since file may not present.

Fixes: #61185
2021-04-28 13:47:03 +05:30
Matt Clay 877e5b3dfe Fix ansible-test AZP build lookup. 2021-04-27 18:32:46 -07:00
Matt Clay be7de9844e Remove obsolete Shippable specific scripts.
Also remove some other unncessary code from CI scripts.
2021-04-27 17:11:09 -07:00
Matt Clay c4e76a7f80 Add collection config support to ansible-test. 2021-04-27 12:09:34 -07:00
Sam Doran 62cba4a6ad incidental_setup_rabbitmq test - Use official repo for rabbitmq-erlang
Previously it was hosted on bintray, but that service is shutting down on May 1. Using the new
repository also required using a newer version of RabbitMQ.
2021-04-27 10:02:27 -07:00
Matt Clay 8223dfccbe ansible-test - Improve __main__ checks. 2021-04-27 09:00:26 -07:00
Rick Elrod fcbf5c3185
[module_utils] make to_bits actually return (#74409)
Change:
- Instead of returning the `str` type, return the value that was
  calculated.

Test Plan:
- New unit tests.

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-27 17:15:24 +02:00
Matt Clay cb7f4f1971 Fix pypi-test-container port conflict. 2021-04-26 14:41:02 -07:00
Matt Clay ecc5a53288
Update default containers to 3.4.0. (#74415)
* Update default containers to 3.4.0.

The 3.4.0 containers use Python 3.6 (the system Python) for `/usr/bin/python3`.

Python 3.9 continues to be the default Python version selected by `ansible-test` for these containers.

* Fix shebang on build-ansible.py.

Using `python` instead of `python3` allows `ansible-test` python interception and requirements install to function.
2021-04-25 21:25:32 -07:00
Alexandre Garnier 8698855ffd
Case-insensitive set theory filters (#74256)
Fixes #74255

* Fix call to 'unique(case_sensitive=False)' triggering error when falling back to Ansible's version which **is** case-sensitive
* Test multiple situations of 'unique' filter errors with fallback not handling specific parameters

Signed-off-by: Rick Elrod <rick@elrod.me>
Co-authored-by: Rick Elrod <rick@elrod.me>
2021-04-23 12:44:43 -05:00
Fernando Correia 7fd989d008
Detect Homebrew on Mac M1 (Apple Silicon) (#74378)
Homebrew's default install location for macOS on ARM is /opt/homebrew.
Source: https://docs.brew.sh/FAQ

On a Mac M1 (Apple Silicon), homebrew will be installed at
/opt/homebrew/bin/brew.
2021-04-23 11:01:52 -04:00
Matt Clay 6cfe36fa1f
Set ansible-test min controller Python to 3.8. (#74395)
- Version neutral sanity tests now require Python 3.8 or later.
- Unit tests for controller-only code now require Python 3.8 or later.
2021-04-23 00:26:19 -07:00
Matt Clay f541c0af23
Update ansible-test default test container. (#74393)
* Update ansible-test default test container.
* Switch generic Python tests from 3.6 to 3.9.
2021-04-22 23:23:16 -07:00
Alexander Sowitzki ff88a2a06d Fix combinated run of unarchive and uri tests under centos 6
The unarchive integration test installs pinned packages via pip,
the uri test installs them from system packages. This explodes.
PR lets unarchive uninstall packages after test ran.
2021-04-22 17:09:10 -07:00
Paul Arthur 7b5dad2321 validate-modules: don't error on valid Ansible YAML in EXAMPLES 2021-04-22 12:42:47 -07:00
Matt Clay 14ff5e213c Fix ansible-test docker container IP detection. 2021-04-22 11:54:54 -07:00
Matt Martz bf7d4ce260
Abstract away libyaml details into yaml utils (#72607)
* Add yaml utils file and use it

* Linting fix and missing import

* Abstract a few more details

* Parser imports

* Don't use CSafeDumper in AnsibleDumper

* Move and use convert_yaml_objects_to_native when libyaml is present

* yaml_load and yaml_dump, instead of safe_*

* re-use HAS_LIBYAML from utils.yaml

* add changelog fragment

* Address recent changes

* Use representer instead of recursive type converter

* Restore needed import

* move yaml utils to module_utils

* Properly guard imports

* Update from_yaml(_all)? to handle text wrappers with CSafeLoader

* Use yaml utils for legacy_collection_loader

* Add HAS_YAML, and ignore pylint issue

* oops

* GPL->BSD
2021-04-21 16:47:03 -05:00
Brian Coca 6418f368e3
Fix pb subs collapse (#74301)
* fix subdir parsing for plays

  fixes #74283

  Co-authored-by: Nikolaos Kakouros <nkak@kth.se>
2021-04-21 17:27:41 -04:00
Matt Martz a3e7cf0110
Update alpine repo to community for libuser (#74374) 2021-04-21 16:20:50 -05:00
Rick Elrod 738132da95
[ansible-test] add freebsd/13.0 remote (#74328)
Change:
- FreeBSD 13.0 was released on the 13th, add it to ansible-test.

Test Plan:
- ci_complete

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-21 15:13:41 -05:00
elara-leitstellentechnik 437a08eb6d
Map Debian 8 to Python 2 (#74152)
* Map Debian 8 to Python 2

If Python 3 is installed on Debian 8 Ansible cannot run, as the version
is too old (3.4)

* Add integration test for python interpreter discovery on Debian 8

* fix test issue on Debian 9, add changelog

* un"fix" not broken test :D

Co-authored-by: Fabian Klemp <fabian.klemp@elara-gmbh.de>
Co-authored-by: Matt Davis <mrd@redhat.com>
2021-04-20 15:28:24 -07:00
Matt Clay e6af2d6827 Fix ansible-test coverage traceback when no data.
If no coverage directory exists, ansible-test coverage would traceback.

Now it silently continues just as if the directory was present but empty.
2021-04-20 14:33:05 -07:00
Amin Vakil 49d4442378
Add umask option to user module (#73821)
* Add umask option to user module

* Fail on setting both umask and local: True

* Add integration test

* Add changelog

* Run integration tests only if HOME_MODE is not set

* Run integration tests only on Linux

Co-authored-by: Matt Clay <matt@mystile.com>
2021-04-20 12:01:56 -04:00
Brian Coca 4494ef3a9d
defend against bad or missing crypt (#74304)
* defend against bad or missing crypt

  fixes #74279
2021-04-20 11:47:34 -04:00
David Shrewsbury d44eb03f49
Remove include from tests (#74330) 2021-04-20 11:19:29 -04:00
Brian Coca 2296da95a2
fix module schema (#74295)
* fix module schema

  not out of date hardcoded list anymore, uses 'current + 4' to
  set valid deprecation targets

Co-authored-by: Matt Clay <matt@mystile.com>
2021-04-20 10:02:39 -04:00
Rick Elrod 698eae3f3d [tests] Work around vixie-cron and PAM issue, el6
Change:
- This works around an issue that causes the cron test to fail sometimes
  on el6.

Test Plan:
- ansible-test integration cron --docker centos6

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-19 20:41:30 -07:00
Rick Elrod 9f1513d4c0 [become] Add Solaris chmod ACL fallback
Change:
- Newer Solaris drops setfacl. Add a fallback for its chmod ACL syntax.

Test Plan:
- New units

Tickets:
- Fixes #74282

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-19 20:28:57 -05:00
Rick Elrod 7d64aebdd3 [become] Fix solaris permissions regression
Change:
- Regression introduced in #70785
- When macOS chmod ACL syntax is used, Solaris-derived chmods return
  with a status of 5. This is also used for our sshpass handling,
  because sshpass will return 5 on auth failure. This means on Solaris,
  we incorrectly assume auth failure when we reach this branch of logic
  and try to run chmod with macOS syntax.
- We now wrap this specific use of chmod in an exception handler that
  looks for AnsibleAuthenticationFailure and skips over it. This adds
  another authentication attempt (something we normally avoid to prevent
  account lockout), but seems better than the regression of not allowing
  other fallbacks to be used.
- Without this patch, if setfacl fails on Solaris (and sshpass is used),
  we do not try common_remote_group or world-readable tmpdir fallbacks.

Test Plan:
- New unit

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-19 20:28:57 -05:00
Matt Clay 7786dbbdc1 Split out module/module_utils unit test execution.
- Unit tests for `modules` and `module_utils` are now limited to importing only `ansible.module_utils` from the `ansible` module.
- Unit tests other than `modules` and `module_utils` are now run only on Python versions supported by the controller (Python 3.8+).
- Unit tests are now run in separate contexts (`controller`, `modules`, `module_utils`), each using separate invocations of `pytest`.
2021-04-19 15:44:58 -07:00
Matt Clay 9ba6cf9a72 Relocate misplaced unit tests. 2021-04-16 22:23:40 -07:00
Matt Clay 277a06f641
Clean up ansible-test cloud plugins. (#74322)
- Improve code reuse.
- Add missing type hints, fix existing ones and convert them to PEP 484 style.
- Add missing imports and clean up existing ones.
- Add missing docstrings and clean up existing ones.
2021-04-16 18:49:22 -07:00
Matt Martz 17237c1d88
Deprecate Py2.6 support for target nodes (#74165) 2021-04-16 11:42:29 -05:00
Brian Coca 07939b04f3
[2.12] 'attributes' (#73707)
* wip 'attributes'

* added version added tests

* syntzx

* not bile

* correztlys merges

* moved desc to frag

* simpler as dict

* unused

* clog

* Update lib/ansible/utils/plugin_docs.py

Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>

* unnoted

* added action plugins

* longer list

* add sttri schema

* huh?

* itsdict

* dictit

* yolo

* gnore for now

* moar attribs

* allow extras

* positive

* added loop, documented 'imports'

* support is now none/partial/full

* import_playbook is outside host loop

Co-authored-by: Jacob Floyd <cognifloyd@gmail.com>
2021-04-16 18:17:00 +02:00
Alex Willmer 185d410316
Factor out host_label() in default stdout callback plugin (#73814)
This simplifies rendering the hostname (or hostname+delegated host) in
the default callback module, and reduces code duplication

I've chosen not move where in each handler the host label is rendered,
in case subsequent operations has side effects. However I'm happy to
change that if considered safe.

I've chosen not to change the formatting operator used (%), to avoid
changes in rendering that might result.

Signed-off-by: Alex Willmer <alex@moreati.org.uk>
2021-04-16 11:12:25 -04:00
Amin Vakil a7c8093ce4
[2.12] Add accept_newhostkey option to git module (#73819)
* Add integration test for accept_newhostkey option

* Add changelog
2021-04-16 11:10:35 -04:00
Jordan Borean 019452dda7
uri - fix traceback on multipart-form int value (#74302) 2021-04-16 11:09:31 -04:00
Amin Vakil fdee5ca16d
Add cacheonly option to yum and dnf modules (#73820)
* Add integration test

* Add changelog

Co-authored-by: Matt Clay <matt@mystile.com>
2021-04-16 11:08:52 -04:00
Amin Vakil 0c101f3f76
Add epoch_int in date_time facts (#73822)
* Add unit test

* Add changelog
2021-04-16 11:03:07 -04:00
Martin Krizek 7fecb7ccc3
Actually run blocks/finalized_task test (#74291) 2021-04-16 08:04:11 +02:00
Rick Elrod 7ef3dc2b8b
[controller ansiballz] escape directory regex (#74270)
Change:
- We were passing a directory name directly to re.compile().
  If the directory isn't valid regex (or is) this can have odd side
  effects, such as crashing.
- Fix a few other similar cases, but less likely to be a real issue.

Test Plan:
- New test

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-15 17:06:58 -05:00
Matt Martz 1082e2ab79
Catch errors getting filters (#74127)
* Catch errors getting filters, and fail

* Add changelog

* Switch to warnings instead of errors, to match other plugin loader behavior

* Add tests

* Handle collections
2021-04-15 15:51:41 -05:00
Martin Krizek 664531d7d6
Prevent ansible_failed_task from further templating (#74290)
* Prevent ansible_failed_task from further templating

Fixes #74036

* Add changelog
2021-04-16 05:48:57 +10:00
Brian Coca c6945de899
Ini fixes (#74285)
* avoid 'mixed' param formats

* added tests

* clog

* fixed alignment
2021-04-16 05:36:49 +10:00
Brian Coca b91749d671
fix config manager list loption with choices (#74267)
fixes #74225

  Co-authored-by: Kim Nørring <github@norring.dk>
2021-04-16 05:07:43 +10:00
Brian Coca 0a7670d1f7
deprecated include (#71262)
* deprecated include

  Update lib/ansible/modules/_include.py
  updated version numbers in schema check (real fix in separate PR)

Co-authored-by: flowerysong <junk+github@flowerysong.com>
Co-authored-by: Matt Clay <matt@mystile.com>
2021-04-15 14:19:04 -04:00
Brian Coca 84e473a26e
All lookups ported to config system (#74108)
* all lookups to support config system

 - added get_options to get full dict with all opts
 - fixed tests to match new error messages
 - kept inline string k=v parsing methods for backwards compat
 - placeholder depredation for inline string k=v parsing
 - updated tests and examples to also show new way
 - refactored and added comments to most custom k=v parsing
 - added missing docs for template_vars to template
 - normalized error messages and exception types
 - fixed constants default
 - better details value errors

Co-authored-by: Felix Fontein <felix@fontein.de>
2021-04-13 15:52:42 -04:00
Brian Coca b3b1dde648
various fixes to command (#74212)
* various fixes to command

  - Updated splitter to allow for all expected args in ad-hoc
  - Ensure we always return the returns we promissed to always return (i.e stderr/stdout)
  - Updated docs to clarify creates/removes precdence in checking
  - Removed abspath from chdir to allow reporting to handle symlinks correctly
  - Corrected tests to new output messages

Co-authored-by: Felix Fontein <felix@fontein.de>
2021-04-13 12:52:29 -04:00
abikouo 29aea9ff34
constructed - Add keyed_groups suboptions 'default_value' and 'trailing_separator' (#74005)
* Support omitting the trailing separator when a dictionary key's value is an empty string

* Support a default value when the value used in the group name is an empty string

* Add tests

* change log
2021-04-13 11:59:50 -04:00
David Shrewsbury 5e55af2f02
[test coverage] Add tests for set_stats (#74243)
* satisfy the all-knowing, ever present God of Sanity and use 'grep -c' vs. 'wc -l'
2021-04-13 11:43:53 -04:00
David Shrewsbury 93fdba7013
[bugfix][coverage] find module should consider file size with file_type=any (#74241)
* add changelog
* fix cl text
* Update changelogs/fragments/74241-find-checks-size-with-any.yml

Co-authored-by: Rick Elrod <rick@elrod.me>
2021-04-13 11:41:44 -04:00
Rick Elrod fa0bccf6a1
[module_utils.distro] Fall back to bundled (#74229)
Change:
- When a "distro" package exists in PYTHONPATH but isn't what we expect,
  fall back to our own vendored one and use it. This prevents a
  traceback if someone has some random thing that provides "distro" but
  isn't actually the "distro" library we need.

Test Plan:
- new tests

Tickets:
- Fixes #74228

Signed-off-by: Rick Elrod <rick@elrod.me>

* nuke playbook test file

Signed-off-by: Rick Elrod <rick@elrod.me>

* test fixes

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-13 11:27:52 -04:00
Rick Elrod aae5bc5b9e
[advanced_host_list] 100% coverage + fix a bug (#74227)
Change:
- Tests for advanced_host_list; it is now at 100% coverage.
- There was a typo (host vs hostnames) where when the host pattern
  failed to parse, instead of treating the name as a literal as
  intended, it would trigger UnboundLocalError. This didn't fatal
  as there's a global "Exception" handler below, but it did lead to
  an ugly error and incorrect behavior.

Test Plan:
- New tests
- Local experimenting

Signed-off-by: Rick Elrod <rick@elrod.me>

* changelog

Signed-off-by: Rick Elrod <rick@elrod.me>

* fix tests

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-13 11:26:29 -04:00
Rick Elrod bd1acb74c8
[playbook/play.py] Increase error test coverage (#74217)
Change:
- Mostly increase error coverage for various conditions in play.py
- Also fix a string in an error, where get_name() was called before
  self.name was read in, so get_name() was always ''.

Test Plan:
- new tests

Signed-off-by: Rick Elrod <rick@elrod.me>

* Fix regex for py2 and py3

Signed-off-by: Rick Elrod <rick@elrod.me>

* py2 hates me

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-13 11:22:02 -04:00
Rick Elrod 19aeb4706d
[conditional] Remove support for bare variables (#74208)
Change:
- Variables used in ``when`` conditionals are no longer parsed and
  attempted to be converted to booleans. All non-empty strings are
  considered true (empty strings, false).

Test Plan:
- Updated existing tests
- Added a bunch of new tests with various kinds of truthy/falsy
  values.

Tickets:
- Fixes #74134

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-13 11:12:10 -04:00
Sloane Hertel ce96591313
Remove deprecated cache interfaces (#74198)
* update unit test
* Remove FactCache 'update' method
2021-04-13 11:08:20 -04:00
Brian Coca 39bd8b99ec
async_wrapper more info on end (#74199)
be consistent on information returned
 normalize 'return functions'
 fix unit test
 add a bit more context on some failures
2021-04-13 10:30:13 -04:00
Rick Elrod f38d03f6fb [ansible-test] nuke virtualenv-isolated.sh
Change:
- This isn't used in our tests, so the suggestion was to just remove
  it.

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-12 15:09:18 -07:00
Matt Clay b752d07163 Overhaul ansible-test container management.
This brings ansible-test closer to being able to support split controller/remote testing.
2021-04-12 12:40:36 -07:00
Brian Coca 9f856a4964
config lookup can query plugin settings (#74186)
* config lookup can query plugin settings
2021-04-12 15:30:25 -04:00
Rick Elrod 3504f4c45f
[yum] report upgraded multiarch packages (#73548)
Change:
- Previously when the same package name was installed twice under
  different architectures, we only reported it once in changes.updated.
- This was the result of using a dict internally and keying on package
  name alone.
- This change still keys on package name but turns the values into lists
  which can contain multiple packages per name.

Test Plan:
- Added a lot of tests around multi-arch support
- Added some tests around virtual provides as well

Tickets:
- Fixes #73284

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-10 02:36:20 -05:00
Rick Elrod 8c413749fc
[test/support/docker_swarm] remove deprecation (#74203)
Change:
- Remove deprecation block from support test code

Tickets:
- Fixes #74146

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-09 22:38:33 -05:00
Guillermo Adrián Molina 9c506031fa
Solaris: Correct version check in svcadm_supports_sync API (#73860)
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-04-10 08:02:58 +05:30
Rick Elrod ef554d0378
[playbook] error on empty, error on 'include' (remove two deprecations) (#74172)
Change:
- Remove two deprecated features
- We now error if a playbook is an empty list instead of just skipping
- We now error if using 'include' instead of 'import_playbook'

Test Plan:
- Added new tests for new errors

Tickets:
- Fixes #74133

Signed-off-by: Rick Elrod <rick@elrod.me>

* sanity & changelog

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-09 10:28:24 -04:00
Matt Clay becf941673 Add PyPI proxy container for tests on Python 2.6. 2021-04-08 15:47:23 -07:00
Rick Elrod d7df8a4484
[cron] Remove deprecated features (#74197)
Change:
- Require name always
- Drop 'reboot' parameter in favor of 'special_time: reboot'

Test Plan:
- CI

Tickets:
- fixes #74132

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-08 15:50:27 -04:00
David Shrewsbury d5ce6e6bed
Increase test coverage for command module (#74183) 2021-04-08 15:24:01 -04:00
Brian Coca b07a78b4ba
remove deprecated connection password functions (#74155)
* they were moved from connecitons to become plugins
* fixed clog, removed sanity ignore
* fixed tests to use become functions
2021-04-08 15:11:06 -04:00
Brian Coca 45ab6fddf3
removed task parameters (#74154)
* fixed clog
* removed ignore
* fix typose
* removed ignore
2021-04-08 15:09:45 -04:00
Sam Doran 4df9ea86c2 ansible-test - change diff mathching regexp so prefixes are optional
The `a/` and `b/` prefixes can be disabled in the `git diff` output by setting
`diff.noprefix` to `true`. The output is still a valid diff, but `ansible-test` would
raise an exception since without the prefixes, it thought the diff line was invalid.
2021-04-07 12:50:39 -07:00
Sam Doran 7b79b69369
ansible-test - ensure trailing separator is added for connection unit test target (#74176)
For connection units tests, if the `__init__.py` file is modified, the trailing separator was
not added, making the target invalid.
2021-04-07 13:27:09 -04:00
Matt Clay 459ea5a4a4
Update test containers in ansible-test. (#74166)
* Update distro test containers to version 2.0.2.

* Update the default test containers.
2021-04-06 15:52:56 -07:00
David Shrewsbury d1842afd59
ansible-inventory - add coverage tests (#74130) 2021-04-06 12:14:54 -04:00
David Shrewsbury 1cacf933b7
lineinfile - improve test coverage (#74122) 2021-04-06 12:11:10 -04:00
Rick Elrod 3a74f7ea22
prep for 2.12 version bump (#74126)
* prep for 2.12
* Add 2.12 deprecations and sort ignore.txt list.

Signed-off-by: Rick Elrod <rick@elrod.me>
2021-04-05 16:56:53 -05:00
Matt Clay f436058fad Add ansible-test constraint for decorator. 2021-04-05 11:56:38 -07:00
Matt Clay 4e2da0f894 Add ansible-test six constraint for Python 2.6. 2021-04-01 14:02:46 -07:00
Brian Coca f9f839fa08
Fix debug factsetter (#74067)
* prevent debug from setting namespaced facts as tlv
* also added tests
2021-03-31 09:30:09 -04:00
Matt Clay b75844af45 Fix ansible-test coverage exporting.
ci_complete
ci_coverage
2021-03-30 14:30:15 -07:00
Amin Vakil 846c2d1ed3
Fix comment in iptables unit test (#74061) 2021-03-30 16:11:12 -04:00
Matt Davis 454c7e37ec
nonzero exit code on ansible galaxy collection verify failures (#74051) 2021-03-29 13:06:02 -07:00
Alexander Sowitzki 1527078a8f
pause - do not continue with '\r' when timeout is set (#74030)
Original function of pause was, to only allow user input
(finished with enter) when no timeout was set. This restores
the behaviour.
2021-03-29 15:39:42 -04:00
Matt Davis a84c1a5669
add --offline option to galaxy collection verify (#74040)
* --offline allows in-place verify for installed collections with manifests
* manifest hash, collection name, version, and path are now always displayed
* test updates
2021-03-29 09:47:15 -07:00
Felix Fontein af7f3fc266
Revert "Add duplicated set filter and documentation (#72729)" (#74053)
This reverts commit 99a6627c60.

* ci_complete
2021-03-27 20:28:28 -05:00
Matt Martz 88d6a72178
Temporarily disable strategy units (#74048) 2021-03-26 19:10:00 -07:00
Baptiste Mille-Mathias 99a6627c60
Add duplicated set filter and documentation (#72729)
Co-authored-by: Kerry <kerry@flatline-studios.com>
2021-03-27 00:18:55 +01:00
Brian Coca 4a82e2c486
Fix setup subset (#74022)
* fix error msg on bad subset

* added test
* handle more raised but not handled fact exceptions
2021-03-26 12:43:16 -04:00
Felix Fontein 940b7af7d8
argspec validation - fix apply_defaults (#74029)
* Add test
2021-03-24 19:17:07 -04:00
Sam Doran fa1b52ce55
dnf test - update libmodulemd when updating python3-dnf (#74025)
The dependency version is set too low in the latest version of the package.

https://bugzilla.redhat.com/show_bug.cgi?id=1942236
2021-03-24 15:49:57 -04:00
Sam Doran c4e211a429 apt_key - update key ID and URL used in test
The GPG key in getfedore.org/static/fedora.gpg changed and caused the test to fail. Update
to using the new key ID and save the GPG file in our S3 to prevent spontaneous changes/breakage.
2021-03-23 13:55:40 -07:00
Felix Fontein a1ece49006
Add integration tests for add_collection_to_versions_and_dates(), and extend ansible-doc tests (#73601)
* Add add_collection_to_versions_and_dates integration tests.

* Add doc fragment tests with fragments from other collections.

* Remove trailing whitespace (Python 2's json.dump inserts some).

* Use ' ' instead of '\s'.
2021-03-24 05:30:57 +10:00
Sam Doran abacf6a108
Use ArgumentSpecValidator in AnsibleModule (#73703)
* Begin using ArgumentSpecValidator in AnsibleModule

* Add check parameters to ArgumentSpecValidator

Add additional parameters for specifying required and mutually exclusive parameters.
Add code to the .validate() method that runs these additional checks.

* Make errors related to unsupported parameters match existing behavior

Update the punctuation in the message slightly to make it more readable.
Add a property to ArgumentSpecValidator to hold valid parameter names.

* Set default values after performining checks

* FIx sanity test failure

* Use correct parameters when checking sub options

* Use a dict when iterating over check functions

Referencing by key names makes things a bit more readable IMO.

* Fix bug in comparison for sub options evaluation

* Add options_context to check functions

This allows the parent parameter to be added the the error message if a validation
error occurs in a sub option.

* Fix bug in apply_defaults behavior of sub spec validation

* Accept options_conext in get_unsupported_parameters()

If options_context is supplied, a tuple of parent key names of unsupported parameter will be
created. This allows the full "path" to the unsupported parameter to be reported.

* Build path to the unsupported parameter for error messages.

* Remove unused import

* Update recursive finder test

* Skip if running in check mode

This was done in the _check_arguments() method. That was moved to a function that has no
way of calling fail_json(), so it must be done outside of validation.

This is a silght change in behavior, but I believe the correct one.

Previously, only unsupported parameters would cause a failure. All other checks would not be executed
if the modlue did not support check mode. This would hide validation failures in check mode.

* The great purge

Remove all methods related to argument spec validation from AnsibleModule

* Keep _name and kind in the caller and out of the validator

This seems a bit awkward since this means the caller could end up with {name} and {kind} in
the error message if they don't run the messages through the .format() method
with name and kind parameters.

* Double moustaches work

I wasn't sure if they get stripped or not. Looks like they do. Neat trick.

* Add changelog

* Update unsupported parameter test

The error message changed to include name and kind.

* Remove unused import

* Add better documentation for ArgumentSpecValidator class

* Fix example

* Few more docs fixes

* Mark required and mutually exclusive attributes as private

* Mark validate functions as private

* Reorganize functions in validation.py

* Remove unused imports in basic.py related to argument spec validation

* Create errors is module_utils

We have errors in lib/ansible/errors/ but those cannot be used by modules.

* Update recursive finder test

* Move errors to file rather than __init__.py

* Change ArgumentSpecValidator.validate() interface

Raise AnsibleValidationErrorMultiple on validation error which contains all AnsibleValidationError
exceptions for validation failures.

Return the validated parameters if validation is successful rather than True/False.

Update docs and tests.

* Get attribute in loop so that the attribute name can also be used as a parameter

* Shorten line

* Update calling code in AnsibleModule for new validator interface

* Update calling code in validate_argument_spec based in new validation interface

* Base custom exception class off of Exception

* Call the __init__ method of the base Exception class to populate args

* Ensure no_log values are always updated

* Make custom exceptions more hierarchical

This redefines AnsibleError from lib/ansible/errors with a different signature since that cannot
be used by modules. This may be a bad idea. Maybe lib/ansible/errors should be moved to
module_utils, or AnsibleError defined in this commit should use the same signature as the original.

* Just go back to basing off Exception

* Return ValidationResult object on successful validation

Create a ValidationResult class.
Return a ValidationResult from ArgumentSpecValidator.validate() when validation is successful.
Update class and method docs.
Update unit tests based on interface change.

* Make it easier to get error objects from AnsibleValidationResultMultiple

This makes the interface cleaner when getting individual error objects contained in a single
AnsibleValidationResultMultiple instance.

* Define custom exception for each type of validation failure

These errors indicate where a validation error occured. Currently they are empty but could
contain specific data for each exception type in the future.

* Update tests based on (yet another) interface change

* Mark several more functions as private

These are all doing rather "internal" things. The ArgumentSpecValidator class is the preferred
public interface.

* Move warnings and deprecations to result object

Rather than calling deprecate() and warn() directly, store them on the result object so the
caller can decide what to do with them.

* Use subclass for module arg spec validation

The subclass uses global warning and deprecations feature

* Fix up docs

* Remove legal_inputs munging from _handle_aliases()

This is done in AnsibleModule by the _set_internal_properties() method. It only makes sense
to do that for an AnsibleModule instance (it should update the parameters before performing
validation) and shouldn't be done by the validator.

Create a private function just for getting legal inputs since that is done in a couple of places.

It may make sense store that on the ValidationResult object.

* Increase test coverage

* Remove unnecessary conditional

ci_complete

* Mark warnings and deprecations as private in the ValidationResult

They can be made public once we come up with a way to make them more generally useful,
probably by creating cusom objects to store the data in more structure way.

* Mark valid_parameter_names as private and populate it during initialization

* Use a global for storing the list of additonal checks to perform

This list is used by the main validate method as well as the sub spec validation.
2021-03-19 12:09:18 -07:00
Brian Coca 089d0a0508
find - set proper default based on use_regex (#73961)
When using "use_regex: yes" and setting an excludes: without
specifying a pattern: the existing code passes the file-glob '*' to
the regex matcher.  This results in an internal invalid-regex
exception being thrown.

This maintains the old semantics of a default match-all for pattern:
but switches the default to '.*' when use_regex is specified.

The code made sense as-is before excludes: was added (2.5).  In that
case, it made no sense to set use_regex but *not* set a pattern.
However, with excludes: it now makes sense to only want to exclude a
given regex but not specify a specific matching pattern.

Closes: #50067

* moved change to new location
added changelog

* Update lib/ansible/modules/find.py


Co-authored-by: Ian Wienand <iwienand@redhat.com>
2021-03-19 13:18:31 -04:00
Sloane Hertel 48c0fbd1cb
Fix a bug adding unrelated candidates to the plugin loader redirect_list (#73863)
* Fix a bug adding unrelated candidates to the plugin loader redirect_list

* Add tests for the redirect list

  * test redirect list for builtin module
  * test redirect list for redirected builtin module
  * test redirect list for collection module
  * test redirect list for redirected collection module
  * test redirect list for legacy module

* changelog
2021-03-18 17:53:57 -04:00
Baptiste Mille-Mathias 3e63eb8418 fix typo 2021-03-18 12:50:06 -07:00
Abhijeet Kasurde 3811fddede Amazon: Fix distribution facts for older release
Ansible can gather distribution facts for older Amazon Linux
with /etc/os-release data.

Fixes: #73946

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-03-18 12:42:04 -07:00
Matt Martz 78f34786dd
Send callbacks directly from the TaskExecutor instead of TaskResults masquerading as callbacks (#73927) 2021-03-18 12:12:29 -07:00
sommersoft 4add723107
ansible-pull: Run All Playbooks When Multiple Are Supplied (#73172)
* ansible-pull: run all playbooks when multiple are supplied

* add test for ansible-pull with multiple playbooks supplied from cli

* add changelog fragment
2021-03-17 13:52:51 -04:00
Matt Martz 832631b888
Ensure task from the worker is finalized/squashed (#73881)
* Ensure task from the worker is finalized/squashed. Fixes #57399. Fixes #49942
2021-03-16 15:09:43 -04:00
David Shrewsbury 1e5ccb326f
Allow for searching handler subdir for included tasks (#73809)
* Allow for searching handler subdir for included tasks
2021-03-15 15:39:59 -04:00
Paul Belanger 9ec4e08534
Don't match passive_interface for validate-modules (#73880)
This is a follow up to:

  https://github.com/ansible/ansible/pull/73508

To avoid adding no_log statements to passive_interface args.

Signed-off-by: Paul Belanger <pabelanger@redhat.com>
2021-03-13 08:28:57 -06:00
Felix Fontein 7c0af58449
validate-modules no_log test: extend search range, add more known false-positives (#73882)
* validate-modules no_log test: extend search range, add more known false-positives.

* Mark false-positives.
2021-03-13 08:28:33 -06:00
Mark Chappell ed18fcac3b
Ensure unit test paths for connection and inventory plugins are based on the context (#73877) 2021-03-12 12:46:40 -08:00
Matt Clay 3a8c9242e1 Use virtual host style S3 bucket names in tests. 2021-03-12 11:34:25 -08:00
Felix Fontein b2015c98e2
validate-modules: make sure that options that potentially contain secret data have no_log set (#73508)
* Catch more potential errors (and increase false-positive rate).
* Flag some false-positives in lib/ansible/modules/ with no_log=False.

Co-authored-by: John Barker <john@johnrbarker.com>
2021-03-11 12:57:11 -05:00
Matt Davis 3e1f6484d7
add optional module_utils import support (#73832)
* add optional module_utils import support

Treat core and collections module_utils imports nested within any Python block statement (eg, `try`, `if`) as optional. This allows Ansible modules to implement runtime fallback behavior for missing module_utils (eg from a newer version of ansible-core), where previously, the module payload builder would always fail when unable to locate a module_util (regardless of any runtime behavior the module may implement).

* sanity test fixes

ci_complete
2021-03-10 11:08:13 -08:00
Matt Clay 15064c7a42 Update resource_prefix syntax for ansible-test. 2021-03-10 09:00:12 -08:00
Brian Coca 9db557e431
Nonfatal facts (#73804)
continue with local facts vs at script error
 actually capture execution errors
 better error messages in general
 add more local facts tests

 fixes #52427
2021-03-08 16:20:37 -05:00
Abhijeet Kasurde fb66b4ffbc
distribution: Add Amazon Linux distribution facts (#73767)
* Update Amazon Linux Distribution facts gathering logic
* Update tests

Fixes: #73742

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2021-03-05 09:16:10 -05:00
David Shrewsbury 78d3810fdf
Auto cleanup of async cache file (#73760)
* Auto cleanup of async cache file

* Add changelog
2021-03-04 11:06:27 -08:00
Brian Coca ce1de28061
Fix notify on import_tasks (#73572)
* Fix notify on import_tasks

  also able to apply to blocks now.
2021-03-03 16:11:09 -05:00
Brian Coca 935528e22e
finish migrating ssh plugin to config system (#73708)
* finish migrating ssh plugin to config system

  fixes #72739
  fixes #57220

* fix connection detection in reset
* correct options for connection meta reset

Co-authored-by: David Shrewsbury <Shrews@users.noreply.github.com>
2021-03-03 15:25:16 -05:00
Brian Coca 43300e2279
module output is only json objects (#73765)
* module output is only json objects

 remove json lists as they are not valid from modules
 fixes #73744
2021-03-03 15:11:18 -05:00
Brian Coca 527bff6b79
Don't fail for mixed typed keys (#73726)
* Don't fail for mixed typed keys

  but warn that content cound not be sorted because of this

* added tests
2021-03-03 14:24:50 -05:00
Matt Clay f40dde44f4 Remove old ansible-test windows completion entries. 2021-03-02 10:48:03 -08:00
Matt Clay b6add939ff Remove outdated --docker and --remote entries. 2021-03-02 10:05:39 -08:00
Felix Fontein 3cc693b92c
Import test: improve docs, add more tests (#73600) 2021-03-01 16:10:46 -08:00
Abhijeet Kasurde 6cb324bb0e
selinux: return selinux_getpolicytype facts (#73609)
* selinux: return selinux_getpolicytype facts

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>

* add basic selinux facts tests

* fix selinux facts test when selinux missing

Co-authored-by: Matt Davis <mrd@redhat.com>
2021-03-01 11:11:09 -08:00
Matt Davis d0e991e892
Clarify CLI version number as core version (#72287)
* clarify CLI version number as core version

* reduce confusion with `ansible` PyPI package >= 2.10 drifting from core version

* fix units
2021-03-01 11:14:56 -06:00
Alexei Znamensky 920b68f5f2
Fixed/improved regular expresssion for collection names (#73577)
* added changelog fragment
* added a couple of tests to coll name validation
2021-03-01 10:40:38 -05:00