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
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
..
action iptables_state: fix race condition between module and its action plugin (#1140) (#1143) 2020-10-20 22:46:12 +02:00
become Fix various sanity errors in plugins (#881) (#893) 2020-09-17 16:39:57 +00:00
cache Fix the linode inventory plugin, and the redis and memcached cache plugins (#1281, #1282, #1283). 2020-11-13 22:06:41 +01:00
callback Improve plugin sanity (#966) (#984) 2020-09-29 04:04:05 +00:00
connection Improve plugin sanity (#966) (#984) 2020-09-29 04:04:05 +00:00
doc_fragments proxmox: create a common base (#1331) (#1378) 2020-11-24 17:56:50 +01:00
filter Add filter dict_kv (#1264) (#1374) 2020-11-24 06:23:37 +01:00
inventory Fix the linode inventory plugin, and the redis and memcached cache plugins (#1281, #1282, #1283). 2020-11-13 22:06:41 +01:00
lookup Added umask option to passwordstore lookup plugin. (#1156) (#1376) 2020-11-24 07:36:15 +00:00
module_utils proxmox: create a common base (#1331) (#1378) 2020-11-24 17:56:50 +01:00
modules Fix macports package present/active detection (#1308) (#1395) 2020-11-26 07:15:27 +01:00