|
| 1 | +--- |
| 2 | +- name: Parent group inventory test |
| 3 | + hosts: instance |
| 4 | + gather_facts: true |
| 5 | + vars: |
| 6 | + cifmw_basedir: "/opt/basedir" |
| 7 | + _cifmw_libvirt_manager_layout: |
| 8 | + vms: |
| 9 | + compute1: |
| 10 | + parent_ansible_group: computes |
| 11 | + amount: 1 |
| 12 | + disk_file_name: "blank" |
| 13 | + disksize: 5 |
| 14 | + memory: 1 |
| 15 | + cpus: 1 |
| 16 | + nets: [] |
| 17 | + compute2: |
| 18 | + parent_ansible_group: computes |
| 19 | + amount: 1 |
| 20 | + disk_file_name: "blank" |
| 21 | + disksize: 5 |
| 22 | + memory: 1 |
| 23 | + cpus: 1 |
| 24 | + nets: [] |
| 25 | + controller: |
| 26 | + amount: 1 |
| 27 | + disk_file_name: "blank" |
| 28 | + disksize: 5 |
| 29 | + memory: 1 |
| 30 | + cpus: 1 |
| 31 | + nets: [] |
| 32 | + tasks: |
| 33 | + - name: Create reproducer-inventory directory |
| 34 | + become: true |
| 35 | + ansible.builtin.file: |
| 36 | + path: "{{ cifmw_basedir }}/reproducer-inventory" |
| 37 | + state: directory |
| 38 | + owner: "{{ ansible_user_id }}" |
| 39 | + group: "{{ ansible_user_id }}" |
| 40 | + mode: "0755" |
| 41 | + |
| 42 | + - name: Set all_vms fact |
| 43 | + ansible.builtin.set_fact: |
| 44 | + cifmw_libvirt_manager_all_vms: |
| 45 | + compute1-0: compute1 |
| 46 | + compute2-0: compute2 |
| 47 | + controller-0: controller |
| 48 | + |
| 49 | + - name: Add VMs to inventory |
| 50 | + vars: |
| 51 | + _full_host_name: "{{ item.key }}" |
| 52 | + _group: "{{ item.value }}" |
| 53 | + _parent_group: >- |
| 54 | + {{ |
| 55 | + _cifmw_libvirt_manager_layout.vms[item.value].parent_ansible_group | |
| 56 | + default('') |
| 57 | + }} |
| 58 | + _ssh_user: "zuul" |
| 59 | + _add_ansible_host: false |
| 60 | + _ansible_host: "" |
| 61 | + _ini_line: "{{ item.key }} ansible_user=zuul vm_type={{ item.value }}" |
| 62 | + ansible.builtin.include_role: |
| 63 | + name: libvirt_manager |
| 64 | + tasks_from: add_vm_to_inventory.yml |
| 65 | + loop: "{{ cifmw_libvirt_manager_all_vms | dict2items }}" |
| 66 | + |
| 67 | + - name: Create all group inventory |
| 68 | + ansible.builtin.include_role: |
| 69 | + name: libvirt_manager |
| 70 | + tasks_from: create_all_group_inventory.yml |
| 71 | + |
| 72 | + # --- Assertions --- |
| 73 | + |
| 74 | + - name: Assert runtime inventory has child and parent groups |
| 75 | + ansible.builtin.assert: |
| 76 | + that: |
| 77 | + - "'compute1-0' in groups['compute1s']" |
| 78 | + - "'compute2-0' in groups['compute2s']" |
| 79 | + - "'compute1-0' in groups['computes']" |
| 80 | + - "'compute2-0' in groups['computes']" |
| 81 | + - "'controller-0' in groups['controllers']" |
| 82 | + - "'controller-0' not in groups.get('computes', [])" |
| 83 | + |
| 84 | + - name: Slurp all-group.yml |
| 85 | + ansible.builtin.slurp: |
| 86 | + path: "{{ cifmw_basedir }}/reproducer-inventory/all-group.yml" |
| 87 | + register: _all_group_content |
| 88 | + |
| 89 | + - name: Assert all-group.yml has parent and child groups |
| 90 | + vars: |
| 91 | + _ag: "{{ _all_group_content.content | b64decode | from_yaml }}" |
| 92 | + ansible.builtin.assert: |
| 93 | + that: |
| 94 | + - "'compute1s' in _ag.all.children" |
| 95 | + - "'compute2s' in _ag.all.children" |
| 96 | + - "'controllers' in _ag.all.children" |
| 97 | + - "'computes' in _ag.all.children" |
| 98 | + - "'compute1s' in _ag.all.children.computes.children" |
| 99 | + - "'compute2s' in _ag.all.children.computes.children" |
| 100 | + - "'controllers' not in _ag.all.children.computes.children" |
| 101 | + |
| 102 | +- name: Parent group collision validation test |
| 103 | + hosts: instance |
| 104 | + gather_facts: false |
| 105 | + vars: |
| 106 | + _cifmw_libvirt_manager_layout: |
| 107 | + vms: |
| 108 | + compute: |
| 109 | + parent_ansible_group: computes |
| 110 | + amount: 1 |
| 111 | + disk_file_name: "blank" |
| 112 | + disksize: 5 |
| 113 | + memory: 1 |
| 114 | + cpus: 1 |
| 115 | + nets: [] |
| 116 | + computes: |
| 117 | + parent_ansible_group: bigcomputes |
| 118 | + amount: 1 |
| 119 | + disk_file_name: "blank" |
| 120 | + disksize: 5 |
| 121 | + memory: 1 |
| 122 | + cpus: 1 |
| 123 | + nets: [] |
| 124 | + tasks: |
| 125 | + - name: Verify collision detection rejects overlapping names |
| 126 | + block: |
| 127 | + - name: Run deploy_layout validation with colliding layout |
| 128 | + ansible.builtin.include_role: |
| 129 | + name: libvirt_manager |
| 130 | + tasks_from: deploy_layout.yml |
| 131 | + |
| 132 | + - name: Fail if validation did not catch collision |
| 133 | + ansible.builtin.fail: |
| 134 | + msg: >- |
| 135 | + deploy_layout.yml should have failed due to |
| 136 | + 'computes' colliding with compute's parent_ansible_group |
| 137 | +
|
| 138 | + rescue: |
| 139 | + - name: Assert failure message mentions collision |
| 140 | + ansible.builtin.assert: |
| 141 | + that: |
| 142 | + - >- |
| 143 | + ansible_failed_result.msg is defined and |
| 144 | + 'Collisions' in ansible_failed_result.msg |
0 commit comments