Skip to content

Commit 1ae3600

Browse files
committed
refactor(tmachine): compose feature environments from base environments
Define the base environments once and build the Keycloak and user-namespace variants from them with a shared helper, instead of listing the Ubuntu Docker variants by hand. Add a features table so a feature's setup playbooks and inputs apply to each base it supports. The Ubuntu Docker Keycloak environment now also gets the base's test-tools playbook, as the Fedora Keycloak environments already do. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent f3d9765 commit 1ae3600

2 files changed

Lines changed: 88 additions & 111 deletions

File tree

‎TESTING.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ nix run .#openshell-test-runner -- run \
331331
--family features --package keycloak-provider-refresh
332332
```
333333

334+
A suite that needs setup beyond a container engine runs in a feature
335+
environment, named `<base>-<feature>`, such as `ubuntu-docker-rootful-keycloak`. `features` in `tests/tmachine/config.nix`
336+
lists each feature's setup playbooks, the inputs they read, and the bases it
337+
supports.
338+
To add one, add an entry there and use the generated environment name in the
339+
suite's row in `.github/workflows/e2e-suites.yml`.
340+
334341
### Python E2E (`e2e/python/`)
335342

336343
`mise run e2e:python` builds `openshell/e2e-python:dev` from

‎tests/tmachine/config.nix‎

Lines changed: 81 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,90 @@ let
3434
openshell_sandbox_image = "../../artifacts/images/openshell-sandbox-tmachine.tar";
3535
openshell_supervisor_image = "../../artifacts/images/openshell-supervisor-tmachine.tar";
3636
};
37-
# A fedora-podman-<podman> environment ("rootful" or "rootless") with more
38-
# setup playbooks after the base ones.
39-
fedoraPodman =
40-
{
41-
name,
42-
podman,
43-
playbooks,
44-
inputs,
45-
}:
37+
fedoraPodman = podman: {
38+
machine = "fedora";
39+
use_galaxy = false;
40+
playbooks = [
41+
"ansible/playbooks/nextest.yaml"
42+
"ansible/playbooks/test-tools.yaml"
43+
"ansible/playbooks/selinux.yaml"
44+
"ansible/playbooks/podman-${podman}.yaml"
45+
];
46+
};
47+
# Base environments, keyed by name: a machine and the playbooks that set up
48+
# its container engine (or k3s).
49+
bases = {
50+
ubuntu-docker-rootful = {
51+
machine = "ubuntu";
52+
use_galaxy = true;
53+
playbooks = [
54+
"ansible/playbooks/nextest.yaml"
55+
"ansible/playbooks/test-tools.yaml"
56+
"ansible/playbooks/docker.yaml"
57+
];
58+
};
59+
ubuntu-k3s = {
60+
machine = "ubuntu";
61+
use_galaxy = false;
62+
playbooks = [
63+
"ansible/playbooks/nextest.yaml"
64+
"ansible/playbooks/test-tools.yaml"
65+
"ansible/playbooks/k3s.yaml"
66+
];
67+
};
68+
fedora-podman-rootful = fedoraPodman "rootful";
69+
fedora-podman-rootless = fedoraPodman "rootless";
70+
};
71+
dockerBases = [ "ubuntu-docker-rootful" ];
72+
podmanBases = [
73+
"fedora-podman-rootful"
74+
"fedora-podman-rootless"
75+
];
76+
# An environment named <base>-<suffix>: a base with more setup playbooks and
77+
# the inputs they read, run after the base's own.
78+
withSetup =
79+
base: suffix: setup:
80+
let
81+
parent = bases.${base};
82+
in
4683
{
47-
inherit name;
48-
machine = "fedora";
84+
name = "${base}-${suffix}";
85+
inherit (parent) machine;
4986
setup = {
50-
use_galaxy = false;
51-
playbooks = [
52-
"ansible/playbooks/nextest.yaml"
53-
"ansible/playbooks/test-tools.yaml"
54-
"ansible/playbooks/selinux.yaml"
55-
"ansible/playbooks/podman-${podman}.yaml"
56-
]
57-
++ playbooks;
58-
inherit inputs;
87+
inherit (parent) use_galaxy;
88+
playbooks = parent.playbooks ++ setup.playbooks;
89+
inputs = setup.inputs or { };
90+
};
91+
};
92+
# Feature environments, <base>-<feature>, one per base the feature supports.
93+
# A suite that needs a feature's setup runs in that environment, so the setup
94+
# lands in a cached layer and other suites don't carry it.
95+
features = {
96+
# Keycloak, for the keycloak-provider-refresh suite.
97+
keycloak = {
98+
bases = dockerBases ++ podmanBases;
99+
setup = {
100+
playbooks = [ "ansible/playbooks/keycloak.yaml" ];
101+
inputs.keycloak_realm_file = "../../scripts/keycloak-realm.json";
59102
};
60103
};
61-
# fedora-podman-{rootful,rootless}-keycloak run Keycloak for the
62-
# keycloak-provider-refresh suite.
63-
keycloakEnvironments = map (
64-
podman:
65-
fedoraPodman {
66-
name = "fedora-podman-${podman}-keycloak";
67-
inherit podman;
68-
playbooks = [ "ansible/playbooks/keycloak.yaml" ];
69-
inputs.keycloak_realm_file = "../../scripts/keycloak-realm.json";
70-
}
71-
) podmanModes;
72-
# fedora-podman-{rootful,rootless}-userns-{default,auto,keep-id,private}
73-
# configure the Podman gateway's user-namespace mode, for the Podman driver
74-
# suite. Every installer applies the mode through
75-
# /etc/openshell-test/gateway-overrides.toml.
104+
};
105+
featureEnvironments = pkgs.lib.concatMap (
106+
feature: map (base: withSetup base feature features.${feature}.setup) features.${feature}.bases
107+
) (builtins.attrNames features);
108+
# <podman base>-userns-{default,auto,keep-id,private} configure the Podman
109+
# gateway's user-namespace mode, for the Podman driver suite. Every installer
110+
# applies the mode through /etc/openshell-test/gateway-overrides.toml.
76111
podmanUsernsEnvironments = pkgs.lib.concatMap (
77-
podman:
112+
base:
78113
map (
79114
userns:
80-
fedoraPodman {
81-
name = "fedora-podman-${podman}-userns-${userns}";
82-
inherit podman;
115+
withSetup base "userns-${userns}" {
83116
playbooks = [ "ansible/playbooks/drivers/podman/userns.yaml" ];
84117
inputs.podman_userns_mode = userns;
85118
}
86119
) podmanUsernsModes
87-
) podmanModes;
88-
podmanModes = [
89-
"rootful"
90-
"rootless"
91-
];
120+
) podmanBases;
92121
podmanUsernsModes = [
93122
"default"
94123
"auto"
@@ -107,75 +136,16 @@ let
107136
}
108137
];
109138

110-
environments = [
111-
{
112-
name = "ubuntu-docker-rootful";
113-
machine = "ubuntu";
114-
setup = {
115-
use_galaxy = true;
116-
playbooks = [
117-
"ansible/playbooks/nextest.yaml"
118-
"ansible/playbooks/test-tools.yaml"
119-
"ansible/playbooks/docker.yaml"
120-
];
121-
};
122-
}
123-
{
124-
name = "ubuntu-docker-rootful-keycloak";
125-
machine = "ubuntu";
126-
setup = {
127-
use_galaxy = true;
128-
playbooks = [
129-
"ansible/playbooks/nextest.yaml"
130-
"ansible/playbooks/docker.yaml"
131-
"ansible/playbooks/keycloak.yaml"
132-
];
133-
inputs = {
134-
keycloak_realm_file = "../../scripts/keycloak-realm.json";
135-
};
136-
};
137-
}
138-
{
139-
name = "ubuntu-k3s";
140-
machine = "ubuntu";
141-
setup = {
142-
use_galaxy = false;
143-
playbooks = [
144-
"ansible/playbooks/nextest.yaml"
145-
"ansible/playbooks/test-tools.yaml"
146-
"ansible/playbooks/k3s.yaml"
147-
];
148-
};
149-
}
150-
{
151-
name = "fedora-podman-rootful";
152-
machine = "fedora";
153-
setup = {
154-
use_galaxy = false;
155-
playbooks = [
156-
"ansible/playbooks/nextest.yaml"
157-
"ansible/playbooks/test-tools.yaml"
158-
"ansible/playbooks/selinux.yaml"
159-
"ansible/playbooks/podman-rootful.yaml"
160-
];
161-
};
162-
}
163-
{
164-
name = "fedora-podman-rootless";
165-
machine = "fedora";
139+
environments =
140+
pkgs.lib.mapAttrsToList (name: base: {
141+
inherit name;
142+
inherit (base) machine;
166143
setup = {
167-
use_galaxy = false;
168-
playbooks = [
169-
"ansible/playbooks/nextest.yaml"
170-
"ansible/playbooks/test-tools.yaml"
171-
"ansible/playbooks/selinux.yaml"
172-
"ansible/playbooks/podman-rootless.yaml"
173-
];
144+
inherit (base) use_galaxy playbooks;
174145
};
175-
}
176-
]
177-
++ keycloakEnvironments
178-
++ podmanUsernsEnvironments;
146+
}) bases
147+
++ featureEnvironments
148+
++ podmanUsernsEnvironments;
179149

180150
installers = [
181151
{

0 commit comments

Comments
 (0)