def test_docker_agent_deploy_flow_does_not_include_host_gateway_for_old_engine_versions( api, docker_engine_version): api.version.return_value = {"Version": docker_engine_version} run = UniversalRun() storage = Local() agent = DockerAgent() with pytest.warns( UserWarning, match= ("`host.docker.internal` could not be automatically resolved.*" f"feature is not supported on Docker Engine v{docker_engine_version}" ), ): agent.deploy_flow(flow_run=GraphQLResult({ "flow": GraphQLResult({ "id": "foo", "name": "flow-name", "storage": storage.serialize(), "core_version": "0.13.11", }), "run_config": run.serialize() if run else None, "id": "id", "name": "name", })) assert "extra_hosts" not in api.create_host_config.call_args[1]
def build_flow_run(self, config, storage=None, core_version="0.13.0"): if storage is None: storage = Local() return GraphQLResult({ "flow": GraphQLResult({ "storage": storage.serialize(), "id": "new_id", "core_version": core_version, }), "run_config": None if config is None else config.serialize(), "id": "id", })
def generate_task_definition(self, run_config, storage=None, **kwargs): if storage is None: storage = Local() agent = ECSAgent(**kwargs) flow_run = GraphQLResult({ "flow": GraphQLResult({ "storage": storage.serialize(), "run_config": run_config.serialize(), "id": "flow-id", "version": 1, "name": "Test Flow", "core_version": "0.13.0", }), "id": "flow-run-id", }) return agent.generate_task_definition(flow_run, run_config)
def test_load_and_run_flow(monkeypatch, tmpdir): myflow = Flow("test-flow") # This is gross. Since the flow is pickled/unpickled, there's no easy way # to access the same object to set a flag. Resort to setting an environment # variable as a global flag that won't get copied eagerly through # cloudpickle. monkeypatch.setenv("TEST_RUN_CALLED", "FALSE") class MyEnvironment(Environment): def run(self, flow): assert flow is myflow os.environ["TEST_RUN_CALLED"] = "TRUE" myflow.environment = MyEnvironment() storage = Local(str(tmpdir)) myflow.storage = storage storage.add_flow(myflow) gql_return = MagicMock(return_value=MagicMock(data=MagicMock(flow_run=[ GraphQLResult({ "flow": GraphQLResult({ "name": myflow.name, "storage": storage.serialize() }) }) ], ))) client = MagicMock() client.return_value.graphql = gql_return monkeypatch.setattr("prefect.environments.execution.base.Client", client) with set_temporary_config({"cloud.auth_token": "test"}), prefect.context({"flow_run_id": "id"}): load_and_run_flow() assert os.environ["TEST_RUN_CALLED"] == "TRUE"