* 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>
* npm - fix updating version specific modules
if a version specific module is used, the comparison will be used with the version and not only by name
* Update plugins/modules/packaging/language/npm.py
Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
* Update changelogs/fragments/2830-npm-version-update.yml
Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
* Update changelogs/fragments/2830-npm-version-update.yml
Co-authored-by: Amin Vakil <info@aminvakil.com>
* Update changelogs/fragments/2830-npm-version-update.yml
Co-authored-by: Amin Vakil <info@aminvakil.com>
Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
Co-authored-by: Amin Vakil <info@aminvakil.com>
* Add server_prefix and server_port as supported arguments for the redhat_subscription module.
* Adjust the argument sequence in the test case to be consistent with the original code in line 364 in redhat_subscription.py and add the changelog fragment.
* Grammatical changes such as adding full stops and using 'an HTTP' instead of 'a HTTP'.
* Commit the suggested changelog update.
Co-authored-by: Amin Vakil <info@aminvakil.com>
* Fix typo.
Co-authored-by: Amin Vakil <info@aminvakil.com>
Co-authored-by: Amin Vakil <info@aminvakil.com>
* also uses LC_ALL to force language
* adjusted test_xfconf and test_cpanm
* added changelog fragment
* Update changelogs/fragments/2731-mh-cmd-locale.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
* adjusted chglog frag per PR
Co-authored-by: Felix Fontein <felix@fontein.de>
* add module pacman_key
* add symlink and fix documentation for pacman_key
* documentation fix for pacman_key
* improve logic around user input
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* Improve parameter checking
required_one_of=[] is neat.
Co-authored-by: Alexei Znamensky
* Revert "Improve parameter checking"
This reverts commit 044b0cbc85.
* Simplify a bunch of code.
* fix typos pointed out by yan12125
* replaced manual checks with required-if invocation
* added default keyring to documentation
* some initial tests
* updated metadata
* refactored to make sanity tests pass
* refactor to make sanity tests pass ... part deux
* refactor: simplify run_command invocations
* test: cover check-mode and some normal operation
* docs: fix grammatical errors
* rip out fingerprint code
a full length (40 characters) key ID is equivalent to the fingerprint.
* refactor tests, add a couple more
* test: added testcase for method: data
* Update plugins/modules/packaging/os/pacman_key.py
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* docs: correct yaml boolean type
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
* rhsm_release: Fix the issue that rhsm_release module considers 8, 7Client and 7Workstation as invalid releases.
* Fix the unit test error: The new release_matcher could pass a wider range of patterns but that would not cause extra issue to the whole module.
* Submit the changelog fragment.
* Update changelogs/fragments/2571-rhsm_release-fix-release_matcher.yaml
Co-authored-by: Amin Vakil <info@aminvakil.com>
Co-authored-by: Amin Vakil <info@aminvakil.com>
* copying from the previous branch
* passing sanity - docs incomplete
* adjusted parameter name
* adjusted unit tests for mode=new
* adjusted integration tests for mode=new
* added 'russoz' to list of maintainers for cpanm
* Update tests/integration/targets/cpanm/tasks/main.yml
* Update tests/integration/targets/cpanm/tasks/main.yml
* ensuring backward compatibility + tests
* added changelog fragment
* version for new parameter and adjusted example
* typo and formatting
* Update plugins/modules/packaging/language/cpanm.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/packaging/language/cpanm.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/packaging/language/cpanm.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* multiple changes
- some fixes from PR
- supporting tests
- integration is no longer unsupported => destructive, should run on
apt- and rpm-based systems only
* only run integration tests in redhat-family > v7 or debian-family
Co-authored-by: Felix Fontein <felix@fontein.de>
* Provide a user friendly message by handling json decode
exception rather than providing a stacktrace
Fixes: #1614
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
* Fix typo in redhat_subscription testcase
* Fix macports state=present matching against the wrong package name
Previous implementation returned true if the desired package name occurred anywhere in
the list of all installed packages. For example as a substring of another package name,
or even as a substring of a variant name for a different package.
Instead:
- request macports only list installed packages matching the desired package name, instead of all installed packages.
- Note `port` exits with 0 regardless of whether any packages match the requested name.
- pass `-q` flag: "Do not print the header line. This is useful when parsing the output of port installed in scripts for further processing."
- eliminate `use_unsafe_shell=True` by searching stdout contents natively in python
instead of using `grep`. This has the added benefit of eliminating any potential
misinterpretation of characters in the package name as regex special characters.
If there are zero matching installed packages, `out` is empty.
If there are one or more matches (due to multiple installed versions), the output format
is: ec8a2bc682/src/port/port.tcl (L3320-L3323)
Notably, two leading spaces, the package name, a space, and then other information.
According to blame via github, those lines haven't changed in 11 years.
* Update macports state=active to eliminate use_unsafe_shell
Similar to previous commit (for macports state=present):
- pass `-q` flag: "Do not print the header line. This is useful when parsing the output of port installed in scripts for further processing."
- search stdout contents natively in python instead of using `grep`.
- added parentheses to search string to eliminate false positives if the package name
or variants contain the word `active`. Still could fail if they contain `(active)`, but
that's less likely
If there are zero matching installed packages, `out` is empty.
If there are one or more matches (due to multiple installed versions), the output format
is: ec8a2bc682/src/port/port.tcl (L3320-L3323)
For "state=active", we're looking for a line that contains `(active)` in the output.
* Basic test case of query_port for present and active
* Attempt to fix lint errors in test
* Different mock module creation, changed test cases indentation/spacing
- picked the wrong mock code to cargo-cult. Thanks to felixfontein for this suggestion
- 4 space indentation on continuation line. I thought I had that originally, but it looks like my editor sabotaged me with mixed tabs/spaces
- Remove leading newline on multi-line test cases. I don't think it would make a difference, but I'd read up on how the python syntax works and want to more accurately represent macports output.
fingers crossed this addresses the known build errors
* Add changelog fragment
* Update tests/unit/plugins/modules/packaging/os/test_macports.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update changelogs/fragments/1307-macports-fix-status-check.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
* * pkgin query_package(..) understands now also package name with version (my-package-1.2nb123456). * pkgin query_package(..) will distinct between not-installed and not-found packages. * pkgin install_package(..) fails with proper error if a non-existing package is attempted to be installed.
* fixup ansibot comments
* add changelog fragment
* add example
* use more pythonic condition
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* remove extra dot between description and link to PR
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
* fix file extension of changelog fragment
* add pkgin unit tests for query_package function
* fix pep8 issues
* use enum Flag instead mix of strings, bools and None as return value
* use IntEnum instead Flag to support Python versions >= 2.6
* fix pep8 and pylint errors
* use regular class instead enum to avoid issues with older Python releases
* fix comment
* remove the combined package state since without an IntFlag or Flag the usage of it would require to use logical operators
Co-authored-by: Erik van Nooijen <eric.vannooijen@tomtom.com>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>