|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +--- |
| 5 | +# Runs the testkit sandbox-lifecycle suite against the gateway the installer |
| 6 | +# registered. testkit finds that gateway the way the CLI does, so no target |
| 7 | +# file is needed. |
| 8 | +- name: Run the sandbox lifecycle suite |
| 9 | + hosts: all |
| 10 | + gather_facts: false |
| 11 | + vars: |
| 12 | + suite_root: /var/lib/openshell-sandbox-lifecycle/tests |
| 13 | + # Fail when the run executes fewer tests than this, so a dropped or |
| 14 | + # filtered-out test cannot pass silently. Raise it when a test is added. |
| 15 | + suite_expected_tests: 1 |
| 16 | + suite_failed: >- |
| 17 | + {{ gateway_status is failed or suite_result.rc != 0 or |
| 18 | + (suite_tests_run | int) < (suite_expected_tests | int) }} |
| 19 | + suite_tests_run: >- |
| 20 | + {{ (suite_result.stderr | default('') | regex_findall('Summary \[[^\]]*\]\s+(\d+) tests? run') | first | default(0)) }} |
| 21 | + tasks: |
| 22 | + - name: Wait for SSH |
| 23 | + ansible.builtin.wait_for_connection: |
| 24 | + |
| 25 | + - name: Create suite directory |
| 26 | + become: true |
| 27 | + ansible.builtin.file: |
| 28 | + path: "{{ suite_root }}" |
| 29 | + state: directory |
| 30 | + owner: tmachine |
| 31 | + group: tmachine |
| 32 | + mode: "0700" |
| 33 | + |
| 34 | + - name: Extract suite bundle |
| 35 | + become: true |
| 36 | + ansible.builtin.unarchive: |
| 37 | + src: "{{ sandbox_lifecycle_test_bundle }}" |
| 38 | + dest: "{{ suite_root }}" |
| 39 | + owner: tmachine |
| 40 | + group: tmachine |
| 41 | + |
| 42 | + - name: Check suite nextest archive |
| 43 | + ansible.builtin.stat: |
| 44 | + path: "{{ suite_root }}/tests.tar.zst" |
| 45 | + register: suite_archive |
| 46 | + |
| 47 | + - name: Require suite nextest archive |
| 48 | + ansible.builtin.assert: |
| 49 | + that: |
| 50 | + - suite_archive.stat.isreg | default(false) |
| 51 | + fail_msg: Sandbox lifecycle test bundle did not contain tests.tar.zst |
| 52 | + |
| 53 | + - name: Resolve installed OpenShell CLI |
| 54 | + ansible.builtin.command: |
| 55 | + argv: |
| 56 | + - /bin/sh |
| 57 | + - -c |
| 58 | + - command -v openshell |
| 59 | + register: openshell_cli |
| 60 | + changed_when: false |
| 61 | + |
| 62 | + # Report a gateway that never came up as one environment failure instead of |
| 63 | + # as every test failing. |
| 64 | + - name: Wait for the registered gateway |
| 65 | + ansible.builtin.command: |
| 66 | + argv: [timeout, 10s, "{{ openshell_cli.stdout }}", status, --output, json] |
| 67 | + register: gateway_status |
| 68 | + changed_when: false |
| 69 | + until: >- |
| 70 | + gateway_status.rc == 0 and |
| 71 | + (gateway_status.stdout | from_json).status == 'connected' |
| 72 | + retries: 60 |
| 73 | + delay: 5 |
| 74 | + ignore_errors: true |
| 75 | + |
| 76 | + # The bundle carries no nextest config, so set the timeouts here. A hung |
| 77 | + # test is killed after two minutes instead of holding the lane until the job |
| 78 | + # times out. |
| 79 | + - name: Write nextest config |
| 80 | + ansible.builtin.copy: |
| 81 | + dest: "{{ suite_root }}/nextest.toml" |
| 82 | + mode: "0600" |
| 83 | + content: | |
| 84 | + [profile.default] |
| 85 | + slow-timeout = { period = "30s", terminate-after = 4 } |
| 86 | + become: true |
| 87 | + become_user: tmachine |
| 88 | + |
| 89 | + - name: Run the suite |
| 90 | + ansible.builtin.command: |
| 91 | + argv: |
| 92 | + - cargo-nextest |
| 93 | + - nextest |
| 94 | + - run |
| 95 | + - --config-file |
| 96 | + - "{{ suite_root }}/nextest.toml" |
| 97 | + - --archive-file |
| 98 | + - "{{ suite_root }}/tests.tar.zst" |
| 99 | + - --workspace-remap |
| 100 | + - "{{ suite_root }}" |
| 101 | + - --no-capture |
| 102 | + # Tests share one gateway and the guest has 4 GiB; run them serially |
| 103 | + # whatever --no-capture implies. |
| 104 | + - --test-threads |
| 105 | + - "1" |
| 106 | + - --no-fail-fast |
| 107 | + environment: |
| 108 | + HOME: /home/tmachine |
| 109 | + OPENSHELL_BIN: "{{ openshell_cli.stdout }}" |
| 110 | + register: suite_result |
| 111 | + changed_when: false |
| 112 | + failed_when: false |
| 113 | + when: gateway_status is succeeded |
| 114 | + |
| 115 | + - name: Show suite diagnostics |
| 116 | + ansible.builtin.debug: |
| 117 | + var: suite_result |
| 118 | + when: suite_failed | bool |
| 119 | + |
| 120 | + - name: Collect OpenShell gateway diagnostics |
| 121 | + ansible.builtin.include_role: |
| 122 | + name: openshell_diagnostics |
| 123 | + when: suite_failed | bool |
| 124 | + |
| 125 | + - name: Require a connected gateway |
| 126 | + ansible.builtin.assert: |
| 127 | + that: |
| 128 | + - gateway_status is succeeded |
| 129 | + fail_msg: OpenShell gateway did not connect before the suite; see gateway diagnostics |
| 130 | + |
| 131 | + - name: Require suite success |
| 132 | + ansible.builtin.assert: |
| 133 | + that: |
| 134 | + - suite_result.rc == 0 |
| 135 | + fail_msg: Sandbox lifecycle suite failed |
| 136 | + |
| 137 | + - name: Require the expected number of tests |
| 138 | + ansible.builtin.assert: |
| 139 | + that: |
| 140 | + - (suite_tests_run | int) >= (suite_expected_tests | int) |
| 141 | + fail_msg: >- |
| 142 | + Sandbox lifecycle suite ran {{ suite_tests_run }} tests; expected at |
| 143 | + least {{ suite_expected_tests }} |
0 commit comments