Example #1
0
def test_cancel_experiment_with_purge_delete_failure(
        prepare_cancel_experiment_mocks: CancelExperimentMocks):
    RUN_QUEUED_COPY = copy.deepcopy(RUN_QUEUED)
    prepare_cancel_experiment_mocks.mocker.patch('commands.experiment.cancel.cancel_experiment_runs').return_value \
        = [RUN_QUEUED_COPY], []
    prepare_cancel_experiment_mocks.get_experiment.return_value = TEST_EXPERIMENTS[
        0]
    prepare_cancel_experiment_mocks.list_runs.return_value = [RUN_QUEUED_COPY]
    update_run_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        RUN_QUEUED_COPY, 'update')
    update_exp_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        TEST_EXPERIMENTS[0], 'update')
    # CAN-1099 - it should be uncommented after repairing docker gc
    # prepare_cancel_experiment_mocks.delete_images_for_experiment.side_effect = RuntimeError()
    cancel.purge_experiment(
        exp_name="experiment-1",
        runs_to_purge=[RUN_QUEUED_COPY],
        namespace="namespace",
        k8s_es_client=prepare_cancel_experiment_mocks.k8s_es_client)

    assert update_run_mock.call_count == 0
    assert update_exp_mock.call_count == 1
    check_cancel_experiment_asserts(prepare_cancel_experiment_mocks,
                                    delete_helm_release_count=1,
                                    delete_k8s_object_count=2)
Example #2
0
def test_cancel_experiment_purge_failure(
        prepare_cancel_experiment_mocks: CancelExperimentMocks):
    RUN_QUEUED_COPY = copy.deepcopy(RUN_QUEUED)
    prepare_cancel_experiment_mocks.mocker.patch('commands.experiment.cancel.cancel_experiment_runs').return_value \
        = [RUN_QUEUED_COPY], []
    prepare_cancel_experiment_mocks.get_experiment.return_value = TEST_EXPERIMENTS[
        0]
    prepare_cancel_experiment_mocks.list_runs.return_value = [RUN_QUEUED_COPY]
    prepare_cancel_experiment_mocks.delete_helm_release.side_effect = [
        RuntimeError
    ]
    update_run_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        RUN_QUEUED_COPY, 'update')
    update_exp_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        TEST_EXPERIMENTS[0], 'update')
    del_list, not_del_list = cancel.purge_experiment(
        exp_name="experiment-1",
        runs_to_purge=[RUN_QUEUED_COPY],
        namespace="namespace",
        k8s_es_client=prepare_cancel_experiment_mocks.k8s_es_client)

    assert len(del_list) == 0
    assert len(not_del_list) == 1
    assert update_exp_mock.call_count == 1
    assert update_run_mock.call_count == 0
    check_cancel_experiment_asserts(prepare_cancel_experiment_mocks,
                                    delete_helm_release_count=1)
Example #3
0
def test_cancel_experiment_success_with_purge(
        prepare_cancel_experiment_mocks: CancelExperimentMocks):
    RUN_QUEUED_COPY = copy.deepcopy(RUN_QUEUED)
    prepare_cancel_experiment_mocks.mocker.patch('commands.experiment.cancel.cancel_experiment_runs').return_value \
        = [RUN_QUEUED_COPY], []
    prepare_cancel_experiment_mocks.get_experiment.return_value = TEST_EXPERIMENTS[
        0]
    prepare_cancel_experiment_mocks.list_runs.return_value = [RUN_QUEUED_COPY]
    update_run_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        RUN_QUEUED_COPY, 'update')
    update_exp_mock = prepare_cancel_experiment_mocks.mocker.patch.object(
        TEST_EXPERIMENTS[0], 'update')
    cancel.purge_experiment(
        exp_name="experiment-1",
        runs_to_purge=[RUN_QUEUED_COPY],
        namespace="namespace",
        k8s_es_client=prepare_cancel_experiment_mocks.k8s_es_client)

    assert update_exp_mock.call_count == 1
    assert update_run_mock.call_count == 0
    check_cancel_experiment_asserts(prepare_cancel_experiment_mocks,
                                    delete_helm_release_count=1,
                                    delete_k8s_object_count=2)