Ejemplo n.º 1
0
 def test_launchctl_error(self):
     '''
     test launchctl function returning an error
     '''
     mock_cmd = MagicMock(return_value={'retcode': 1,
                                        'stdout': 'failure',
                                        'stderr': 'test failure'})
     error = 'Failed to enable service:\n' \
             'stdout: failure\n' \
             'stderr: test failure\n' \
             'retcode: 1'
     with patch('salt.utils.mac_utils.__salt__', {'cmd.run_all': mock_cmd}):
         try:
             mac_utils.launchctl('enable', 'org.salt.minion')
         except CommandExecutionError as exc:
             self.assertEqual(exc.message, error)
Ejemplo n.º 2
0
 def test_launchctl_error(self):
     """
     test launchctl function returning an error
     """
     mock_cmd = MagicMock(
         return_value={"retcode": 1, "stdout": "failure", "stderr": "test failure"}
     )
     error = (
         "Failed to enable service:\n"
         "stdout: failure\n"
         "stderr: test failure\n"
         "retcode: 1"
     )
     with patch("salt.utils.mac_utils.__salt__", {"cmd.run_all": mock_cmd}):
         try:
             mac_utils.launchctl("enable", "org.salt.minion")
         except CommandExecutionError as exc:
             self.assertEqual(exc.message, error)
Ejemplo n.º 3
0
 def test_not_bootout_retcode_36_fail(self):
     """
     Make sure that if we get a retcode 36 on non bootout cmds
     that we still get a failure.
     """
     error = ("Failed to bootstrap service:\n"
              "stdout: failure\n"
              "stderr: test failure\n"
              "retcode: 36")
     proc = MagicMock(return_value=MockTimedProc(
         stdout=b"failure", stderr=b"test failure", returncode=36))
     with patch("salt.utils.timed_subprocess.TimedProc", proc):
         with patch("salt.utils.mac_utils.__salt__",
                    {"cmd.run_all": cmd._run_all_quiet}):
             try:
                 mac_utils.launchctl("bootstrap", "org.salt.minion")
             except CommandExecutionError as exc:
                 self.assertEqual(exc.message, error)
Ejemplo n.º 4
0
 def test_bootout_retcode_99_fail(self):
     """
     Make sure that if we run a `launchctl bootout` cmd and it returns
     something other than 0 or 36 that we treat it as a fail.
     """
     error = ("Failed to bootout service:\n"
              "stdout: failure\n"
              "stderr: test failure\n"
              "retcode: 99")
     proc = MagicMock(return_value=MockTimedProc(
         stdout=b"failure", stderr=b"test failure", returncode=99))
     with patch("salt.utils.timed_subprocess.TimedProc", proc):
         with patch("salt.utils.mac_utils.__salt__",
                    {"cmd.run_all": cmd._run_all_quiet}):
             try:
                 mac_utils.launchctl("bootout", "org.salt.minion")
             except CommandExecutionError as exc:
                 self.assertEqual(exc.message, error)
Ejemplo n.º 5
0
 def test_launchctl_error(self):
     '''
     test launchctl function returning an error
     '''
     mock_cmd = MagicMock(return_value={'retcode': 1,
                                        'stdout': 'failure',
                                        'stderr': 'test failure'})
     error = 'Failed to enable service:\n' \
             'stdout: failure\n' \
             'stderr: test failure\n' \
             'retcode: 1'
     with patch('salt.modules.cmdmod.run_all', mock_cmd) as m_run_all:
         try:
             mac_utils.launchctl('enable', 'org.salt.minion')
         except CommandExecutionError as exc:
             self.assertEqual(exc.message, error)
         m_run_all.assert_called_with(['launchctl', 'enable', 'org.salt.minion'],
                                      python_shell=False)
Ejemplo n.º 6
0
 def test_launchctl_return_stdout(self):
     """
     test launchctl function and return stdout
     """
     mock_cmd = MagicMock(
         return_value={"retcode": 0, "stdout": "success", "stderr": "none"}
     )
     with patch("salt.utils.mac_utils.__salt__", {"cmd.run_all": mock_cmd}):
         ret = mac_utils.launchctl("enable", "org.salt.minion", return_stdout=True)
         self.assertEqual(ret, "success")
Ejemplo n.º 7
0
 def test_launchctl(self):
     '''
     test launchctl function
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0,
                                        'stdout': 'success',
                                        'stderr': 'none'})
     with patch('salt.utils.mac_utils.__salt__', {'cmd.run_all': mock_cmd}):
         ret = mac_utils.launchctl('enable', 'org.salt.minion')
         self.assertEqual(ret, True)
Ejemplo n.º 8
0
 def test_bootout_retcode_36_success(self):
     """
     Make sure that if we run a `launchctl bootout` cmd and it returns
     36 that we treat it as a success.
     """
     proc = MagicMock(return_value=MockTimedProc(
         stdout=None, stderr=None, returncode=36))
     with patch("salt.utils.timed_subprocess.TimedProc", proc):
         with patch("salt.utils.mac_utils.__salt__",
                    {"cmd.run_all": cmd._run_all_quiet}):
             ret = mac_utils.launchctl("bootout", "org.salt.minion")
     self.assertEqual(ret, True)
Ejemplo n.º 9
0
 def test_launchctl(self):
     '''
     test launchctl function
     '''
     mock_cmd = MagicMock(return_value={'retcode': 0,
                                        'stdout': 'success',
                                        'stderr': 'none'})
     with patch('salt.modules.cmdmod.run_all', mock_cmd) as m_run_all:
         ret = mac_utils.launchctl('enable', 'org.salt.minion')
         m_run_all.assert_called_with(
             ['launchctl', 'enable', 'org.salt.minion'],
             python_shell=False)
         self.assertEqual(ret, True)