mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
d347bf5fa0
* add systemd run0 as a become method Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * add fragment Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * remove space after hyphen Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * replace ansible with collection version Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * update version_added and remove changelog fragment Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * update formating Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * add types Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * slim super() Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * imports must appear below docs Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * add initial unit test Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> * update unit tests Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com> --------- Signed-off-by: Thomas Sjögren <konstruktoid@users.noreply.github.com>
64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
# Copyright (c) 2024 Ansible Project
|
|
#
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
import re
|
|
|
|
from ansible import context
|
|
|
|
from .helper import call_become_plugin
|
|
|
|
|
|
def test_run0_basic(mocker, parser, reset_cli_args):
|
|
options = parser.parse_args([])
|
|
context._init_global_context(options)
|
|
|
|
default_cmd = "/bin/foo"
|
|
default_exe = "/bin/sh"
|
|
run0_exe = "run0"
|
|
|
|
success = "BECOME-SUCCESS-.+?"
|
|
|
|
task = {
|
|
"become_method": "community.general.run0",
|
|
}
|
|
var_options = {}
|
|
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
|
assert (
|
|
re.match(
|
|
f"{run0_exe} --user=root {default_exe} -c 'echo {success}; {default_cmd}'",
|
|
cmd,
|
|
)
|
|
is not None
|
|
)
|
|
|
|
|
|
def test_run0_flags(mocker, parser, reset_cli_args):
|
|
options = parser.parse_args([])
|
|
context._init_global_context(options)
|
|
|
|
default_cmd = "/bin/foo"
|
|
default_exe = "/bin/sh"
|
|
run0_exe = "run0"
|
|
run0_flags = "--nice=15"
|
|
|
|
success = "BECOME-SUCCESS-.+?"
|
|
|
|
task = {
|
|
"become_method": "community.general.run0",
|
|
"become_flags": run0_flags,
|
|
}
|
|
var_options = {}
|
|
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
|
assert (
|
|
re.match(
|
|
f"{run0_exe} --user=root --nice=15 {default_exe} -c 'echo {success}; {default_cmd}'",
|
|
cmd,
|
|
)
|
|
is not None
|
|
)
|