Skip to content

Commit d90a519

Browse files
test(tmachine): add a gateway_overrides role for environment gateway settings
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 89975a4 commit d90a519

8 files changed

Lines changed: 125 additions & 72 deletions

File tree

‎TESTING.md‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ service.
324324
clients there from the variables. A missing variable fails the test; it
325325
never skips it.
326326
- **Documentation.** Document the variables in the fixture's module docs, so
327-
anyone can run the suite against their own deployment by setting them.
327+
anyone can run the suite against their own deployment by setting them, and
328+
add a row for each to the
329+
[environment contract table](tests/support/README.md#environment-contract).
328330

329331
The Keycloak fixture is `tests/support/keycloak`. Run the suite that uses it
330332
with:
@@ -596,11 +598,26 @@ nix run .#openshell-test-runner -- run \
596598

597599
#### Gateway overrides in an environment
598600

599-
An environment overrides gateway settings by writing the tables to change to
600-
`/etc/openshell-test/gateway-overrides.toml` in a playbook that runs before the
601-
installer. The file holds whole tables, such as `[openshell.gateway]` or
602-
`[openshell.drivers.podman]`, and is not a complete configuration. Each
603-
installer applies it to the gateway's own file:
601+
An environment overrides gateway settings with the `gateway_overrides` role,
602+
which takes a name and the tables to change, such as `[openshell.gateway]` or
603+
`[openshell.drivers.podman]`:
604+
605+
```yaml
606+
- name: Push configuration to supervisors
607+
ansible.builtin.include_role:
608+
name: gateway_overrides
609+
vars:
610+
gateway_overrides_name: config-push
611+
gateway_overrides_content: |
612+
[openshell.gateway]
613+
config_delivery_mode = "push"
614+
```
615+
616+
The role writes each name as its own marked block in
617+
`/etc/openshell-test/gateway-overrides.toml`, so writers keep each other's
618+
settings. Two blocks must not declare the same table. Don't write the file
619+
directly. The file is not a complete configuration. Each installer applies it
620+
to the gateway's own file:
604621

605622
- `binaries` applies it to the `/etc/openshell/gateway.toml` it generates.
606623
- `deb` and `rpm` apply it to the service user's

‎tests/tmachine/ansible/playbooks/drivers/podman/userns.yaml‎

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
# Configure the Podman gateway's user-namespace mode and publish it.
55
#
66
# `podman_userns_mode` is default, auto, keep-id or private. Every mode except
7-
# default writes its `[openshell.drivers.podman]` settings to
8-
# `/etc/openshell-test/gateway-overrides.toml`, which every installer applies to the active
9-
# gateway-overrides.toml (the openshell_gateway role for `binaries`, the
10-
# openshell_packaged_gateway role for the packages); default removes the file. The
11-
# Podman support crate (tests/support/podman) reads the published mode and
12-
# runs Podman's own reference container in it.
7+
# default adds its `[openshell.drivers.podman]` settings to the gateway
8+
# overrides (the gateway_overrides role), which every installer applies to the
9+
# gateway's configuration. Default mode adds nothing, so userns, uidmap and
10+
# gidmap stay unset. The Podman support crate (tests/support/podman) reads the
11+
# published mode and runs Podman's own reference container in it.
1312
---
1413
- name: Podman user namespaces for tests
1514
hosts: all
1615
gather_facts: false
1716
vars:
18-
podman_userns_driver_config: /etc/openshell-test/gateway-overrides.toml
1917
podman_userns_settings:
2018
default: ""
2119
auto: |
@@ -43,34 +41,14 @@
4341
{{ podman_userns_settings.keys() | join(', ') }}, not
4442
{{ podman_userns_mode | default('unset') }}
4543
46-
- name: Create the test configuration directory
47-
become: true
48-
ansible.builtin.file:
49-
path: "{{ podman_userns_driver_config | dirname }}"
50-
state: directory
51-
owner: root
52-
group: root
53-
mode: "0755"
54-
5544
- name: Write the Podman driver user-namespace settings
56-
become: true
57-
ansible.builtin.copy:
58-
dest: "{{ podman_userns_driver_config }}"
59-
content: "{{ podman_userns_settings[podman_userns_mode] }}"
60-
owner: root
61-
group: root
62-
mode: "0644"
45+
ansible.builtin.include_role:
46+
name: gateway_overrides
47+
vars:
48+
gateway_overrides_name: podman-userns
49+
gateway_overrides_content: "{{ podman_userns_settings[podman_userns_mode] }}"
6350
when: podman_userns_mode != "default"
6451

65-
# The fragment is the only source of userns, uidmap and gidmap settings in
66-
# the gateway's configuration, so default mode leaves them unset.
67-
- name: Remove Podman driver user-namespace settings for default mode
68-
become: true
69-
ansible.builtin.file:
70-
path: "{{ podman_userns_driver_config }}"
71-
state: absent
72-
when: podman_userns_mode == "default"
73-
7452
- name: Publish Podman user-namespace test variables
7553
ansible.builtin.include_tasks: ../../test-env.yaml
7654
vars:

‎tests/tmachine/ansible/roles/cdi_fixtures/tasks/main.yaml‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,11 @@
3838
# The tests select the scenario device per sandbox through driver config, which
3939
# the gateway rejects unless an administrator allows it. The installers add
4040
# this to the active driver's settings.
41-
- name: Create the test settings directory
42-
become: true
43-
ansible.builtin.file:
44-
path: /etc/openshell-test
45-
state: directory
46-
owner: root
47-
group: root
48-
mode: "0755"
49-
50-
# The gateway must accept a per-sandbox CDI device, which it does only when the
51-
# driver allows caller driver config. Every installer merges this override into
52-
# the gateway's own configuration (see openshell_gateway/tasks/merge-settings.yaml).
5341
- name: Allow caller driver config for the CDI tests
54-
become: true
55-
ansible.builtin.copy:
56-
dest: /etc/openshell-test/gateway-overrides.toml
57-
content: |
42+
ansible.builtin.include_role:
43+
name: gateway_overrides
44+
vars:
45+
gateway_overrides_name: cdi
46+
gateway_overrides_content: |
5847
[openshell.drivers.{{ environment_driver }}]
5948
allow_driver_config = true
60-
owner: root
61-
group: root
62-
mode: "0644"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
gateway_overrides_path: /etc/openshell-test/gateway-overrides.toml
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Add gateway settings to /etc/openshell-test/gateway-overrides.toml, which
5+
# the `binaries`, `deb` and `rpm` installers apply to the gateway's
6+
# configuration (openshell_gateway/tasks/merge-settings.yaml; k3s installers
7+
# ignore it).
8+
#
9+
# Inputs:
10+
# gateway_overrides_name names the marked block, such as `cdi`; writing
11+
# the same name again replaces its block
12+
# gateway_overrides_content whole TOML tables, such as
13+
# `[openshell.drivers.podman]`
14+
#
15+
# Each name gets its own marked block, so writers keep each other's settings
16+
# and may run in any order. Two blocks must not declare the same table: TOML
17+
# rejects a table defined twice, and the installer fails on it.
18+
#
19+
# TODO: https://github.com/NVIDIA/OpenShell/pull/5489 reads gateway.d drop-in
20+
# files. When it lands, write each name to its own drop-in here instead.
21+
---
22+
- name: Require a gateway override name and content
23+
ansible.builtin.assert:
24+
that:
25+
- gateway_overrides_name is defined
26+
- gateway_overrides_name is match('^[a-z0-9][a-z0-9-]*$')
27+
- gateway_overrides_content is defined
28+
- gateway_overrides_content | trim | length > 0
29+
fail_msg: >-
30+
gateway_overrides needs gateway_overrides_name (lowercase letters,
31+
digits and dashes) and non-empty gateway_overrides_content
32+
33+
- name: Create the test configuration directory
34+
become: true
35+
ansible.builtin.file:
36+
path: "{{ gateway_overrides_path | dirname }}"
37+
state: directory
38+
owner: root
39+
group: root
40+
mode: "0755"
41+
42+
- name: Write the {{ gateway_overrides_name }} gateway overrides
43+
become: true
44+
ansible.builtin.blockinfile:
45+
path: "{{ gateway_overrides_path }}"
46+
create: true
47+
owner: root
48+
group: root
49+
mode: "0644"
50+
marker: "# {mark} {{ gateway_overrides_name }}"
51+
block: "{{ gateway_overrides_content }}"

‎tests/tmachine/ansible/roles/openshell_external_driver/tasks/main.yaml‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,11 @@
108108
ansible.builtin.fail:
109109
msg: The external driver socket did not appear
110110

111-
- name: Create the environment settings directory
112-
become: true
113-
ansible.builtin.file:
114-
path: /etc/openshell-test
115-
state: directory
116-
mode: "0755"
117-
118111
- name: Point the gateway at the external driver
119-
become: true
120-
ansible.builtin.copy:
121-
dest: /etc/openshell-test/gateway-overrides.toml
122-
mode: "0644"
123-
content: |
112+
ansible.builtin.include_role:
113+
name: gateway_overrides
114+
vars:
115+
gateway_overrides_name: external-driver
116+
gateway_overrides_content: |
124117
[openshell.drivers.{{ openshell_external_driver_name }}]
125118
socket_path = "{{ openshell_external_driver_socket }}"

‎tests/tmachine/ansible/roles/openshell_gateway/files/merge_gateway_toml_test.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,25 @@ def test_creates_from_default_else_minimal(tmp_path):
9898
run, base = merge(other, None, '[openshell.drivers.podman]\nuserns = "auto"\n')
9999
parsed = tomllib.loads(base.read_text())
100100
assert parsed["openshell"]["version"] == 2
101+
102+
103+
def test_applies_every_marked_block(tmp_path):
104+
overrides = (
105+
"# BEGIN podman-userns\n[openshell.drivers.podman]\nuserns = \"auto\"\n# END podman-userns\n"
106+
"# BEGIN config-push\n[openshell.gateway]\nconfig_delivery_mode = \"push\"\n# END config-push\n"
107+
)
108+
run, base = merge(tmp_path, BASE, overrides)
109+
assert run.returncode == 0, run.stderr
110+
parsed = tomllib.loads(base.read_text())
111+
assert parsed["openshell"]["drivers"]["podman"]["userns"] == "auto"
112+
assert parsed["openshell"]["gateway"]["config_delivery_mode"] == "push"
113+
114+
115+
def test_rejects_blocks_that_declare_the_same_table(tmp_path):
116+
overrides = (
117+
"# BEGIN cdi\n[openshell.drivers.podman]\nallow_driver_config = true\n# END cdi\n"
118+
"# BEGIN podman-userns\n[openshell.drivers.podman]\nuserns = \"auto\"\n# END podman-userns\n"
119+
)
120+
run, base = merge(tmp_path, BASE, overrides)
121+
assert run.returncode != 0
122+
assert base.read_text() == BASE

‎tests/tmachine/ansible/roles/openshell_gateway/tasks/merge-settings.yaml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# An environment overrides gateway settings by writing the tables to change,
4+
# An environment overrides gateway settings by adding the tables to change,
55
# such as `[openshell.drivers.podman]`, to
6-
# /etc/openshell-test/gateway-overrides.toml before the installer runs (for
7-
# example playbooks/drivers/podman/userns.yaml). Apply them to
6+
# /etc/openshell-test/gateway-overrides.toml with the gateway_overrides role
7+
# before the installer runs (for example playbooks/drivers/podman/userns.yaml).
8+
# Apply them to
89
# `openshell_gateway_merge_target` without replacing the file; see
910
# files/merge-gateway-toml.py.
1011
#

0 commit comments

Comments
 (0)