mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
add systemd run0 as a become method (#8306)
* 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>
This commit is contained in:
parent
3b7f13c58e
commit
d347bf5fa0
3 changed files with 194 additions and 0 deletions
64
tests/unit/plugins/become/test_run0.py
Normal file
64
tests/unit/plugins/become/test_run0.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
# 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
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue