Skip to content

Commit

Permalink
build: Provide a proper home dir to python tests that run "docker com…
Browse files Browse the repository at this point in the history
…pose".

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.
  • Loading branch information
jiceatscion committed Oct 3, 2023
1 parent 6c79632 commit dc4b786
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
8 changes: 7 additions & 1 deletion acceptance/common/raw.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
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,
args = [],
deps = [],
data = [],
tags = [],
homedir = "",
local = False):
py_library(
name = "%s_lib" % name,
Expand Down Expand Up @@ -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,
},
)
8 changes: 7 additions & 1 deletion acceptance/common/topogen.bzl
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -10,6 +15,7 @@ def topogen_test(
args = [],
deps = [],
data = [],
homedir = "",
tester = "//docker:tester"):
"""Creates a test based on a topology file.
Expand Down Expand Up @@ -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,
},
)

Expand Down
2 changes: 2 additions & 0 deletions acceptance/router_multi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ raw_test(
"--bfd",
],
data = data,
homedir = "$(rootpath :router)",
# This test uses sudo and accesses /var/run/netns.
local = True,
)
Expand All @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions acceptance/trc_update/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

0 comments on commit dc4b786

Please sign in to comment.