|
| 1 | +--- |
| 2 | +# RDS Compare Test task for Telco-KPIs |
| 3 | +# Purpose: Validate spoke cluster against RAN RDS metadata from telco-reference |
| 4 | +# Output: cluster-compare.log with comparison results |
| 5 | +# Uses: kubectl-cluster_compare in podman container |
| 6 | + |
| 7 | +- name: Ensure test-runner container image exists on bastion |
| 8 | + ansible.builtin.import_tasks: setup-test-runner.yml |
| 9 | + |
| 10 | +- name: Create artifacts directory on bastion |
| 11 | + ansible.builtin.tempfile: |
| 12 | + state: directory |
| 13 | + suffix: .rds-compare-{{ spoke_cluster }} |
| 14 | + path: /tmp |
| 15 | + register: artifacts_dir |
| 16 | + |
| 17 | +- name: Display RDS compare configuration |
| 18 | + ansible.builtin.debug: |
| 19 | + msg: |
| 20 | + - "==========================================" |
| 21 | + - "RDS Comparison Configuration" |
| 22 | + - "==========================================" |
| 23 | + - "Spoke Cluster: {{ spoke_cluster }}" |
| 24 | + - "OCP Version: {{ version }}" |
| 25 | + - "Reference Repo: {{ reference_repo_url }}" |
| 26 | + - "Metadata Path: {{ metadata_relpath }}" |
| 27 | + - "Baseline Mode: {{ baseline | default(false) }}" |
| 28 | + - "Kubeconfig: {{ spoke_kubeconfig }}" |
| 29 | + - "Artifacts: {{ artifacts_dir.path }}" |
| 30 | + - "==========================================" |
| 31 | + |
| 32 | +- name: Determine reference branch |
| 33 | + ansible.builtin.set_fact: |
| 34 | + reference_branch: "{{ reference_branch if reference_branch else 'release-' + version }}" |
| 35 | + |
| 36 | +- name: Set telco-reference clone path |
| 37 | + ansible.builtin.set_fact: |
| 38 | + reference_repo_path: "/tmp/telco-reference-{{ spoke_cluster }}" |
| 39 | + |
| 40 | +- name: Clone or update telco-reference repo on bastion |
| 41 | + ansible.builtin.git: |
| 42 | + repo: "{{ reference_repo_url }}" |
| 43 | + dest: "{{ reference_repo_path }}" |
| 44 | + version: "{{ reference_branch }}" |
| 45 | + update: yes |
| 46 | + force: yes |
| 47 | + register: git_clone |
| 48 | + |
| 49 | +- name: Validate metadata file exists |
| 50 | + ansible.builtin.stat: |
| 51 | + path: "{{ reference_repo_path }}/{{ metadata_relpath }}" |
| 52 | + register: metadata_file |
| 53 | + failed_when: not metadata_file.stat.exists |
| 54 | + |
| 55 | +- name: Display repository details |
| 56 | + ansible.builtin.debug: |
| 57 | + msg: |
| 58 | + - "Repository: {{ reference_repo_path }}" |
| 59 | + - "Branch: {{ reference_branch }}" |
| 60 | + - "Commit: {{ git_clone.after }}" |
| 61 | + - "Metadata: {{ metadata_relpath }}" |
| 62 | + |
| 63 | +- name: Ensure kubeconfig is readable by podman container |
| 64 | + ansible.builtin.file: |
| 65 | + path: "{{ spoke_kubeconfig }}" |
| 66 | + mode: '0644' |
| 67 | + |
| 68 | +- name: Run kubectl-cluster_compare in podman container |
| 69 | + ansible.builtin.shell: | |
| 70 | + podman run --rm \ |
| 71 | + -v {{ spoke_kubeconfig }}:/tmp/kubeconfig-ro:ro,Z \ |
| 72 | + -v {{ reference_repo_path }}:/workspace/reference:ro,Z \ |
| 73 | + -v {{ artifacts_dir.path }}:/workspace/artifacts:rw,Z \ |
| 74 | + -e KUBECONFIG=/tmp/kubeconfig-ro \ |
| 75 | + telco-kpis-test-runner:latest \ |
| 76 | + bash -c " |
| 77 | + set -euo pipefail |
| 78 | + cd /workspace/reference |
| 79 | + echo '[INFO] Running kubectl-cluster_compare' |
| 80 | + echo '[INFO] Metadata: {{ metadata_relpath }}' |
| 81 | + echo '[INFO] Extra args: {{ compare_extra_args | default('(none)') }}' |
| 82 | + set +e |
| 83 | + kubectl-cluster_compare -r '{{ metadata_relpath }}' {{ compare_extra_args | default('') }} 2>&1 | tee /workspace/artifacts/cluster-compare.log |
| 84 | + exit \${PIPESTATUS[0]} |
| 85 | + " |
| 86 | + register: compare_result |
| 87 | + failed_when: false |
| 88 | + changed_when: false |
| 89 | + |
| 90 | +- name: Count comparison results |
| 91 | + ansible.builtin.set_fact: |
| 92 | + compare_exit_code: "{{ compare_result.rc }}" |
| 93 | + compare_success: "{{ compare_result.rc == 0 }}" |
| 94 | + |
| 95 | +- name: Display comparison summary |
| 96 | + ansible.builtin.debug: |
| 97 | + msg: |
| 98 | + - "==========================================" |
| 99 | + - "RDS Comparison Summary" |
| 100 | + - "==========================================" |
| 101 | + - "Exit Code: {{ compare_exit_code }}" |
| 102 | + - "Status: {{ 'PASS (all resources match)' if compare_success else 'FAIL (mismatches found)' }}" |
| 103 | + - "Baseline Mode: {{ 'Yes (non-failing)' if (baseline | default(false)) else 'No' }}" |
| 104 | + - "Log: {{ artifacts_dir.path }}/cluster-compare.log" |
| 105 | + - "==========================================" |
| 106 | + |
| 107 | +- name: Manage test artifacts (collect, share, report) |
| 108 | + ansible.builtin.include_role: |
| 109 | + name: artifact-management |
| 110 | + vars: |
| 111 | + artifact_management_test_name: "rds-compare" |
| 112 | + artifact_management_spoke_cluster: "{{ spoke_cluster }}" |
| 113 | + artifact_management_temp_dir: "{{ artifacts_dir.path }}" |
| 114 | + artifact_management_test_rc: "{{ compare_result.rc }}" |
| 115 | + artifact_management_test_duration: "600" # RDS compare doesn't have duration, use default |
| 116 | + |
| 117 | +- name: Cleanup artifacts directory on bastion |
| 118 | + ansible.builtin.file: |
| 119 | + path: "{{ artifacts_dir.path }}" |
| 120 | + state: absent |
| 121 | + |
| 122 | +- name: Cleanup telco-reference clone on bastion |
| 123 | + ansible.builtin.file: |
| 124 | + path: "{{ reference_repo_path }}" |
| 125 | + state: absent |
| 126 | + |
| 127 | +- name: Fail if comparison found mismatches (unless baseline mode) |
| 128 | + ansible.builtin.fail: |
| 129 | + msg: "RDS comparison failed: cluster state does not match reference metadata. Review cluster-compare.log for details." |
| 130 | + when: |
| 131 | + - not compare_success |
| 132 | + - not (baseline | default(false)) |
| 133 | + |
| 134 | +- name: Display completion message |
| 135 | + ansible.builtin.debug: |
| 136 | + msg: |
| 137 | + - "==========================================" |
| 138 | + - "RDS Comparison Complete" |
| 139 | + - "==========================================" |
| 140 | + - "Result: {{ 'PASSED' if compare_success else ('BASELINE COLLECTED' if (baseline | default(false)) else 'FAILED') }}" |
| 141 | + - "Comparison log saved to artifacts" |
| 142 | + - "==========================================" |
0 commit comments