mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-11 14:35:06 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -6,7 +6,10 @@ from __future__ import annotations
|
|||
|
||||
import sys
|
||||
from unittest.mock import patch, Mock, mock_open
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ModuleTestCase, set_module_args
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
from ansible_collections.community.general.plugins.modules.modprobe import Modprobe, build_module
|
||||
|
||||
|
||||
|
|
@ -15,10 +18,10 @@ class TestLoadModule(ModuleTestCase):
|
|||
super().setUp()
|
||||
|
||||
self.mock_module_loaded = patch(
|
||||
'ansible_collections.community.general.plugins.modules.modprobe.Modprobe.module_loaded'
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.Modprobe.module_loaded"
|
||||
)
|
||||
self.mock_run_command = patch('ansible.module_utils.basic.AnsibleModule.run_command')
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_run_command = patch("ansible.module_utils.basic.AnsibleModule.run_command")
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.module_loaded = self.mock_module_loaded.start()
|
||||
self.run_command = self.mock_run_command.start()
|
||||
|
|
@ -32,43 +35,47 @@ class TestLoadModule(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_load_module_success(self):
|
||||
with set_module_args(dict(
|
||||
name='test',
|
||||
state='present',
|
||||
)):
|
||||
with set_module_args(
|
||||
dict(
|
||||
name="test",
|
||||
state="present",
|
||||
)
|
||||
):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
self.module_loaded.side_effect = [True]
|
||||
self.run_command.side_effect = [(0, '', '')]
|
||||
self.run_command.side_effect = [(0, "", "")]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
modprobe.load_module()
|
||||
|
||||
assert modprobe.result == {
|
||||
'changed': True,
|
||||
'name': 'test',
|
||||
'params': '',
|
||||
'state': 'present',
|
||||
"changed": True,
|
||||
"name": "test",
|
||||
"params": "",
|
||||
"state": "present",
|
||||
}
|
||||
|
||||
def test_load_module_unchanged(self):
|
||||
with set_module_args(dict(
|
||||
name='test',
|
||||
state='present',
|
||||
)):
|
||||
with set_module_args(
|
||||
dict(
|
||||
name="test",
|
||||
state="present",
|
||||
)
|
||||
):
|
||||
module = build_module()
|
||||
|
||||
module.warn = Mock()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
self.module_loaded.side_effect = [False]
|
||||
self.run_command.side_effect = [(0, '', ''), (1, '', '')]
|
||||
self.run_command.side_effect = [(0, "", ""), (1, "", "")]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
modprobe.load_module()
|
||||
|
||||
module.warn.assert_called_once_with('')
|
||||
module.warn.assert_called_once_with("")
|
||||
|
||||
|
||||
class TestUnloadModule(ModuleTestCase):
|
||||
|
|
@ -76,10 +83,10 @@ class TestUnloadModule(ModuleTestCase):
|
|||
super().setUp()
|
||||
|
||||
self.mock_module_loaded = patch(
|
||||
'ansible_collections.community.general.plugins.modules.modprobe.Modprobe.module_loaded'
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.Modprobe.module_loaded"
|
||||
)
|
||||
self.mock_run_command = patch('ansible.module_utils.basic.AnsibleModule.run_command')
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_run_command = patch("ansible.module_utils.basic.AnsibleModule.run_command")
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.module_loaded = self.mock_module_loaded.start()
|
||||
self.run_command = self.mock_run_command.start()
|
||||
|
|
@ -93,52 +100,54 @@ class TestUnloadModule(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_unload_module_success(self):
|
||||
with set_module_args(dict(
|
||||
name='test',
|
||||
state='absent',
|
||||
)):
|
||||
with set_module_args(
|
||||
dict(
|
||||
name="test",
|
||||
state="absent",
|
||||
)
|
||||
):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
self.module_loaded.side_effect = [False]
|
||||
self.run_command.side_effect = [(0, '', '')]
|
||||
self.run_command.side_effect = [(0, "", "")]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
modprobe.unload_module()
|
||||
|
||||
assert modprobe.result == {
|
||||
'changed': True,
|
||||
'name': 'test',
|
||||
'params': '',
|
||||
'state': 'absent',
|
||||
"changed": True,
|
||||
"name": "test",
|
||||
"params": "",
|
||||
"state": "absent",
|
||||
}
|
||||
|
||||
def test_unload_module_failure(self):
|
||||
with set_module_args(dict(
|
||||
name='test',
|
||||
state='absent',
|
||||
)):
|
||||
with set_module_args(
|
||||
dict(
|
||||
name="test",
|
||||
state="absent",
|
||||
)
|
||||
):
|
||||
module = build_module()
|
||||
|
||||
module.fail_json = Mock()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
self.module_loaded.side_effect = [True]
|
||||
self.run_command.side_effect = [(1, '', '')]
|
||||
self.run_command.side_effect = [(1, "", "")]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
modprobe.unload_module()
|
||||
|
||||
dummy_result = {
|
||||
'changed': False,
|
||||
'name': 'test',
|
||||
'state': 'absent',
|
||||
'params': '',
|
||||
"changed": False,
|
||||
"name": "test",
|
||||
"state": "absent",
|
||||
"params": "",
|
||||
}
|
||||
|
||||
module.fail_json.assert_called_once_with(
|
||||
msg='', rc=1, stdout='', stderr='', **dummy_result
|
||||
)
|
||||
module.fail_json.assert_called_once_with(msg="", rc=1, stdout="", stderr="", **dummy_result)
|
||||
|
||||
|
||||
class TestModuleIsLoadedPersistently(ModuleTestCase):
|
||||
|
|
@ -148,7 +157,7 @@ class TestModuleIsLoadedPersistently(ModuleTestCase):
|
|||
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -159,58 +168,47 @@ class TestModuleIsLoadedPersistently(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_module_is_loaded(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data='dummy')) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files'):
|
||||
modprobe.modules_files = ['/etc/modules-load.d/dummy.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data="dummy")
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files"):
|
||||
modprobe.modules_files = ["/etc/modules-load.d/dummy.conf"]
|
||||
|
||||
assert modprobe.module_is_loaded_persistently
|
||||
|
||||
mocked_file.assert_called_once_with('/etc/modules-load.d/dummy.conf')
|
||||
mocked_file.assert_called_once_with("/etc/modules-load.d/dummy.conf")
|
||||
|
||||
def test_module_is_not_loaded_empty_file(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data='')) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files'):
|
||||
modprobe.modules_files = ['/etc/modules-load.d/dummy.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data="")
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files"):
|
||||
modprobe.modules_files = ["/etc/modules-load.d/dummy.conf"]
|
||||
|
||||
assert not modprobe.module_is_loaded_persistently
|
||||
|
||||
mocked_file.assert_called_once_with('/etc/modules-load.d/dummy.conf')
|
||||
mocked_file.assert_called_once_with("/etc/modules-load.d/dummy.conf")
|
||||
|
||||
def test_module_is_not_loaded_no_files(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files'):
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files"):
|
||||
modprobe.modules_files = []
|
||||
|
||||
assert not modprobe.module_is_loaded_persistently
|
||||
|
|
@ -222,7 +220,7 @@ class TestPermanentParams(ModuleTestCase):
|
|||
self.skipTest("open_mock doesn't support readline in earlier python versions")
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -233,54 +231,47 @@ class TestPermanentParams(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_module_permanent_params_exist(self):
|
||||
|
||||
files_content = [
|
||||
'options dummy numdummies=4\noptions dummy dummy_parameter1=6',
|
||||
'options dummy dummy_parameter2=5 #Comment\noptions notdummy notdummy_param=5'
|
||||
"options dummy numdummies=4\noptions dummy dummy_parameter1=6",
|
||||
"options dummy dummy_parameter2=5 #Comment\noptions notdummy notdummy_param=5",
|
||||
]
|
||||
mock_files_content = [mock_open(read_data=content).return_value for content in files_content]
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open()) as mocked_file:
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open()
|
||||
) as mocked_file:
|
||||
mocked_file.side_effect = mock_files_content
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files'):
|
||||
modprobe.modprobe_files = ['/etc/modprobe.d/dummy1.conf', '/etc/modprobe.d/dummy2.conf']
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files"):
|
||||
modprobe.modprobe_files = ["/etc/modprobe.d/dummy1.conf", "/etc/modprobe.d/dummy2.conf"]
|
||||
|
||||
assert modprobe.permanent_params == set(['numdummies=4', 'dummy_parameter1=6', 'dummy_parameter2=5'])
|
||||
assert modprobe.permanent_params == set(
|
||||
["numdummies=4", "dummy_parameter1=6", "dummy_parameter2=5"]
|
||||
)
|
||||
|
||||
def test_module_permanent_params_empty(self):
|
||||
|
||||
files_content = [
|
||||
'',
|
||||
''
|
||||
]
|
||||
files_content = ["", ""]
|
||||
mock_files_content = [mock_open(read_data=content).return_value for content in files_content]
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data='')) as mocked_file:
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data="")
|
||||
) as mocked_file:
|
||||
mocked_file.side_effect = mock_files_content
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files'):
|
||||
modprobe.modprobe_files = ['/etc/modprobe.d/dummy1.conf', '/etc/modprobe.d/dummy2.conf']
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files"):
|
||||
modprobe.modprobe_files = ["/etc/modprobe.d/dummy1.conf", "/etc/modprobe.d/dummy2.conf"]
|
||||
|
||||
assert modprobe.permanent_params == set()
|
||||
|
||||
|
|
@ -289,7 +280,7 @@ class TestCreateModuleFIle(ModuleTestCase):
|
|||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -300,29 +291,26 @@ class TestCreateModuleFIle(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_create_file(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open()) as mocked_file:
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open()
|
||||
) as mocked_file:
|
||||
modprobe.create_module_file()
|
||||
mocked_file.assert_called_once_with('/etc/modules-load.d/dummy.conf', 'w')
|
||||
mocked_file().write.assert_called_once_with('dummy\n')
|
||||
mocked_file.assert_called_once_with("/etc/modules-load.d/dummy.conf", "w")
|
||||
mocked_file().write.assert_called_once_with("dummy\n")
|
||||
|
||||
|
||||
class TestCreateModuleOptionsFIle(ModuleTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -333,30 +321,26 @@ class TestCreateModuleOptionsFIle(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_create_file(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
params='numdummies=4',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", params="numdummies=4", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open()) as mocked_file:
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open()
|
||||
) as mocked_file:
|
||||
modprobe.create_module_options_file()
|
||||
mocked_file.assert_called_once_with('/etc/modprobe.d/dummy.conf', 'w')
|
||||
mocked_file().write.assert_called_once_with('options dummy numdummies=4\n')
|
||||
mocked_file.assert_called_once_with("/etc/modprobe.d/dummy.conf", "w")
|
||||
mocked_file().write.assert_called_once_with("options dummy numdummies=4\n")
|
||||
|
||||
|
||||
class TestDisableOldParams(ModuleTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -367,54 +351,48 @@ class TestDisableOldParams(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_disable_old_params_file_changed(self):
|
||||
mock_data = 'options dummy numdummies=4'
|
||||
mock_data = "options dummy numdummies=4"
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
params='numdummies=4',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", params="numdummies=4", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data=mock_data)) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files'):
|
||||
modprobe.modprobe_files = ['/etc/modprobe.d/dummy1.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data=mock_data)
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files"):
|
||||
modprobe.modprobe_files = ["/etc/modprobe.d/dummy1.conf"]
|
||||
modprobe.disable_old_params()
|
||||
mocked_file.assert_called_with('/etc/modprobe.d/dummy1.conf', 'w')
|
||||
mocked_file().write.assert_called_once_with('#options dummy numdummies=4')
|
||||
mocked_file.assert_called_with("/etc/modprobe.d/dummy1.conf", "w")
|
||||
mocked_file().write.assert_called_once_with("#options dummy numdummies=4")
|
||||
|
||||
def test_disable_old_params_file_unchanged(self):
|
||||
mock_data = 'options notdummy numdummies=4'
|
||||
mock_data = "options notdummy numdummies=4"
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
params='numdummies=4',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", params="numdummies=4", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data=mock_data)) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files'):
|
||||
modprobe.modprobe_files = ['/etc/modprobe.d/dummy1.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data=mock_data)
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files"):
|
||||
modprobe.modprobe_files = ["/etc/modprobe.d/dummy1.conf"]
|
||||
modprobe.disable_old_params()
|
||||
mocked_file.assert_called_once_with('/etc/modprobe.d/dummy1.conf')
|
||||
mocked_file.assert_called_once_with("/etc/modprobe.d/dummy1.conf")
|
||||
|
||||
|
||||
class TestDisableModulePermanent(ModuleTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.mock_get_bin_path = patch('ansible.module_utils.basic.AnsibleModule.get_bin_path')
|
||||
self.mock_get_bin_path = patch("ansible.module_utils.basic.AnsibleModule.get_bin_path")
|
||||
|
||||
self.get_bin_path = self.mock_get_bin_path.start()
|
||||
|
||||
|
|
@ -425,42 +403,34 @@ class TestDisableModulePermanent(ModuleTestCase):
|
|||
self.mock_get_bin_path.stop()
|
||||
|
||||
def test_disable_module_permanent_file_changed(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
params='numdummies=4',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", params="numdummies=4", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data='dummy')) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files'):
|
||||
modprobe.modules_files = ['/etc/modules-load.d/dummy.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data="dummy")
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files"):
|
||||
modprobe.modules_files = ["/etc/modules-load.d/dummy.conf"]
|
||||
modprobe.disable_module_permanent()
|
||||
mocked_file.assert_called_with('/etc/modules-load.d/dummy.conf', 'w')
|
||||
mocked_file().write.assert_called_once_with('#dummy')
|
||||
mocked_file.assert_called_with("/etc/modules-load.d/dummy.conf", "w")
|
||||
mocked_file().write.assert_called_once_with("#dummy")
|
||||
|
||||
def test_disable_module_permanent_file_unchanged(self):
|
||||
|
||||
with set_module_args(dict(
|
||||
name='dummy',
|
||||
state='present',
|
||||
params='numdummies=4',
|
||||
persistent='present'
|
||||
)):
|
||||
with set_module_args(dict(name="dummy", state="present", params="numdummies=4", persistent="present")):
|
||||
module = build_module()
|
||||
|
||||
self.get_bin_path.side_effect = ['modprobe']
|
||||
self.get_bin_path.side_effect = ["modprobe"]
|
||||
|
||||
modprobe = Modprobe(module)
|
||||
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.open', mock_open(read_data='notdummy')) as mocked_file:
|
||||
with patch('ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files'):
|
||||
modprobe.modules_files = ['/etc/modules-load.d/dummy.conf']
|
||||
with patch(
|
||||
"ansible_collections.community.general.plugins.modules.modprobe.open", mock_open(read_data="notdummy")
|
||||
) as mocked_file:
|
||||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modules_files"):
|
||||
modprobe.modules_files = ["/etc/modules-load.d/dummy.conf"]
|
||||
modprobe.disable_module_permanent()
|
||||
mocked_file.assert_called_once_with('/etc/modules-load.d/dummy.conf')
|
||||
mocked_file.assert_called_once_with("/etc/modules-load.d/dummy.conf")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue