Skip to content

Commit fb21680

Browse files
committed
buildstream-plugins-community: run the test suite as a NixOS VM test
The upstream pytest suite needs `buildstream` present (including its shared source-plugin test helpers and templated repo-kind tests) and needs buildbox-casd's real FUSE-based staging, which needs `/dev/fuse` and a working mount path that the Nix build sandbox doesn't provide. Add nixosTests.buildstream-plugins-community and point passthru.tests.pytest at it instead: programs.fuse.enable gives real /dev/fuse access, so the suite exercises the actual FUSE-backed staging path. `buildstream`'s own `bst` entry point bakes its dependencies' site-packages directories into that script rather than exposing them under its own site-packages directory, so `toPythonModule` is used to pull `buildstream` and its dependencies into a shared environment that `pytest` can import from. Deselect the handful of tests that reach out to gitlab.com for real network fetches (bazel/bazel_file manifest downloads, the git-lfs test repo), since network access isn't available in the test VM either. Also deselect the shared repo-kind tests pulled in from buildstream._testing._sourcetests via sourcetests_collection_hook: pytest-datafiles copies their datafiles fixtures from buildstream's own installed (Nix-store-read-only) package data, preserving the missing write bit, so code that writes into the copy fails with PermissionError. This is the same upstream bug as apache/buildstream#2196 (see also PR NixOS#510073 for the same fix in the sibling buildstream-plugins package), and isn't specific to the build sandbox, so it still applies in the VM. Assisted-by: Claude <[email protected]>
1 parent 3a9391d commit fb21680

3 files changed

Lines changed: 100 additions & 2 deletions

File tree

‎nixos/tests/all-tests.nix‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ in
380380
budgie = runTest ./budgie.nix;
381381
buildbot = runTest ./buildbot.nix;
382382
buildkite-agents = runTest ./buildkite-agents.nix;
383+
buildstream-plugins-community = runTest ./buildstream-plugins-community.nix;
383384
bulwark = runTest ./bulwark.nix;
384385
c2fmzq = runTest ./c2fmzq.nix;
385386
caddy = runTest ./caddy.nix;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{ pkgs, lib, ... }:
2+
let
3+
bstPluginsCommunity = pkgs.python3Packages.buildstream-plugins-community;
4+
5+
# These reach out to gitlab.com to download real files (bazel manifest
6+
# fetches, git-lfs test repo), which isn't possible in this VM either.
7+
deselectedTests = [
8+
"tests/sources/bazel.py::test_basic"
9+
"tests/sources/bazel.py::test_multi_url"
10+
"tests/sources/bazel_file.py::test_basic"
11+
"tests/sources/bazel_file.py::test_multi_url"
12+
"tests/sources/git_tag.py::test_gitlfs"
13+
"tests/sources/git_tag.py::test_gitlfs_off"
14+
"tests/sources/git_tag.py::test_gitlfs_notset"
15+
16+
# These are the shared repo-kind tests that `tests/conftest.py` pulls in
17+
# from `buildstream._testing._sourcetests` via `sourcetests_collection_hook`.
18+
# Their datafiles fixtures are project templates bundled inside the
19+
# already-installed (and therefore read-only, per the Nix store)
20+
# `buildstream` package; `pytest-datafiles` copies them with
21+
# `shutil.copytree`/`copy`, which preserve the source's (missing) write
22+
# bit, so code that writes into the copy (e.g. `add_plugins_conf`'s
23+
# atomic yaml dump) fails with `PermissionError`. This isn't specific to
24+
# the Nix build sandbox, so it still applies here.
25+
"build_checkout.py::test_fetch_build_checkout"
26+
"fetch.py::test_fetch"
27+
"fetch.py::test_fetch_cross_junction"
28+
"mirror.py::test_mirror_fetch"
29+
"mirror.py::test_mirror_fetch_upstream_absent"
30+
"mirror.py::test_mirror_from_includes"
31+
"mirror.py::test_mirror_track_upstream_present"
32+
"mirror.py::test_mirror_track_upstream_absent"
33+
"track.py::test_track"
34+
"track.py::test_track_recurse"
35+
"track.py::test_track_recurse_except"
36+
"track.py::test_cross_junction"
37+
"track.py::test_track_include"
38+
"track.py::test_track_include_junction"
39+
"track.py::test_track_junction_included"
40+
"workspace.py::test_open"
41+
];
42+
43+
# `buildstream`'s own `bst` entry point bakes its dependencies' site-packages
44+
# directories directly into that script (via `site.addsitedir`), rather than
45+
# exposing them under `${buildstream}/${python3.sitePackages}`; `toPythonModule`
46+
# is needed to pull `buildstream` and its dependencies into a shared
47+
# environment that `pytest` can import from.
48+
pythonEnv = pkgs.python3.withPackages (
49+
ps: with ps; [
50+
(ps.toPythonModule pkgs.buildstream)
51+
bstPluginsCommunity
52+
pytest
53+
pytest-datafiles
54+
pytest-env
55+
pytest-xdist
56+
pyftpdlib
57+
]
58+
);
59+
in
60+
{
61+
name = "buildstream-plugins-community";
62+
63+
meta.maintainers = with pkgs.lib.maintainers; [ shymega ];
64+
65+
nodes.machine =
66+
{ pkgs, ... }:
67+
{
68+
# buildbox-casd finds `buildbox-fuse` on PATH and defaults to real
69+
# FUSE-based staging, which needs `/dev/fuse` and a working mount
70+
# path that the Nix build sandbox can't provide. Running here as a
71+
# VM test instead exercises the real FUSE-backed path.
72+
programs.fuse.enable = true;
73+
74+
environment.systemPackages = [
75+
pythonEnv
76+
pkgs.buildbox
77+
pkgs.gitMinimal
78+
pkgs.ostree
79+
];
80+
};
81+
82+
testScript = ''
83+
machine.succeed("cp -r ${bstPluginsCommunity.src} /tmp/src && chmod -R u+w /tmp/src")
84+
machine.succeed(
85+
"cd /tmp/src && HOME=/root ${pythonEnv}/bin/pytest"
86+
+ " ${lib.concatStringsSep " " (map (t: "--deselect=${t}") deselectedTests)}"
87+
)
88+
'';
89+
}

‎pkgs/development/python-modules/buildstream-plugins-community/default.nix‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
buildPythonPackage,
44
fetchFromGitLab,
55
gitUpdater,
6+
nixosTests,
67
setuptools,
78
setuptools-scm,
89

@@ -48,12 +49,19 @@ buildPythonPackage (finalAttrs: {
4849
# always has `buildstream` in its environment when imported; drop it from
4950
# the wheel's declared dependencies instead of propagating it as a
5051
# `dependencies` entry, to avoid pulling a second `buildstream` closure
51-
# into consumers that already bundle it.
52+
# into consumers that already bundle it. Its test suite, which does need
53+
# `buildstream` present, and needs real `/dev/fuse` access that the Nix
54+
# build sandbox doesn't provide, is run as a NixOS VM test instead; see
55+
# `passthru.tests.pytest`.
5256
pythonRemoveDeps = [ "buildstream" ];
5357

5458
pythonImportsCheck = [ "buildstream_plugins_community" ];
5559

56-
passthru.updateScript = gitUpdater { };
60+
passthru = {
61+
updateScript = gitUpdater { };
62+
63+
tests.pytest = nixosTests.buildstream-plugins-community;
64+
};
5765

5866
meta = {
5967
changelog = "https://gitlab.com/BuildStream/buildstream-plugins-community/-/blob/${finalAttrs.src.tag}/NEWS";

0 commit comments

Comments
 (0)