1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-08 13:07:19 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -6,7 +6,11 @@ from __future__ import annotations
from unittest.mock import patch
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleFailJson,
ModuleTestCase,
set_module_args,
)
from ansible_collections.community.general.plugins.modules.simpleinit_msb import SimpleinitMSB, build_module
@ -83,44 +87,49 @@ _TELINIT_STATUS_RUNNING_NOT = """
class TestSimpleinitMSB(ModuleTestCase):
def setUp(self):
super().setUp()
def tearDown(self):
super().tearDown()
@patch('os.path.exists', return_value=True)
@patch('ansible.module_utils.basic.AnsibleModule.get_bin_path', return_value="/sbin/telinit")
@patch("os.path.exists", return_value=True)
@patch("ansible.module_utils.basic.AnsibleModule.get_bin_path", return_value="/sbin/telinit")
def test_get_service_tools(self, *args, **kwargs):
with set_module_args({
'name': 'smgl-suspend-single',
'state': 'running',
}):
with set_module_args(
{
"name": "smgl-suspend-single",
"state": "running",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
simpleinit_msb.get_service_tools()
self.assertEqual(simpleinit_msb.telinit_cmd, "/sbin/telinit")
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command")
def test_service_exists(self, execute_command):
with set_module_args({
'name': 'smgl-suspend-single',
'state': 'running',
}):
with set_module_args(
{
"name": "smgl-suspend-single",
"state": "running",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
execute_command.return_value = (0, _TELINIT_LIST, "")
simpleinit_msb.service_exists()
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command")
def test_service_exists_not(self, execute_command):
with set_module_args({
'name': 'ntp',
'state': 'running',
}):
with set_module_args(
{
"name": "ntp",
"state": "running",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
execute_command.return_value = (0, _TELINIT_LIST, "")
@ -130,14 +139,16 @@ class TestSimpleinitMSB(ModuleTestCase):
self.assertEqual("telinit could not find the requested service: ntp", context.exception.args[0]["msg"])
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_exists')
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_exists")
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command")
def test_check_service_enabled(self, execute_command, service_exists):
with set_module_args({
'name': 'nscd',
'state': 'running',
'enabled': 'true',
}):
with set_module_args(
{
"name": "nscd",
"state": "running",
"enabled": "true",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
service_exists.return_value = True
@ -146,21 +157,26 @@ class TestSimpleinitMSB(ModuleTestCase):
self.assertTrue(simpleinit_msb.service_enabled())
# Race condition check
with patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_enabled', return_value=False):
with patch(
"ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_enabled",
return_value=False,
):
execute_command.return_value = (0, "", _TELINIT_ALREADY_ENABLED)
simpleinit_msb.service_enable()
self.assertFalse(simpleinit_msb.changed)
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_exists')
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_exists")
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.execute_command")
def test_check_service_disabled(self, execute_command, service_exists):
with set_module_args({
'name': 'sysstat',
'state': 'stopped',
'enabled': 'false',
}):
with set_module_args(
{
"name": "sysstat",
"state": "stopped",
"enabled": "false",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
service_exists.return_value = True
@ -169,31 +185,38 @@ class TestSimpleinitMSB(ModuleTestCase):
self.assertFalse(simpleinit_msb.service_enabled())
# Race condition check
with patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_enabled', return_value=True):
with patch(
"ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_enabled",
return_value=True,
):
execute_command.return_value = (0, "", _TELINIT_ALREADY_DISABLED)
simpleinit_msb.service_enable()
self.assertFalse(simpleinit_msb.changed)
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_control')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_control")
def test_check_service_running(self, service_control):
with set_module_args({
'name': 'sshd',
'state': 'running',
}):
with set_module_args(
{
"name": "sshd",
"state": "running",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
service_control.return_value = (0, _TELINIT_STATUS_RUNNING, "")
self.assertFalse(simpleinit_msb.get_service_status())
@patch('ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_control')
@patch("ansible_collections.community.general.plugins.modules.simpleinit_msb.SimpleinitMSB.service_control")
def test_check_service_running_not(self, service_control):
with set_module_args({
'name': 'smgl-metalog',
'state': 'running',
}):
with set_module_args(
{
"name": "smgl-metalog",
"state": "running",
}
):
simpleinit_msb = SimpleinitMSB(build_module())
service_control.return_value = (0, _TELINIT_STATUS_RUNNING_NOT, "")