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/plugins/modules/packaging/os
patchback[bot] 9e780b9d5e
Fix macports package present/active detection (#1308) (#1395)
* 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>
(cherry picked from commit d669e2b60d)

Co-authored-by: Dan Jackson <dan@djackson.org>
2020-11-26 07:15:27 +01:00
..
apk.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
apt_repo.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
apt_rpm.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
flatpak.py Add --non-interactive argurment to Flatpak (#1246) (#1332) 2020-11-19 21:31:36 +01:00
flatpak_remote.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
homebrew.py Resolve homebrew and homebrew_cask package name validation issues (#1038) (#1188) 2020-10-28 06:46:35 +01:00
homebrew_cask.py Resolve homebrew and homebrew_cask package name validation issues (#1038) (#1188) 2020-10-28 06:46:35 +01:00
homebrew_tap.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
installp.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
layman.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
macports.py Fix macports package present/active detection (#1308) (#1395) 2020-11-26 07:15:27 +01:00
mas.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
openbsd_pkg.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
opkg.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
pacman.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
pkg5.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
pkg5_publisher.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
pkgin.py feat(pkgin): add support for installation of full versioned package names (#1256) (#1349) 2020-11-21 21:41:09 +01:00
pkgng.py [pkgng] present the 'ignore_osver' option to pkg (#1243) (#1321) 2020-11-17 07:37:00 +01:00
pkgutil.py Fix boolean defaults. (#1343) (#1358) 2020-11-23 12:29:14 +01:00
portage.py Add getbinpkgonly (-G) to portage (#1169) (#1182) 2020-10-26 21:08:04 +01:00
portinstall.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
pulp_repo.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
redhat_subscription.py Fix boolean defaults. (#1343) (#1358) 2020-11-23 12:29:14 +01:00
rhn_channel.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
rhn_register.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
rhsm_release.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
rhsm_repository.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
slackpkg.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
snap.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
sorcery.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
svr4pkg.py Fix boolean defaults. (#1343) (#1358) 2020-11-23 12:29:14 +01:00
swdepot.py modules: fix examples to use FQCN (#644) 2020-07-13 21:50:31 +02:00
swupd.py Fix boolean defaults. (#1343) (#1358) 2020-11-23 12:29:14 +01:00
urpmi.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
xbps.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
zypper.py Tidy up validate-modules ignores for packaging modules (#1289) (#1291) 2020-11-13 14:04:53 +01:00
zypper_repository.py zypper_repository: Proper failure when python-xml is missing (#939) (#940) 2020-09-21 13:56:37 +02:00