|
| 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" |
0 commit comments