Esempio n. 1
0
def test_waiting_for_pod_container_creation():
    mock_client = create_mocked_client(timer=create_timing_out_timer(
        num_good_ticks=2))
    single_waiting_pod = _pod_list_for_container_status(
        _create_status(
            state=V1ContainerState(waiting=V1ContainerStateWaiting(
                reason=KubernetesWaitingReasons.ContainerCreating)),
            ready=False,
        ))
    single_ready_running_pod = _pod_list_for_container_status(
        _ready_running_status())

    mock_client.core_api.list_namespaced_pod.side_effect = [
        single_waiting_pod,
        single_ready_running_pod,
    ]

    pod_name = "a_pod"
    mock_client.wait_for_pod(pod_name=pod_name, namespace="namespace")

    assert_logger_calls(
        mock_client.logger,
        [
            'Waiting for pod "%s"' % pod_name,
            "Waiting for container creation...",
            'Pod "%s" is ready, done waiting' % pod_name,
        ],
    )
    # slept only once
    assert len(mock_client.sleeper.mock_calls) == 1
Esempio n. 2
0
def test_bad_waiting_state():
    mock_client = create_mocked_client(timer=create_timing_out_timer(
        num_good_ticks=2))
    single_waiting_pod = _pod_list_for_container_status(
        _create_status(
            state=V1ContainerState(waiting=V1ContainerStateWaiting(
                reason="InvalidReason")),
            ready=False,
        ))
    mock_client.core_api.list_namespaced_pod.side_effect = [single_waiting_pod]
    pod_name = "a_pod"
    with pytest.raises(DagsterK8sError) as exc_info:
        mock_client.wait_for_pod(pod_name=pod_name, namespace="namespace")

    assert str(
        exc_info.value
    ) == "Unknown issue: {'message': None, 'reason': 'InvalidReason'}"
Esempio n. 3
0
def test_valid_failure_waiting_reasons():
    mock_client = create_mocked_client()
    for reason in [
            KubernetesWaitingReasons.ErrImagePull,
            KubernetesWaitingReasons.ImagePullBackOff,
            KubernetesWaitingReasons.CrashLoopBackOff,
            KubernetesWaitingReasons.RunContainerError,
    ]:
        single_waiting_pod_failure = _pod_list_for_container_status(
            _create_status(
                state=V1ContainerState(waiting=V1ContainerStateWaiting(
                    reason=reason, message="bad things")),
                ready=False,
            ))
        mock_client.core_api.list_namespaced_pod.side_effect = [
            single_waiting_pod_failure,
        ]
        pod_name = "a_pod"
        with pytest.raises(DagsterK8sError) as exc_info:
            mock_client.wait_for_pod(pod_name=pod_name, namespace="namespace")
        assert str(
            exc_info.value
        ) == 'Failed: Reason="{reason}" Message="bad things"'.format(
            reason=reason)