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:
Stephen Simpson
2025-12-29 16:02:39 -06:00
parent bb829c9b63
commit ec04f0bec5
46 changed files with 2005 additions and 2055 deletions

View File

@@ -0,0 +1,19 @@
# AWS Playbooks
This directory will contain AWS-specific playbooks for the Rocky Linux Testing Framework.
## Future Playbooks
- `setup.yml` - Configure AWS resources (VPC, security groups, etc.)
- `create-ami.yml` - Build custom Rocky Linux AMIs
- `cleanup.yml` - Clean up AWS resources
## Workflow
AWS testing doesn't require golden image creation. Instead:
1. Select Rocky Linux AMI
2. Launch EC2 instance
3. Run Sparrowdo tests
4. Terminate instance
All tests use the main `playbooks/run-tests.yml` playbook, which automatically handles AWS-specific infrastructure provisioning.

View File

@@ -0,0 +1,19 @@
# Azure Playbooks
This directory will contain Azure-specific playbooks for the Rocky Linux Testing Framework.
## Future Playbooks
- `setup.yml` - Configure Azure resources (resource groups, networks, etc.)
- `create-image.yml` - Build custom Rocky Linux VM images
- `cleanup.yml` - Clean up Azure resources
## Workflow
Azure testing doesn't require golden image creation. Instead:
1. Select Rocky Linux VM image
2. Create Azure VM
3. Run Sparrowdo tests
4. Delete VM
All tests use the main `playbooks/run-tests.yml` playbook, which automatically handles Azure-specific infrastructure provisioning.

View File

@@ -0,0 +1,78 @@
---
# Build a golden image: Download -> Customize -> Bootstrap Sparrowdo
- name: Build Golden Image
hosts: libvirt
gather_facts: true
vars_prompt:
- name: qcow2_url
prompt: "Rocky Linux QCOW2 URL (Enter for Rocky 9 default)"
default: "https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2"
private: false
pre_tasks:
- name: Verify sparrowdo is installed
stat:
path: ~/.raku/bin/sparrowdo
register: sparrowdo_check
failed_when: not sparrowdo_check.stat.exists
- name: Set build paths
set_fact:
build_id: "{{ lookup('pipe', 'date +%s') }}"
- name: Set golden image path
set_fact:
timestamped_golden_path: "{{ golden_images_dir }}/rocky-golden-{{ build_id }}.qcow2"
- name: Ensure directories exist
file:
path: "{{ item }}"
state: directory
mode: '0755'
become: true
loop:
- "{{ golden_images_dir }}"
- /tmp/rocky-test-keys
- name: Generate SSH keys if needed
command: ssh-keygen -t rsa -b 4096 -f /tmp/rocky-test-keys/id_rsa -N "" -C "rocky-test"
args:
creates: /tmp/rocky-test-keys/id_rsa
- name: Set SSH key paths
set_fact:
ssh_private_key_path: /tmp/rocky-test-keys/id_rsa
ssh_public_key_path: /tmp/rocky-test-keys/id_rsa.pub
tasks:
- name: Download base image
include_role:
name: download_image
vars:
image_path_var: "base_image_path"
- name: Create golden image
include_role:
name: golden_image
vars:
golden_image_path: "{{ timestamped_golden_path }}"
- name: Bootstrap Sparrowdo
include_role:
name: bootstrap_sparrowdo
vars:
golden_image_path: "{{ timestamped_golden_path }}"
- name: Create symlink to latest golden image
file:
src: "{{ timestamped_golden_path }}"
dest: "{{ golden_image_path }}"
state: link
force: yes
become: true
- name: Done
debug:
msg: "Golden image ready: {{ golden_image_path }}"

View 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