Exemplo n.º 1
0
def test_create_namespaced_job_fails_outside_cluster():
    environment = DaskKubernetesEnvironment()
    storage = Docker(registry_url="test1", image_name="test2", image_tag="test3")

    with pytest.raises(EnvironmentError):
        with set_temporary_config({"cloud.auth_token": "test"}):
            flow = base_flow
            flow.storage = storage
            with set_temporary_config({"cloud.auth_token": "test"}):
                environment.execute(flow=flow)
Exemplo n.º 2
0
def test_execute(monkeypatch):
    environment = DaskKubernetesEnvironment()
    storage = Docker(registry_url="test1", image_name="test2", image_tag="test3")

    create_flow_run = MagicMock()
    monkeypatch.setattr(
        "prefect.environments.DaskKubernetesEnvironment.create_flow_run_job",
        create_flow_run,
    )

    environment.execute(storage=storage, flow_location="")

    assert create_flow_run.call_args[1]["docker_name"] == "test1/test2:test3"
Exemplo n.º 3
0
def test_execute(monkeypatch):
    environment = DaskKubernetesEnvironment()

    config = MagicMock()
    monkeypatch.setattr("kubernetes.config", config)

    batchv1 = MagicMock()
    monkeypatch.setattr("kubernetes.client",
                        MagicMock(BatchV1Api=MagicMock(return_value=batchv1)))

    environment = DaskKubernetesEnvironment()
    storage = Docker(registry_url="test1",
                     image_name="test2",
                     image_tag="test3")

    flow = base_flow
    flow.storage = storage
    with set_temporary_config({"cloud.auth_token": "test"}):
        environment.execute(flow=flow)

    assert (batchv1.create_namespaced_job.call_args[1]["body"]["apiVersion"] ==
            "batch/v1")
def test_execute_storage_missing_fields():
    environment = DaskKubernetesEnvironment()
    with pytest.raises(ValueError):
        environment.execute(storage=Docker(), flow_location="")
def test_execute_improper_storage():
    environment = DaskKubernetesEnvironment()
    with pytest.raises(TypeError):
        environment.execute(storage=Local(), flow_location="")