1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/unit/plugins/modules
Jean Raby 1580f3c2b4
request for comments - pacman: speed up most operations when working with a package list (#3907)
* pacman: rewrite with a cache to speed up execution

- Use a cache (or inventory) to speed up lookups of:
  - installed packages and groups
  - available packages and groups
  - upgradable packages
- Call pacman with the list of pkgs instead of one call per package (for
  installations, upgrades and removals)
- Use pacman [--sync|--upgrade] --print-format [...] to gather list of
  changes. Parsing that instead of the regular output of pacman, which
  is error prone and can be changed by user configuration.
  This can introduce a TOCTOU problem but unless something else calls
  pacman between the invocations, it shouldn't be a concern.
- Given the above, "check mode" code is within the function that would
  carry out the actual operation. This should make it harder for the
  check code and the "real code" to diverge.
- Support for specifying alternate package name formats is a bit more
  robust. pacman is used to extract the name of the package when the
  specified package is a file or a URL.
  The "<repo>/<pkgname>" format is also supported.

For "state: latest" with a list of ~35 pkgs, this module is about 5
times faster than the original.

* Let fail() actually work

* all unhappy paths now end up calling fail()

* Update copyright

* Argument changes

update_cache_extra_args handled as a list like the others
moved the module setup to its own function for easier testing
update and upgrade have no defaults (None) to let required_one_of() do
its job properly

* update_cache exit path

Shift successful exit without name or upgrade under "update_cache".

It is an error if name or upgrade isn't specified and update_cache wasn't specified
either. (Caught by ansiblemodule required_one_of but still)

* Add pkgs to output on success only

Also align both format, only pkg name for now

* Multiple fixes

Move VersionTuple to top level for import from tests
Add removed pkgs to the exit json when removing packages
fixup list of upgraded pkgs reported on upgrades (was tuple of list for
no reason)
use list idiom for upgrades, like the rest
drop unused expand_package_groups function
skip empty lines when building inventory

* pacman: add tests

* python 2.x compat + pep8

* python 2.x some more

* Fix failure when pacman emits warnings

Add tests covering that failure case

* typo

* Whitespace

black failed me...

* Adjust documentation to fit implicit defaults

* fix test failures on older pythons

* remove file not intended for commit

* Test exception str with e.match

* Build inventory after cache update + adjust tests

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/packaging/os/pacman.py

Co-authored-by: Felix Fontein <felix@fontein.de>

* changelog

* bump copyright year and add my name to authors

* Update changelogs/fragments/3907-pacman-speedup.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* maintainer entry

Co-authored-by: Felix Fontein <felix@fontein.de>
2022-02-08 22:46:00 +01:00
..
cloud Refactor all Proxmox modules to use shared module_utils. (#4029) 2022-02-07 06:21:24 +01:00
database Added redis_incr module (#3229) 2021-10-22 07:54:02 +02:00
files archive - fixing determination of archive root when root is '/' (#3036) 2021-07-24 22:10:56 +02:00
identity New Module: Keycloak Realm Info (#3998) 2022-01-11 06:42:47 +01:00
messaging Move modules and module_utils unit tests to correct place (#81) 2020-03-31 10:42:38 +02:00
monitoring monit - invoke run_command passing list (#3821) 2021-12-02 07:50:02 +01:00
net_tools Add nmcli support for IPv6 routes (#4062) 2022-01-23 13:02:03 +01:00
notification discord.py: Add new module for discord notifications (#2398) 2021-05-11 19:31:46 +02:00
packaging request for comments - pacman: speed up most operations when working with a package list (#3907) 2022-02-08 22:46:00 +01:00
remote_management Fix CI (#3637) 2021-10-30 10:58:48 +02:00
source_control Bugfix: github_repo does not apply defaults on existing repos (#2386) 2021-11-22 07:11:26 +01:00
storage sanity: Add future boilerplate (#573) 2020-06-24 21:50:36 +02:00
system interfaces_file: unit tests improved (#3863) 2021-12-08 12:31:12 +01:00
web_infrastructure Add fallback url for jenkins plugin (#1334) 2021-06-29 10:26:59 +04:30
__init__.py Move modules and module_utils unit tests to correct place (#81) 2020-03-31 10:42:38 +02:00
conftest.py Replace ansible.module_utils._text by ansible.module_utils.common.text.converters (#2877) 2021-06-26 23:59:11 +02:00
utils.py Replace ansible.module_utils._text by ansible.module_utils.common.text.converters (#2877) 2021-06-26 23:59:11 +02:00