Skip to content

Commit 5d1a8e8

Browse files
committed
test(tmachine): add CDI scenario fixtures to the Docker environment
Define each CDI scenario once in vars/scenarios.yaml: the host fixtures it needs (directories, files, a character device, a socket), the CDI edits that reference them, and the behavior the workload is expected to observe. The cdi_fixtures role creates the fixtures, renders one tmachine.example/cdi-scenario spec with a device per scenario, and publishes the expectations as scenarios.json. Install the spec into /var/run/cdi from systemd-tmpfiles on every boot so it survives tmachine's setup, installation, and test disk layers, and run the role as part of the ubuntu-docker-rootful setup. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent ad0cee4 commit 5d1a8e8

10 files changed

Lines changed: 448 additions & 0 deletions

File tree

‎tests/ansible/playbooks/cdi.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
- name: Prepare hardware-free CDI fixtures in the Docker environment
6+
hosts: all
7+
gather_facts: false
8+
pre_tasks:
9+
- name: Wait for SSH
10+
ansible.builtin.wait_for_connection:
11+
roles:
12+
- cdi_fixtures
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
cdi_fixture_root: /var/lib/openshell-test-inputs/cdi
6+
7+
# Specs the role installs into /var/run/cdi on every boot. The CDI feature
8+
# playbook checks the same list, so a new spec is added here only.
9+
cdi_fixture_spec_files:
10+
- openshell-tmachine-scenarios.yaml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
[Unit]
4+
Description=OpenShell tmachine CDI Unix socket fixture
5+
6+
[Socket]
7+
ListenStream=/var/lib/openshell-test-inputs/cdi/scenarios/socket/echo.sock
8+
SocketMode=0666
9+
Accept=yes
10+
RemoveOnStop=yes
11+
12+
[Install]
13+
WantedBy=sockets.target
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
[Unit]
4+
Description=OpenShell tmachine CDI echo connection
5+
6+
[Service]
7+
ExecStart=/bin/cat
8+
StandardInput=socket
9+
StandardOutput=socket
10+
DynamicUser=yes
11+
NoNewPrivileges=yes
12+
PrivateTmp=yes
13+
ProtectSystem=strict
14+
ProtectHome=yes
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
# Persistent sources are copied into /var/run/cdi by systemd-tmpfiles on every
6+
# boot, including the setup, installation, and test disk layers.
7+
- name: Check fixture paths before creating CDI specs
8+
become: true
9+
ansible.builtin.stat:
10+
path: "{{ item }}"
11+
follow: false
12+
loop: "{{ cdi_fixture_spec_files | map('regex_replace', '^', '/var/run/cdi/') }}"
13+
register: cdi_fixture_paths
14+
15+
- name: Require a guest without existing fixture paths
16+
ansible.builtin.assert:
17+
that: [not item.stat.exists]
18+
fail_msg: "Refusing to replace existing CDI fixture path {{ item.item }}"
19+
loop: "{{ cdi_fixture_paths.results }}"
20+
21+
- name: Create CDI spec directories
22+
become: true
23+
ansible.builtin.file:
24+
path: "{{ item }}"
25+
state: directory
26+
owner: root
27+
group: root
28+
mode: "0755"
29+
loop:
30+
- "{{ cdi_fixture_root }}"
31+
- "{{ cdi_fixture_root }}/specs"
32+
33+
- name: Prepare named CDI scenarios
34+
ansible.builtin.include_tasks: scenarios.yaml
35+
36+
- name: Recreate volatile CDI specs on every VM boot
37+
become: true
38+
ansible.builtin.template:
39+
src: tmpfiles.conf.j2
40+
dest: /etc/tmpfiles.d/openshell-tmachine-cdi.conf
41+
owner: root
42+
group: root
43+
mode: "0644"
44+
45+
- name: Populate CDI specs for the current boot
46+
become: true
47+
ansible.builtin.command:
48+
argv: [systemd-tmpfiles, --create, /etc/tmpfiles.d/openshell-tmachine-cdi.conf]
49+
changed_when: true
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
- name: Allocate a supplementary group for the CDI device fixture
6+
become: true
7+
ansible.builtin.group:
8+
name: openshell-cdi-fixture
9+
system: true
10+
register: cdi_fixture_group
11+
12+
- name: Load named CDI scenarios
13+
ansible.builtin.include_vars:
14+
file: scenarios.yaml
15+
16+
- name: Collect scenario fixtures
17+
ansible.builtin.set_fact:
18+
cdi_scenario_fixtures: >-
19+
{{ cdi_scenario_common_fixtures
20+
+ (cdi_scenarios | map(attribute='fixtures', default=[]) | flatten) }}
21+
22+
- name: Create the scenario fixture root
23+
become: true
24+
ansible.builtin.file:
25+
path: "{{ cdi_scenario_dir }}"
26+
state: directory
27+
owner: root
28+
group: root
29+
mode: "0755"
30+
31+
- name: Create scenario fixture directories
32+
become: true
33+
ansible.builtin.file:
34+
path: "{{ cdi_scenario_dir }}/{{ item.path }}"
35+
state: directory
36+
owner: "{{ item.owner | default('root') }}"
37+
group: "{{ item.group | default('root') }}"
38+
mode: "{{ item.mode }}"
39+
loop: "{{ cdi_scenario_fixtures | selectattr('type', 'eq', 'dir') | list }}"
40+
loop_control:
41+
label: "{{ item.path }}"
42+
43+
- name: Write scenario fixture files
44+
become: true
45+
ansible.builtin.copy:
46+
dest: "{{ cdi_scenario_dir }}/{{ item.path }}"
47+
content: "{{ item.content }}"
48+
owner: "{{ item.owner | default('root') }}"
49+
group: "{{ item.group | default('root') }}"
50+
mode: "{{ item.mode }}"
51+
loop: "{{ cdi_scenario_fixtures | selectattr('type', 'eq', 'file') | list }}"
52+
loop_control:
53+
label: "{{ item.path }}"
54+
55+
- name: Create scenario fixture named pipes
56+
become: true
57+
ansible.builtin.command:
58+
argv: [mkfifo, "--mode={{ item.mode }}", "{{ cdi_scenario_dir }}/{{ item.path }}"]
59+
creates: "{{ cdi_scenario_dir }}/{{ item.path }}"
60+
loop: "{{ cdi_scenario_fixtures | selectattr('type', 'eq', 'fifo') | list }}"
61+
loop_control:
62+
label: "{{ item.path }}"
63+
64+
- name: Create scenario fixture character devices
65+
become: true
66+
ansible.builtin.command:
67+
argv: [mknod, "{{ cdi_scenario_dir }}/{{ item.path }}", c, "{{ item.major }}", "{{ item.minor }}"]
68+
creates: "{{ cdi_scenario_dir }}/{{ item.path }}"
69+
loop: "{{ cdi_scenario_fixtures | selectattr('type', 'eq', 'chardev') | list }}"
70+
loop_control:
71+
label: "{{ item.path }}"
72+
73+
- name: Set scenario fixture device ownership
74+
become: true
75+
ansible.builtin.file:
76+
path: "{{ cdi_scenario_dir }}/{{ item.path }}"
77+
owner: "{{ item.owner | default('root') }}"
78+
group: "{{ item.group | default('root') }}"
79+
mode: "{{ item.mode }}"
80+
loop: "{{ cdi_scenario_fixtures | selectattr('type', 'in', ['chardev', 'fifo']) | list }}"
81+
loop_control:
82+
label: "{{ item.path }}"
83+
84+
- name: Install socket fixture units
85+
become: true
86+
ansible.builtin.copy:
87+
src: "{{ item }}"
88+
dest: "/etc/systemd/system/{{ item }}"
89+
owner: root
90+
group: root
91+
mode: "0644"
92+
loop: [openshell-cdi-echo.socket, 'openshell-cdi-echo@.service']
93+
94+
- name: Start the persistent socket fixture
95+
become: true
96+
ansible.builtin.systemd_service:
97+
name: openshell-cdi-echo.socket
98+
daemon_reload: true
99+
enabled: true
100+
state: started
101+
102+
- name: Generate named CDI scenario devices
103+
become: true
104+
ansible.builtin.template:
105+
src: scenarios.yaml.j2
106+
dest: "{{ cdi_fixture_root }}/specs/openshell-tmachine-scenarios.yaml"
107+
owner: root
108+
group: root
109+
mode: "0644"
110+
111+
- name: Publish scenario expectations for the CDI feature tests
112+
become: true
113+
ansible.builtin.copy:
114+
dest: "{{ cdi_fixture_root }}/scenarios.json"
115+
content: >-
116+
{{ {'common_checks': cdi_scenario_common_checks,
117+
'scenarios': cdi_scenarios | items2dict(key_name='name', value_name='expect')}
118+
| to_nice_json }}
119+
owner: root
120+
group: root
121+
mode: "0644"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
# Generated from vars/scenarios.yaml. Scenarios are selected individually, so
4+
# negative scenarios never combine with positive ones.
5+
cdiVersion: "0.8.0"
6+
kind: tmachine.example/cdi-scenario
7+
containerEdits:
8+
{{ cdi_scenario_spec_edits | to_nice_yaml(indent=2) | indent(2, true) }}
9+
devices:
10+
{% for case in cdi_scenarios %}
11+
- name: {{ case.name }}
12+
containerEdits:
13+
{{ case.edits | to_nice_yaml(indent=2) | indent(6, true) }}
14+
{% endfor %}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Hardware-free CDI fixtures for the disposable Docker test environment.
2+
d /run/cdi 0755 root root -
3+
{% for spec in cdi_fixture_spec_files %}
4+
C /run/cdi/{{ spec }} 0644 root root - {{ cdi_fixture_root }}/specs/{{ spec }}
5+
{% endfor %}

0 commit comments

Comments
 (0)