Пример #1
0
    def test_winrm_run_cmd_timeout(self, mock_get_command_output):
        mock_protocol = mock.MagicMock()
        mock_protocol.open_shell.return_value = 123
        mock_protocol.run_command.return_value = 456
        mock_session = mock.MagicMock(protocol=mock_protocol)
        mock_get_command_output.side_effect = WinRmRunnerTimoutError(
            Response(("", "", 5)))

        self._init_runner()
        result = self._runner._winrm_run_cmd(
            mock_session,
            "fake-command",
            args=["arg1", "arg2"],
            env={"PATH": "C:\\st2\\bin"},
            cwd="C:\\st2",
        )
        expected_response = Response(("", "", 5))
        expected_response.timeout = True

        self.assertEqual(result.__dict__, expected_response.__dict__)
        mock_protocol.open_shell.assert_called_with(
            env_vars={"PATH": "C:\\st2\\bin"}, working_directory="C:\\st2")
        mock_protocol.run_command.assert_called_with(123, "fake-command",
                                                     ["arg1", "arg2"])
        mock_protocol.cleanup_command.assert_called_with(123, 456)
        mock_protocol.close_shell.assert_called_with(123)
Пример #2
0
 def test_win_rm_runner_timout_error(self):
     error = WinRmRunnerTimoutError('test_response')
     self.assertIsInstance(error, Exception)
     self.assertEquals(error.response, 'test_response')
     with self.assertRaises(WinRmRunnerTimoutError):
         raise WinRmRunnerTimoutError('test raising')