Fix alternatives module (#4836)

* Only pass subcommands when they are specified as module arguments.

* When 'subcommands' is specified, 'link' must be given for every subcommand.

* Extend subcommand tests.
This commit is contained in:
Felix Fontein 2022-06-14 16:02:31 +02:00 committed by GitHub
parent a45b90e93f
commit 84d8ca9234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 151 additions and 3 deletions

View file

@ -77,6 +77,7 @@ options:
description:
- The path to the symbolic link that should point to the real subcommand executable.
type: path
required: true
version_added: 5.1.0
requirements: [ update-alternatives ]
'''
@ -204,7 +205,7 @@ class AlternativesModule(object):
cmd = [self.UPDATE_ALTERNATIVES, '--install', self.link, self.name, self.path, str(self.priority)]
if self.subcommands is not None:
if self.module.params['subcommands'] is not None:
subcommands = [['--slave', subcmd['link'], subcmd['name'], subcmd['path']] for subcmd in self.subcommands]
cmd += [item for sublist in subcommands for item in sublist]
@ -384,7 +385,7 @@ def main():
subcommands=dict(type='list', elements='dict', aliases=['slaves'], options=dict(
name=dict(type='str', required=True),
path=dict(type='path', required=True),
link=dict(type='path'),
link=dict(type='path', required=True),
)),
),
supports_check_mode=True,