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>
This commit is contained in:
123
ansible/playbooks/run-tests.yml
Normal file
123
ansible/playbooks/run-tests.yml
Normal file
@@ -0,0 +1,123 @@
|
||||
---
|
||||
# Provider-aware test suite runner
|
||||
# Loads tests from vars/test-definitions.yml
|
||||
# Handles infrastructure provisioning/cleanup based on provider type
|
||||
|
||||
- name: Run Test Suite
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
|
||||
vars_files:
|
||||
- ../vars/test-definitions.yml
|
||||
|
||||
vars:
|
||||
# Test filtering (override with -e "test_filter=ssh")
|
||||
test_filter: "{{ default_test_filter }}"
|
||||
|
||||
# Results tracking
|
||||
test_results: []
|
||||
passed_tests: []
|
||||
failed_tests: []
|
||||
|
||||
pre_tasks:
|
||||
- name: Filter tests based on test_filter
|
||||
set_fact:
|
||||
filtered_tests: "{{ tests | selectattr('name', 'match', test_filter) | list }}"
|
||||
|
||||
- name: Validate test list
|
||||
fail:
|
||||
msg: "No tests match filter: {{ test_filter }}"
|
||||
when: filtered_tests | length == 0
|
||||
|
||||
- name: Display test suite information
|
||||
debug:
|
||||
msg:
|
||||
- "=========================================="
|
||||
- "Running Test Suite"
|
||||
- "=========================================="
|
||||
- "Provider: {{ provider }}"
|
||||
- "Total tests: {{ filtered_tests | length }}"
|
||||
- "Test filter: {{ test_filter }}"
|
||||
- "=========================================="
|
||||
|
||||
- name: Display tests to run
|
||||
debug:
|
||||
msg: " {{ loop_index + 1 }}. {{ item.name }}"
|
||||
loop: "{{ filtered_tests }}"
|
||||
loop_control:
|
||||
index_var: loop_index
|
||||
|
||||
tasks:
|
||||
# Provider-aware test execution loop
|
||||
- name: Execute test suite
|
||||
block:
|
||||
- name: Run each test with provider-specific infrastructure
|
||||
include_tasks: ../tasks/run-test-with-infrastructure.yml
|
||||
loop: "{{ filtered_tests }}"
|
||||
loop_control:
|
||||
loop_var: test_item
|
||||
label: "{{ test_item.name }}"
|
||||
rescue:
|
||||
- name: Handle catastrophic failure
|
||||
debug:
|
||||
msg: "Test suite encountered a critical error"
|
||||
|
||||
post_tasks:
|
||||
- name: Collect test results
|
||||
set_fact:
|
||||
passed_tests: "{{ test_results | selectattr('status', 'equalto', 'passed') | list }}"
|
||||
failed_tests: "{{ test_results | selectattr('status', 'equalto', 'failed') | list }}"
|
||||
|
||||
- name: Display test results summary
|
||||
debug:
|
||||
msg:
|
||||
- "=========================================="
|
||||
- "Test Suite Results"
|
||||
- "=========================================="
|
||||
- "Provider: {{ provider }}"
|
||||
- "Total Tests: {{ test_results | length }}"
|
||||
- "Passed: {{ passed_tests | length }}"
|
||||
- "Failed: {{ failed_tests | length }}"
|
||||
- "=========================================="
|
||||
|
||||
- name: Display passed tests
|
||||
debug:
|
||||
msg: " ✓ {{ item.name }}"
|
||||
loop: "{{ passed_tests }}"
|
||||
when: passed_tests | length > 0
|
||||
|
||||
- name: Display failed tests
|
||||
debug:
|
||||
msg: " ✗ {{ item.name }}: {{ item.error | default('Unknown error') }}"
|
||||
loop: "{{ failed_tests }}"
|
||||
when: failed_tests | length > 0
|
||||
|
||||
- name: Save results to file
|
||||
copy:
|
||||
content: |
|
||||
Test Suite Results - {{ ansible_date_time.iso8601 }}
|
||||
Provider: {{ provider }}
|
||||
|
||||
Summary:
|
||||
- Total: {{ test_results | length }}
|
||||
- Passed: {{ passed_tests | length }}
|
||||
- Failed: {{ failed_tests | length }}
|
||||
|
||||
Passed Tests:
|
||||
{% for test in passed_tests %}
|
||||
- {{ test.name }}
|
||||
{% endfor %}
|
||||
|
||||
Failed Tests:
|
||||
{% for test in failed_tests %}
|
||||
- {{ test.name }}: {{ test.error | default('Unknown error') }}
|
||||
{% endfor %}
|
||||
dest: "{{ logs_dir }}/test-results-{{ ansible_date_time.epoch }}.txt"
|
||||
when: test_results | length > 0
|
||||
|
||||
- name: Fail if any tests failed
|
||||
fail:
|
||||
msg: "{{ failed_tests | length }} test(s) failed"
|
||||
when:
|
||||
- failed_tests | length > 0
|
||||
- not continue_on_failure
|
||||
Reference in New Issue
Block a user