-
Notifications
You must be signed in to change notification settings - Fork 23.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't hardcode the dnf module, dynamically select one (#83183)
- Loading branch information
Showing
7 changed files
with
61 additions
and
25 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
test/integration/targets/dnf/filter_plugins/dnf_module_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright: Contributors to the Ansible project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import annotations | ||
|
||
from collections import Counter | ||
|
||
|
||
def parse_module_list(stdout): | ||
lines = stdout.splitlines() | ||
name_offset = 0 | ||
empty_offset = -1 | ||
modules = [] | ||
for i, line in enumerate(lines): | ||
if line.startswith('Name '): | ||
name_offset = i + 1 | ||
if not line.strip(): | ||
empty_offset = i | ||
for line in lines[name_offset:empty_offset]: | ||
cols = line.split()[:3] | ||
modules.append({ | ||
'name': cols[0], | ||
'version': cols[1], | ||
'profile': cols[2].rstrip(','), # Just the first profile | ||
}) | ||
return modules | ||
|
||
|
||
def get_first_single_version_module(stdout): | ||
modules = parse_module_list(stdout) | ||
name = Counter([m['name'] for m in modules]).most_common()[-1][0] | ||
module, = [m for m in modules if m['name'] == name] | ||
return module | ||
|
||
|
||
class FilterModule: | ||
def filters(self): | ||
return { | ||
'get_first_single_version_module': get_first_single_version_module, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.