mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 04:40:22 -07:00
Improve error condition handling for dnf module (#44770)
- Fix comma separated list handling for package names - Fix error message for unavailable/unknown package install attempt - Fix pkg install result output generation Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
15886b1d56
commit
1e3b927a73
3 changed files with 47 additions and 10 deletions
|
@ -87,12 +87,30 @@ class YumDnf(with_metaclass(ABCMeta, object)):
|
|||
|
||||
# It's possible someone passed a comma separated string since it used
|
||||
# to be a string type, so we should handle that
|
||||
if self.enablerepo and len(self.enablerepo) == 1 and ',' in self.enablerepo:
|
||||
self.enablerepo = self.module.params['enablerepo'].split(',')
|
||||
if self.disablerepo and len(self.disablerepo) == 1 and ',' in self.disablerepo:
|
||||
self.disablerepo = self.module.params['disablerepo'].split(',')
|
||||
if self.exclude and len(self.exclude) == 1 and ',' in self.exclude:
|
||||
self.exclude = self.module.params['exclude'].split(',')
|
||||
self.names = self.listify_comma_sep_strings_in_list(self.names)
|
||||
self.disablerepo = self.listify_comma_sep_strings_in_list(self.disablerepo)
|
||||
self.enablerepo = self.listify_comma_sep_strings_in_list(self.enablerepo)
|
||||
self.exclude = self.listify_comma_sep_strings_in_list(self.exclude)
|
||||
|
||||
def listify_comma_sep_strings_in_list(self, some_list):
|
||||
"""
|
||||
method to accept a list of strings as the parameter, find any strings
|
||||
in that list that are comma separated, remove them from the list and add
|
||||
their comma separated elements to the original list
|
||||
"""
|
||||
new_list = []
|
||||
remove_from_original_list = []
|
||||
for element in some_list:
|
||||
if ',' in element:
|
||||
remove_from_original_list.append(element)
|
||||
new_list.extend([e.strip() for e in element.split(',')])
|
||||
|
||||
for element in remove_from_original_list:
|
||||
some_list.remove(element)
|
||||
|
||||
some_list.extend(new_list)
|
||||
|
||||
return some_list
|
||||
|
||||
@abstractmethod
|
||||
def run(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue