Files
resf-testing-repo/ansible/roles/run_test/tasks/main.yml
Stephen Simpson ec04f0bec5 Implement Ansible roles for Rocky Linux Testing Framework
- Added `bootstrap_sparrowdo` role for bootstrapping Sparrowdo on a VM.
- Introduced `cleanup_vm` role for cleaning up VMs and disk images.
- Created `download_image` role to download and cache QCOW2 images.
- Developed `golden_image` role for creating and customizing golden images.
- Implemented `provision_vm` role for provisioning VMs as linked clones.
- Added `run_test` role for executing tests with Sparrowdo.
- Created playbooks for building golden images, running single tests, and running test suites.
- Enhanced documentation with usage examples, configuration details, and troubleshooting tips.
- Added support for multiple cloud providers (AWS, Azure) in the test execution workflow.

Signed-off-by: Stephen Simpson <ssimpson89@users.noreply.github.com>
2025-12-29 16:02:39 -06:00

165 lines
4.2 KiB
YAML

---
# Tasks for run_test role
- name: Validate test parameters
fail:
msg: "{{ item.msg }}"
when: item.condition
loop:
- { condition: "{{ test_name == '' }}", msg: "test_name is required" }
- { condition: "{{ test_repo_url == '' }}", msg: "test_repo_url is required" }
- name: Generate unique VM name
set_fact:
test_vm_name: "{{ test_name }}-{{ ansible_date_time.epoch }}"
- name: Create working directory
file:
path: "{{ work_dir }}/{{ test_vm_name }}"
state: directory
mode: '0755'
- name: Display test info
debug:
msg:
- "Running test: {{ test_name }}"
- "Repository: {{ test_repo_url }}"
- "Branch: {{ test_repo_branch }}"
- "VM: {{ test_vm_name }}"
# Provision VM
- name: Provision test VM
include_role:
name: provision_vm
vars:
vm_name: "{{ test_vm_name }}"
vm_ip_var: "test_vm_ip"
- name: Set VM IP variable
set_fact:
vm_ip: "{{ test_vm_ip }}"
- name: Display VM information
debug:
msg: "VM ready at {{ vm_ip }}"
# Wait for SSH
- name: Wait for SSH to be ready
wait_for:
host: "{{ vm_ip }}"
port: 22
timeout: 60
state: started
delegate_to: localhost
- name: Test SSH connection
command: >
ssh -i {{ ssh_private_key_path }}
-o StrictHostKeyChecking=no
-o ConnectTimeout=5
-o UserKnownHostsFile=/dev/null
{{ ssh_user }}@{{ vm_ip }}
'echo SSH ready'
register: ssh_test
until: ssh_test.rc == 0
retries: 30
delay: 2
changed_when: false
# Clone test repository
- name: Clone test repository
git:
repo: "{{ test_repo_url }}"
dest: "{{ work_dir }}/{{ test_vm_name }}/test-repo"
version: "{{ test_repo_branch }}"
register: repo_cloned
- name: Find sparrowfile
find:
paths: "{{ work_dir }}/{{ test_vm_name }}/test-repo"
patterns:
- "main.raku"
- "sparrowfile"
recurse: true
register: sparrowfile_search
- name: Validate sparrowfile exists
fail:
msg: "No sparrowfile or main.raku found in test repository"
when: sparrowfile_search.files | length == 0
- name: Set sparrowfile path
set_fact:
sparrowfile_path: "{{ sparrowfile_search.files[0].path }}"
- name: Display sparrowfile path
debug:
msg: "Found sparrowfile: {{ sparrowfile_path }}"
# Run Sparrowdo test
- name: Build sparrowdo command
set_fact:
sparrowdo_cmd: >
sparrowdo
--host={{ vm_ip }}
--ssh_user={{ ssh_user }}
--ssh_private_key={{ ssh_private_key_path }}
--ssh_args="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
{% if sparrowdo_no_sudo %}--no_sudo{% endif %}
--sparrowfile={{ sparrowfile_path }}
{% if sparrowdo_verbose %}--verbose{% endif %}
{% if sparrowdo_color %}--color{% endif %}
- name: Create logs directory
file:
path: "{{ logs_dir }}/{{ test_vm_name }}"
state: directory
mode: '0755'
when: save_logs
- name: Run Sparrowdo test
shell: "{{ sparrowdo_cmd }} 2>&1 | tee {{ logs_dir }}/{{ test_vm_name }}/test.log"
args:
executable: /bin/bash
register: sparrowdo_result
timeout: "{{ sparrowdo_timeout }}"
when: save_logs
- name: Run Sparrowdo test (without logging)
command: "{{ sparrowdo_cmd }}"
register: sparrowdo_result_nolog
timeout: "{{ sparrowdo_timeout }}"
when: not save_logs
- name: Display test result
debug:
msg: "Test {{ test_name }} completed successfully"
- name: Cleanup test VM
include_role:
name: cleanup_vm
vars:
vm_name: "{{ test_vm_name }}"
when: cleanup_after_test
- name: Archive test results
set_fact:
test_results: "{{ test_results | default([]) + [{'name': test_name, 'status': 'passed', 'vm': test_vm_name, 'log': logs_dir + '/' + test_vm_name + '/test.log'}] }}"
when: save_logs
# Error handling
- name: Handle test failure
block:
- name: Archive failed test logs
set_fact:
test_results: "{{ test_results | default([]) + [{'name': test_name, 'status': 'failed', 'vm': test_vm_name, 'log': logs_dir + '/' + test_vm_name + '/test.log'}] }}"
when: save_logs
- name: Cleanup VM on failure
include_role:
name: cleanup_vm
vars:
vm_name: "{{ test_vm_name }}"
when: cleanup_after_test
when: sparrowdo_result is failed or sparrowdo_result_nolog is failed