From dc4b7865f693ba29326e267297d52fc7fd983ed8 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hugly Date: Tue, 3 Oct 2023 13:02:14 +0200 Subject: [PATCH] build: Provide a proper home dir to python tests that run "docker compose". This is due to a bug in some version of docker-compose v2 that causes an unused .cache directory to be created in $HOME. Due to a bug in Bazel, tests don't have a HOME variable (it should be set to $TEST_TMPDIR but isn't set at all). So we must provide one ourselves. My previous work around of using /tmp had the potential of creating collisions in the future. This method is cleaner. It uses an output location internal to the test. This is the simplest I could manage. Tools are supposed to be enablers, but Bazel prefers to be a disabler it seems. --- BUILD.bazel | 1 + acceptance/common/raw.bzl | 8 +++++++- acceptance/common/topogen.bzl | 8 +++++++- acceptance/router_multi/BUILD.bazel | 2 ++ acceptance/trc_update/BUILD.bazel | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index be76b0e6c1..267914fd4b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -245,6 +245,7 @@ updatesrc_update_all( write_source_files( name = "write_all_source_files", additional_update_targets = [ + "//doc/_build/_static/command:write_files", "//doc/command:write_files", ], ) diff --git a/acceptance/common/raw.bzl b/acceptance/common/raw.bzl index ba16e2b23b..2f024ca8d9 100644 --- a/acceptance/common/raw.bzl +++ b/acceptance/common/raw.bzl @@ -1,6 +1,11 @@ load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test") load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement") +# Bug in bazel: HOME isn't set to TEST_TMPDIR. +# Bug in docker-compose v2.21 a writable HOME is required (eventhough not used). +# Poor design in Bazel, there's no sane way to obtain the path to some +# location that's not a litteral dependency. +# So, HOME must be provided by the invoker. def raw_test( name, src, @@ -8,6 +13,7 @@ def raw_test( deps = [], data = [], tags = [], + homedir = "", local = False): py_library( name = "%s_lib" % name, @@ -63,6 +69,6 @@ def raw_test( "PYTHONUNBUFFERED": "1", # Ensure that unicode output can be printed to the log/console "PYTHONIOENCODING": "utf-8", - "HOME": "/tmp", + "HOME": homedir, }, ) diff --git a/acceptance/common/topogen.bzl b/acceptance/common/topogen.bzl index b92967e269..08d90df42f 100644 --- a/acceptance/common/topogen.bzl +++ b/acceptance/common/topogen.bzl @@ -1,6 +1,11 @@ load("//tools/lint:py.bzl", "py_binary", "py_library", "py_test") load("@com_github_scionproto_scion_python_deps//:requirements.bzl", "requirement") +# Bug in bazel: HOME isn't set to TEST_TMPDIR. +# Bug in docker-compose v2.21 a writable HOME is required (eventhough not used). +# Poor design in Bazel, there's no sane way to obtain the path to some +# location that's not a litteral dependency. +# So, HOME must be provided by the invoker. def topogen_test( name, src, @@ -10,6 +15,7 @@ def topogen_test( args = [], deps = [], data = [], + homedir = "", tester = "//docker:tester"): """Creates a test based on a topology file. @@ -105,7 +111,7 @@ def topogen_test( "PYTHONUNBUFFERED": "1", # Ensure that unicode output can be printed to the log/console "PYTHONIOENCODING": "utf-8", - "HOME": "/tmp", + "HOME": homedir, }, ) diff --git a/acceptance/router_multi/BUILD.bazel b/acceptance/router_multi/BUILD.bazel index 1809014062..762c404da2 100644 --- a/acceptance/router_multi/BUILD.bazel +++ b/acceptance/router_multi/BUILD.bazel @@ -30,6 +30,7 @@ raw_test( "--bfd", ], data = data, + homedir = "$(rootpath :router)", # This test uses sudo and accesses /var/run/netns. local = True, ) @@ -39,6 +40,7 @@ raw_test( src = "test.py", args = args, data = data, + homedir = "$(rootpath :router)", # This test uses sudo and accesses /var/run/netns. local = True, ) diff --git a/acceptance/trc_update/BUILD.bazel b/acceptance/trc_update/BUILD.bazel index 4f91062faf..6e8125faf7 100644 --- a/acceptance/trc_update/BUILD.bazel +++ b/acceptance/trc_update/BUILD.bazel @@ -7,5 +7,6 @@ topogen_test( "--executable=end2end_integration:$(location //tools/end2end_integration)", ], data = ["//tools/end2end_integration"], + homedir = "$(rootpath //tools/end2end_integration)", topo = "//topology:tiny4.topo", )