예제 #1
0
def test_main_timeout_failure():
    fake_container_id = 'fake_container_id'
    fake_timeout = 3
    with contextlib.nested(
            mock.patch(
                'paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                return_value=fake_container_id,
                autospec=True),
            mock.patch('paasta_tools.paasta_execute_docker_command.parse_args',
                       autospec=True),
            mock.patch(
                'paasta_tools.paasta_execute_docker_command.execute_in_container',
                return_value=('fake_output', 0),
                autospec=True),
            mock.patch('paasta_tools.paasta_execute_docker_command.time_limit',
                       side_effect=TimeoutException,
                       autospec=True),
    ) as (
            get_id_patch,
            args_patch,
            exec_patch,
            time_limit_patch,
    ):
        args_patch.return_value.mesos_id = 'fake_task_id'
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        time_limit_patch.assert_called_once_with(fake_timeout)
        assert excinfo.value.code == 1
예제 #2
0
def test_main_timeout_failure():
    fake_container_id = "fake_container_id"
    fake_timeout = 3
    with mock.patch(
            "paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id",
            return_value=fake_container_id,
            autospec=True,
    ), mock.patch(
            "paasta_tools.paasta_execute_docker_command.parse_args",
            autospec=True
    ) as args_patch, mock.patch(
            "paasta_tools.paasta_execute_docker_command.execute_in_container",
            return_value=("fake_output", 0),
            autospec=True,
    ), mock.patch(
            "paasta_tools.paasta_execute_docker_command.time_limit",
            side_effect=TimeoutException,
            autospec=True,
    ) as time_limit_patch:
        args_patch.return_value.mesos_id = "fake_task_id"
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        time_limit_patch.assert_called_once_with(fake_timeout)
        assert excinfo.value.code == 1
예제 #3
0
def test_main_cmd_unclean_exit_failure():
    fake_container_id = 'fake_container_id'
    with contextlib.nested(
            mock.patch(
                'paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                return_value=fake_container_id,
                autospec=True),
            mock.patch(
                'paasta_tools.paasta_execute_docker_command.execute_in_container',
                return_value=('fake_output', 2),
                autospec=True),
            mock.patch('paasta_tools.paasta_execute_docker_command.parse_args',
                       autospec=True),
            mock.patch('paasta_tools.paasta_execute_docker_command.time_limit',
                       autospec=True),
    ) as (
            get_id_patch,
            exec_patch,
            args_patch,
            time_limit_patch,
    ):
        args_patch.return_value.mesos_id = 'fake_task_id'
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 2
예제 #4
0
def test_main_container_not_found_failure():
    with mock.patch(
        'paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
        return_value=None, autospec=True,
    ), mock.patch(
        'paasta_tools.paasta_execute_docker_command.execute_in_container',
        return_value=('fake_output', 2), autospec=True,
    ), mock.patch(
        'paasta_tools.paasta_execute_docker_command.parse_args', autospec=True,
    ) as args_patch, mock.patch(
        'paasta_tools.paasta_execute_docker_command.time_limit', autospec=True,
    ):
        args_patch.return_value.mesos_id = 'fake_task_id'
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 1
def test_main_container_not_found_failure():
    with contextlib.nested(
        mock.patch('paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                   return_value=None, autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.execute_in_container',
                   return_value=('fake_output', 2), autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.parse_args', autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.time_limit', autospec=True),
    ) as (
        get_id_patch,
        exec_patch,
        args_patch,
        time_limit_patch,
    ):
        args_patch.return_value.mesos_id = 'fake_task_id'
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 1
예제 #6
0
def test_main_cmd_unclean_exit_failure():
    fake_container_id = "fake_container_id"
    with mock.patch(
            "paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id",
            return_value=fake_container_id,
            autospec=True,
    ), mock.patch(
            "paasta_tools.paasta_execute_docker_command.execute_in_container",
            return_value=("fake_output", 2),
            autospec=True,
    ), mock.patch("paasta_tools.paasta_execute_docker_command.parse_args",
                  autospec=True) as args_patch, mock.patch(
                      "paasta_tools.paasta_execute_docker_command.time_limit",
                      autospec=True):
        args_patch.return_value.mesos_id = "fake_task_id"
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 2
예제 #7
0
def test_main_with_empty_task_id():
    fake_container_id = 'fake_container_id'
    fake_timeout = 3
    with mock.patch(
        'paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
        return_value=fake_container_id, autospec=True,
    ), mock.patch(
        'paasta_tools.paasta_execute_docker_command.parse_args', autospec=True,
    ) as args_patch, mock.patch(
        'paasta_tools.paasta_execute_docker_command.execute_in_container',
        return_value=('fake_output', 0), autospec=True,
    ), mock.patch(
        'paasta_tools.paasta_execute_docker_command.time_limit', autospec=True,
    ):
        args_patch.return_value.mesos_id = ''
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 2
def test_main_with_empty_task_id():
    fake_container_id = 'fake_container_id'
    fake_timeout = 3
    with contextlib.nested(
        mock.patch('paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                   return_value=fake_container_id, autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.parse_args', autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.execute_in_container',
                   return_value=('fake_output', 0), autospec=True),
        mock.patch('paasta_tools.paasta_execute_docker_command.time_limit', autospec=True),
    ) as (
        get_id_patch,
        args_patch,
        exec_patch,
        time_limit_patch,
    ):
        args_patch.return_value.mesos_id = ''
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 2
예제 #9
0
def test_main_with_empty_task_id():
    fake_container_id = 'fake_container_id'
    fake_timeout = 3
    with contextlib.nested(
        mock.patch('paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                   return_value=fake_container_id),
        mock.patch('paasta_tools.paasta_execute_docker_command.parse_args'),
        mock.patch('paasta_tools.paasta_execute_docker_command.execute_in_container',
                   return_value=('fake_output', 0)),
        mock.patch('paasta_tools.paasta_execute_docker_command.time_limit')
    ) as (
        get_id_patch,
        args_patch,
        exec_patch,
        time_limit_patch,
    ):
        args_patch.return_value.mesos_id = ''
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        assert excinfo.value.code == 2
def test_main():
    fake_container_id = 'fake_container_id'
    fake_timeout = 3
    with contextlib.nested(
        mock.patch('paasta_tools.paasta_execute_docker_command.get_container_id_for_mesos_id',
                   return_value=fake_container_id),
        mock.patch('paasta_tools.paasta_execute_docker_command.parse_args'),
        mock.patch('paasta_tools.paasta_execute_docker_command.execute_in_container',
                   return_value=('fake_output', 0)),
        mock.patch('paasta_tools.paasta_execute_docker_command.time_limit')
    ) as (
        get_id_patch,
        args_patch,
        exec_patch,
        time_limit_patch,
    ):
        args_patch.return_value.mesos_id = 'fake_task_id'
        args_patch.return_value.timeout = fake_timeout
        with pytest.raises(SystemExit) as excinfo:
            main()
        time_limit_patch.assert_called_once_with(fake_timeout)
        assert excinfo.value.code == 0