Skip to content

Commit ad0cee4

Browse files
committed
test(tmachine): publish the installed gateway context to feature tests
Have the openshell client role publish the installed gateway's name, active TOML path, service scope, service user, and network, and add an openshell_test_gateway role that loads that context, resolves the CLI, restarts the gateway service, and collects its journal. A feature suite can then change the gateway's active configuration for its own run and restore it afterwards. Select the candidate runtime images for packaged installs through a qualification gateway.toml referenced by OPENSHELL_GATEWAY_CONFIG instead of OPENSHELL_* variables in the service environment file, so the gateway has a TOML file a suite can modify. Update the packaging asset check to match. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent d1b09a6 commit ad0cee4

8 files changed

Lines changed: 172 additions & 15 deletions

File tree

‎tasks/scripts/test-packaging-assets.sh‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,10 @@ assert_contains "$spec" '%files prover'
9191
assert_contains "$spec" '%{_bindir}/%{name}-prover'
9292
assert_not_contains "$spec" '%%S/openshell/tls'
9393

94-
# Installed-package qualification must select the candidate trusted runtime
95-
# images through the same environment file consumed by preflight and startup,
96-
# without generating operator-owned gateway TOML.
94+
# Qualification retains the package-owned service's environment file. The
95+
# selected configuration and runtime images are exercised by tmachine's
96+
# installed-package integration lanes.
9797
assert_contains "$package_qualification" 'dest: "{{ openshell_gateway_home }}/.config/openshell/gateway.env"'
98-
assert_contains "$package_qualification" 'OPENSHELL_COMPUTE_DRIVER={{ openshell_gateway_driver }}'
99-
assert_contains "$package_qualification" 'OPENSHELL_SANDBOX_RUNTIME_IMAGE=docker.io/openshell/sandbox:tmachine'
100-
assert_contains "$package_qualification" 'OPENSHELL_SUPERVISOR_IMAGE=docker.io/openshell/supervisor:tmachine'
101-
assert_not_contains "$package_qualification" 'OPENSHELL_GATEWAY_CONFIG='
102-
assert_not_contains "$package_qualification" '/var/lib/openshell-qualification/gateway.toml'
10398

10499
# Direct tmachine gateway services select trusted runtime images through the
105100
# process environment. Driver TOML remains available for settings that do not

‎tests/ansible/roles/openshell_client/tasks/main.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,17 @@
1212
- --local
1313
- --name
1414
- "{{ openshell_client_gateway_name | default('tmachine') }}"
15+
16+
- name: Publish test gateway context
17+
ansible.builtin.include_role:
18+
name: openshell_test_gateway
19+
tasks_from: publish.yaml
20+
vars:
21+
openshell_test_gateway_context:
22+
name: "{{ openshell_client_gateway_name | default('tmachine') }}"
23+
config_path: "{{ openshell_client_gateway_config_path | default('/etc/openshell/gateway.toml') }}"
24+
service_scope: "{{ openshell_client_gateway_service_scope | default('system') }}"
25+
service_user: "{{ openshell_gateway_user if openshell_client_gateway_service_scope | default('system') == 'user' else 'root' }}"
26+
service_home: "{{ openshell_gateway_home if openshell_client_gateway_service_scope | default('system') == 'user' else '/root' }}"
27+
service_uid: "{{ openshell_gateway_uid if openshell_client_gateway_service_scope | default('system') == 'user' else '0' }}"
28+
network_name: "{{ openshell_client_gateway_network_name | default('tmachine') }}"

‎tests/ansible/roles/openshell_packaged_gateway/tasks/main.yaml‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
name: openshell_gateway
2222
tasks_from: "{{ openshell_gateway_driver }}.yaml"
2323

24+
# Package defaults select published images. Keep candidate image overrides
25+
# separate from the operator-owned gateway.toml in both installers.
26+
- name: Create qualification configuration directory
27+
become: true
28+
ansible.builtin.file:
29+
path: /var/lib/openshell-qualification
30+
state: directory
31+
owner: root
32+
group: root
33+
mode: "0755"
34+
35+
- name: Configure candidate runtime images for qualification
36+
become: true
37+
ansible.builtin.template:
38+
src: gateway.toml.j2
39+
dest: /var/lib/openshell-qualification/gateway.toml
40+
owner: root
41+
group: root
42+
mode: "0644"
43+
2444
- name: Create packaged gateway environment directory
2545
become: true
2646
ansible.builtin.file:
@@ -30,20 +50,15 @@
3050
group: "{{ openshell_gateway_user }}"
3151
mode: "0700"
3252

33-
# Exercise the package-owned service's environment-file mechanism without
34-
# generating operator-owned gateway TOML. Preflight and startup must resolve
35-
# the same candidate runtime images.
36-
- name: Configure candidate runtime images for qualification
53+
- name: Select qualification gateway configuration
3754
become: true
3855
ansible.builtin.copy:
3956
dest: "{{ openshell_gateway_home }}/.config/openshell/gateway.env"
4057
owner: "{{ openshell_gateway_user }}"
4158
group: "{{ openshell_gateway_user }}"
4259
mode: "0600"
4360
content: |
44-
OPENSHELL_COMPUTE_DRIVER={{ openshell_gateway_driver }}
45-
OPENSHELL_SANDBOX_RUNTIME_IMAGE=docker.io/openshell/sandbox:tmachine
46-
OPENSHELL_SUPERVISOR_IMAGE=docker.io/openshell/supervisor:tmachine
61+
OPENSHELL_GATEWAY_CONFIG=/var/lib/openshell-qualification/gateway.toml
4762
4863
- name: Start gateway user manager
4964
ansible.builtin.include_role:
@@ -106,3 +121,6 @@
106121
vars:
107122
openshell_client_gateway_endpoint: https://127.0.0.1:17670
108123
openshell_client_gateway_name: openshell
124+
openshell_client_gateway_config_path: /var/lib/openshell-qualification/gateway.toml
125+
openshell_client_gateway_service_scope: user
126+
openshell_client_gateway_network_name: openshell
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. #}
2+
{# SPDX-License-Identifier: Apache-2.0 #}
3+
[openshell]
4+
version = 2
5+
6+
[openshell.drivers.{{ openshell_gateway_driver }}]
7+
sandbox_runtime_image = "docker.io/openshell/sandbox:tmachine"
8+
supervisor_image = "docker.io/openshell/supervisor:tmachine"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
# Root's packaged user unit can log to the system journal. Match journal
6+
# fields instead of --user so both root and tmachine user units are captured.
7+
- name: Capture installed gateway journal
8+
become: true
9+
ansible.builtin.command:
10+
argv: >-
11+
{{ ['journalctl']
12+
+ (['_SYSTEMD_USER_UNIT=openshell-gateway.service', '_UID=' ~ openshell_test_gateway.service_uid]
13+
if openshell_test_gateway.service_scope == 'user'
14+
else ['--unit', 'openshell-gateway.service'])
15+
+ ['--no-pager', '--lines', '200'] }}
16+
register: openshell_test_gateway_journal
17+
changed_when: false
18+
failed_when: false
19+
20+
- name: Show installed gateway journal
21+
ansible.builtin.debug:
22+
var: openshell_test_gateway_journal.stdout_lines
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
- name: Read installed gateway context
6+
ansible.builtin.slurp:
7+
src: /var/lib/openshell-test/gateway.yaml
8+
register: openshell_test_gateway_metadata
9+
10+
- name: Load installed gateway context
11+
ansible.builtin.set_fact:
12+
openshell_test_gateway: "{{ (openshell_test_gateway_metadata.content | b64decode | from_yaml).openshell_test_gateway }}"
13+
14+
- name: Validate installed gateway context
15+
ansible.builtin.assert:
16+
that:
17+
- openshell_test_gateway.service_scope in ['system', 'user']
18+
- openshell_test_gateway.config_path is match('^/')
19+
- openshell_test_gateway.name | length > 0
20+
21+
- name: Resolve installed OpenShell CLI from PATH
22+
ansible.builtin.command:
23+
argv: [/bin/sh, -c, command -v openshell]
24+
register: openshell_test_cli
25+
changed_when: false
26+
27+
- name: Check active gateway configuration
28+
become: true
29+
ansible.builtin.stat:
30+
path: "{{ openshell_test_gateway.config_path }}"
31+
register: openshell_test_gateway_config
32+
33+
- name: Require active gateway configuration
34+
ansible.builtin.assert:
35+
that: [openshell_test_gateway_config.stat.isreg | default(false)]
36+
37+
- name: Resolve gateway service environment
38+
ansible.builtin.set_fact:
39+
openshell_test_gateway_service_environment:
40+
HOME: "{{ openshell_test_gateway.service_home }}"
41+
XDG_RUNTIME_DIR: "/run/user/{{ openshell_test_gateway.service_uid }}"
42+
DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ openshell_test_gateway.service_uid }}/bus"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
# Installation and suite execution are separate Ansible processes. Persist only
6+
# non-secret metadata; the CLI keeps registration and mTLS credentials itself.
7+
- name: Create test gateway metadata directory
8+
become: true
9+
ansible.builtin.file:
10+
path: /var/lib/openshell-test
11+
state: directory
12+
owner: root
13+
group: root
14+
mode: "0755"
15+
16+
- name: Publish installed gateway context
17+
become: true
18+
ansible.builtin.copy:
19+
dest: /var/lib/openshell-test/gateway.yaml
20+
owner: root
21+
group: root
22+
mode: "0644"
23+
content: "{{ {'openshell_test_gateway': openshell_test_gateway_context} | to_nice_yaml }}"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
- name: Restart installed gateway
6+
block:
7+
- name: Restart gateway service with the active configuration
8+
become: true
9+
become_user: "{{ openshell_test_gateway.service_user }}"
10+
ansible.builtin.systemd_service:
11+
name: openshell-gateway.service
12+
scope: "{{ openshell_test_gateway.service_scope }}"
13+
state: restarted
14+
environment: "{{ openshell_test_gateway_service_environment }}"
15+
16+
- name: Wait for authenticated gateway readiness
17+
ansible.builtin.command:
18+
argv: ["{{ openshell_test_cli.stdout }}", gateway, info, --output, json]
19+
environment:
20+
OPENSHELL_GATEWAY: "{{ openshell_test_gateway.name }}"
21+
changed_when: false
22+
register: openshell_test_gateway_ready
23+
retries: 30
24+
delay: 2
25+
until: >-
26+
openshell_test_gateway_ready.rc == 0 and
27+
(openshell_test_gateway_ready.stdout | from_json).status == 'healthy'
28+
29+
rescue:
30+
- name: Collect gateway restart diagnostics
31+
ansible.builtin.include_tasks: journal.yaml
32+
33+
- name: Report gateway restart failure
34+
ansible.builtin.fail:
35+
msg: Installed gateway failed to restart with the driver fixture

0 commit comments

Comments
 (0)