Skip to content

Commit 52ebb62

Browse files
committed
test(tmachine): apply gateway overrides as a drop-in config
Install an environment's gateway overrides as `gateway.d/90-test-overrides.toml` next to the gateway's own config instead of merging them into it with a script. A package with no default config runs on the drop-in config alone. The override files declare `[openshell] version = 2`. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 696fa36 commit 52ebb62

7 files changed

Lines changed: 92 additions & 341 deletions

File tree

‎TESTING.md‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -659,27 +659,25 @@ which takes a name and the tables to change, such as `[openshell.gateway]` or
659659
The role writes each name as its own marked block in
660660
`/etc/openshell-test/gateway-overrides.toml`, so writers keep each other's
661661
settings, and `gateway_overrides_state: absent` removes a name's block.
662-
Two blocks must not declare the same table. Don't write the file
663-
directly. The file is not a complete configuration. Each installer applies it
664-
to the gateway's own file:
665-
666-
- `binaries` applies it to the `/etc/openshell/gateway.toml` it generates.
667-
- `deb` and `rpm` apply it to the service user's
662+
The role also writes the `[openshell] version = 2` header the gateway requires,
663+
so callers leave it out. Two blocks must not declare the same table. Don't write
664+
the file directly. Each installer installs it as the drop-in config
665+
`gateway.d/90-test-overrides.toml` next to the gateway's own `gateway.toml`, and
666+
the gateway merges it over that file. The base file is never edited:
667+
668+
- `binaries` installs it beside the `/etc/openshell/gateway.toml` it generates.
669+
- `deb` and `rpm` install it beside the service user's
668670
`~/.config/openshell/gateway.toml`, the file the packaged service reads. The
669-
file starts as a copy of the rpm's
670-
`/usr/share/openshell-gateway/gateway.toml.default`, where the service would
671-
seed it on first start, or as a minimal `version = 2` file when the package
672-
has no default. No environment replaces the packaged file, and an environment
673-
with no overrides leaves it untouched.
671+
rpm still seeds that file from
672+
`/usr/share/openshell-gateway/gateway.toml.default` on first start. A package
673+
with no default runs on the drop-in config alone. An environment with no
674+
overrides leaves the packaged configuration untouched.
674675
- `k3s` installers ignore the file.
675676

676-
`tests/tmachine/ansible/roles/openshell_gateway/files/merge-gateway-toml.py`
677-
does the work. Each key in the overrides replaces the same key in the table, or
678-
is added to it, and a table the file lacks is appended. The rest of the file,
679-
comments included, stays. The script parses the result and fails the setup,
680-
leaving the file unchanged, when it isn't valid TOML. It can't remove a key.
681-
Settings that the packaged service reads from `gateway.env` instead of the
682-
TOML are not covered.
677+
A key in the drop-in config replaces the same key in the base file's table, or is
678+
added to it, and a table the base lacks is added. Arrays replace the base
679+
array. A drop-in config can't remove a key. Settings that the packaged service reads
680+
from `gateway.env` instead of the TOML are not covered.
683681

684682
The `oci-image` feature suite (`tests/suites/features/oci-image`) checks OCI
685683
image identity and working-directory behavior shared by the Docker and Podman

‎tasks/test.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ depends = [
2525
"test:maintainer-approval",
2626
"test:cargo-lockfile-alignment",
2727
"test:review-readiness",
28-
"test:merge-gateway-toml",
2928
"test:accepted-work",
3029
"test:label-issue",
3130
]
@@ -42,10 +41,6 @@ run = [
4241
]
4342
hide = true
4443

45-
["test:merge-gateway-toml"]
46-
description = "Test the tmachine gateway TOML merge script"
47-
run = "uv run --no-project --with pytest pytest tests/tmachine/ansible/roles/openshell_gateway/files/merge_gateway_toml_test.py"
48-
4944
["test:cargo-lockfile-alignment"]
5045
description = "Test the Cargo lockfile alignment check"
5146
run = "uv run --no-project --with pytest pytest tasks/scripts/check_cargo_lockfile_alignment_test.py"

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# 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).
5+
# the `binaries`, `deb` and `rpm` installers install as a `gateway.d` drop-in
6+
# config next to the gateway's configuration
7+
# (openshell_gateway/tasks/merge-settings.yaml; k3s installers ignore it).
88
#
99
# Inputs:
1010
# gateway_overrides_name names the marked block, such as `cdi`; writing
@@ -16,10 +16,11 @@
1616
#
1717
# Each name gets its own marked block, so writers keep each other's settings
1818
# and may run in any order. Two blocks must not declare the same table: TOML
19-
# rejects a table defined twice, and the installer fails on it.
19+
# rejects a table defined twice, and the gateway fails on it.
2020
#
21-
# TODO: https://github.com/NVIDIA/OpenShell/pull/5489 reads gateway.d drop-in
22-
# files. When it lands, write each name to its own drop-in here instead.
21+
# A drop-in config must declare the schema version, so the role keeps a
22+
# `version` block with `[openshell] version = 2` in the file. Callers leave it
23+
# out.
2324
---
2425
- name: Require a gateway override name and content
2526
ansible.builtin.assert:
@@ -47,6 +48,20 @@
4748
group: root
4849
mode: "0755"
4950

51+
- name: Declare the gateway schema version for the overrides
52+
become: true
53+
ansible.builtin.blockinfile:
54+
path: "{{ gateway_overrides_path }}"
55+
create: true
56+
owner: root
57+
group: root
58+
mode: "0644"
59+
marker: "# {mark} version"
60+
block: |
61+
[openshell]
62+
version = 2
63+
when: gateway_overrides_state == 'present'
64+
5065
- name: Write the {{ gateway_overrides_name }} gateway overrides
5166
become: true
5267
ansible.builtin.blockinfile:

‎tests/tmachine/ansible/roles/openshell_gateway/files/merge-gateway-toml.py‎

Lines changed: 0 additions & 165 deletions
This file was deleted.

0 commit comments

Comments
 (0)