mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
alternatives: handle absent link, add integration tests (#27967)
* alternatives: add integration tests
* alternatives: handle absent link (fix AttributeError)
Error occurred at least on Debian Stretch and OpenSuse 42.2:
Traceback (most recent call last):
File "/tmp/ansible_RY6X41/ansible_module_alternatives.py", line 161, in <module>
main()
File "/tmp/ansible_RY6X41/ansible_module_alternatives.py", line 113, in main
current_path = current_path_regex.search(display_output).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
update-alternatives stdout sample:
dummy - manual mode
link best version is /usr/bin/dummy1
link currently absent
link dummy is /usr/bin/dummy
* alternatives: PEP 8 fixes
* alternatives: fix copyright in integration tests
* alternatives: nested loops handle more than 2 items
Thanks to Michael Scherer (@mscherer) for pointing that.
* alternatives: enable integration tests
This commit is contained in:
@@ -77,12 +77,12 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(required=True),
|
||||
path = dict(required=True, type='path'),
|
||||
link = dict(required=False, type='path'),
|
||||
priority = dict(required=False, type='int',
|
||||
default=50),
|
||||
argument_spec=dict(
|
||||
name=dict(required=True),
|
||||
path=dict(required=True, type='path'),
|
||||
link=dict(required=False, type='path'),
|
||||
priority=dict(required=False, type='int',
|
||||
default=50),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
@@ -93,7 +93,7 @@ def main():
|
||||
link = params['link']
|
||||
priority = params['priority']
|
||||
|
||||
UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives',True)
|
||||
UPDATE_ALTERNATIVES = module.get_bin_path('update-alternatives', True)
|
||||
|
||||
current_path = None
|
||||
all_alternatives = []
|
||||
@@ -111,7 +111,9 @@ def main():
|
||||
re.MULTILINE)
|
||||
alternative_regex = re.compile(r'^(\/.*)\s-\spriority', re.MULTILINE)
|
||||
|
||||
current_path = current_path_regex.search(display_output).group(1)
|
||||
match = current_path_regex.search(display_output)
|
||||
if match:
|
||||
current_path = match.group(1)
|
||||
all_alternatives = alternative_regex.findall(display_output)
|
||||
|
||||
if not link:
|
||||
|
||||
Reference in New Issue
Block a user