mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Bug 62940 change tests for cron inconsistency in _write_cron_lines
This commit is contained in:
parent
0fe1954b91
commit
c967d9eddb
1 changed files with 38 additions and 16 deletions
|
@ -1421,10 +1421,11 @@ class PsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
ret = cron.rm_job("DUMMY_USER", "/bin/echo NOT A DROID", 1, 2, 3, 4, 5)
|
||||
self.assertEqual("absent", ret)
|
||||
|
||||
def test_write_cron_lines_root_rh(self):
|
||||
def test_write_cron_lines_euid_match_user_rh(self):
|
||||
"""
|
||||
Assert that _write_cron_lines() is called with the correct cron command and user
|
||||
OS: RedHat. User: root. Expected to run with runas argument.
|
||||
OS: RedHat. EUID match User (either root, root or user, user).
|
||||
Expected to run without runas argument.
|
||||
"""
|
||||
temp_path = "some_temp_path"
|
||||
crontab_cmd = "crontab {}".format(temp_path)
|
||||
|
@ -1436,8 +1437,6 @@ class PsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
new=MagicMock(return_value=True),
|
||||
), patch(
|
||||
"salt.utils.files.fpopen", mock_open()
|
||||
), patch.dict(
|
||||
cron.__salt__, {"file.user_to_uid": MagicMock(return_value=1)}
|
||||
), patch(
|
||||
"salt.utils.files.mkstemp", MagicMock(return_value=temp_path)
|
||||
), patch(
|
||||
|
@ -1445,13 +1444,40 @@ class PsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
):
|
||||
cron._write_cron_lines("root", "test 123")
|
||||
cron.__salt__["cmd.run_all"].assert_called_with(
|
||||
crontab_cmd, python_shell=False, runas="root"
|
||||
crontab_cmd, python_shell=False
|
||||
)
|
||||
|
||||
def test_write_cron_lines_non_root_rh(self):
|
||||
def test_write_cron_lines_root_non_root_rh(self):
|
||||
"""
|
||||
Assert that _write_cron_lines() is called with the correct cron command and user
|
||||
OS: RedHat. User: non-root. Expected to run without runas argument.
|
||||
OS: RedHat. EUID: root. User: non-root.
|
||||
Expected to run without runas argument and with -u non-root argument.
|
||||
"""
|
||||
temp_path = "some_temp_path"
|
||||
crontab_cmd = "crontab -u {} {}".format("non-root", temp_path)
|
||||
|
||||
with patch.dict(cron.__grains__, {"os_family": "RedHat"}), patch.dict(
|
||||
cron.__salt__, {"cmd.run_all": MagicMock()}
|
||||
), patch(
|
||||
"salt.modules.cron._check_instance_uid_match",
|
||||
new=MagicMock(side_effect=[False, True]),
|
||||
), patch(
|
||||
"salt.utils.files.fpopen", mock_open()
|
||||
), patch(
|
||||
"salt.utils.files.mkstemp", MagicMock(return_value=temp_path)
|
||||
), patch(
|
||||
"os.remove", MagicMock()
|
||||
):
|
||||
cron._write_cron_lines("non-root", "test 123")
|
||||
cron.__salt__["cmd.run_all"].assert_called_with(
|
||||
crontab_cmd, python_shell=False
|
||||
)
|
||||
|
||||
def test_write_cron_lines_non_root_euid_doesnt_match_user_rh(self):
|
||||
"""
|
||||
Assert that _write_cron_lines() is called with the correct cron command and user
|
||||
OS: RedHat. EUID: non-root. EUID doesn't match User.
|
||||
Expected to run with runas argument.
|
||||
"""
|
||||
temp_path = "some_temp_path"
|
||||
crontab_cmd = "crontab {}".format(temp_path)
|
||||
|
@ -1472,22 +1498,20 @@ class PsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
):
|
||||
cron._write_cron_lines("non-root", "test 123")
|
||||
cron.__salt__["cmd.run_all"].assert_called_with(
|
||||
crontab_cmd, python_shell=False
|
||||
crontab_cmd, python_shell=False, runas="non-root"
|
||||
)
|
||||
|
||||
def test_write_cron_lines_non_root_aix(self):
|
||||
"""
|
||||
Assert that _write_cron_lines() is called with the correct cron command and user
|
||||
OS: AIX. User: non-root. Expected to run with runas argument.
|
||||
OS: AIX. User: non-root.
|
||||
Expected to run with runas argument.
|
||||
"""
|
||||
temp_path = "some_temp_path"
|
||||
crontab_cmd = "crontab {}".format(temp_path)
|
||||
|
||||
with patch.dict(cron.__grains__, {"os_family": "AIX"}), patch.dict(
|
||||
cron.__salt__, {"cmd.run_all": MagicMock()}
|
||||
), patch(
|
||||
"salt.modules.cron._check_instance_uid_match",
|
||||
new=MagicMock(return_value=False),
|
||||
), patch(
|
||||
"salt.utils.files.fpopen", mock_open()
|
||||
), patch.dict(
|
||||
|
@ -1505,16 +1529,14 @@ class PsTestCase(TestCase, LoaderModuleMockMixin):
|
|||
def test_write_cron_lines_non_root_solaris(self):
|
||||
"""
|
||||
Assert that _write_cron_lines() is called with the correct cron command and user
|
||||
OS: Solaris. User: non-root. Expected to run with runas argument.
|
||||
OS: Solaris. User: non-root.
|
||||
Expected to run with runas argument.
|
||||
"""
|
||||
temp_path = "some_temp_path"
|
||||
crontab_cmd = "crontab {}".format(temp_path)
|
||||
|
||||
with patch.dict(cron.__grains__, {"os_family": "AIX"}), patch.dict(
|
||||
cron.__salt__, {"cmd.run_all": MagicMock()}
|
||||
), patch(
|
||||
"salt.modules.cron._check_instance_uid_match",
|
||||
new=MagicMock(return_value=False),
|
||||
), patch(
|
||||
"salt.utils.files.fpopen", mock_open()
|
||||
), patch.dict(
|
||||
|
|
Loading…
Add table
Reference in a new issue