|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +# This scenario tests BOTH build and download modes: |
| 18 | +# 1. Build image from source |
| 19 | +# 2. Serve the built image via HTTP |
| 20 | +# 3. Download the image using the download feature |
| 21 | +# 4. Test that both images work |
| 22 | + |
| 23 | +- name: Converge - Test build and download modes |
| 24 | + hosts: instance |
| 25 | + vars: |
| 26 | + cifmw_basedir: "{{ ansible_user_dir }}/ci-framework-data" |
| 27 | + cifmw_nat64_build_dir: "{{ cifmw_basedir }}/nat64_build" |
| 28 | + cifmw_nat64_download_dir: "{{ cifmw_basedir }}/nat64_download" |
| 29 | + cifmw_nat64_http_port: 8765 |
| 30 | + tasks: |
| 31 | + - name: Create SSH keypair |
| 32 | + register: _test_key |
| 33 | + community.crypto.openssh_keypair: |
| 34 | + comment: "test-key" |
| 35 | + path: "{{ (ansible_user_dir, '.ssh/id_test') | path_join }}" |
| 36 | + type: "ecdsa" |
| 37 | + |
| 38 | + - name: Enable forwarding in the libvirt zone |
| 39 | + become: true |
| 40 | + ansible.builtin.command: |
| 41 | + cmd: >- |
| 42 | + firewall-cmd --permanent --zone libvirt --add-forward |
| 43 | +
|
| 44 | + - name: Restart firewalld.service |
| 45 | + become: true |
| 46 | + ansible.builtin.systemd_service: |
| 47 | + name: firewalld |
| 48 | + state: restarted |
| 49 | + |
| 50 | + # ============================================================= |
| 51 | + # PHASE 1: Build image from source |
| 52 | + # ============================================================= |
| 53 | + - name: "PHASE 1: Build nat64 appliance image from source" |
| 54 | + vars: |
| 55 | + cifmw_basedir: "{{ cifmw_nat64_build_dir }}" |
| 56 | + cifmw_nat64_appliance_run_dib_as_root: true |
| 57 | + ansible.builtin.include_role: |
| 58 | + name: nat64_appliance |
| 59 | + |
| 60 | + - name: Fix permissions on nat64_appliance dir (built as root) |
| 61 | + become: true |
| 62 | + ansible.builtin.file: |
| 63 | + path: "{{ cifmw_nat64_build_dir }}/nat64_appliance" |
| 64 | + state: directory |
| 65 | + mode: "0755" |
| 66 | + recurse: true |
| 67 | + owner: "{{ ansible_user_id }}" |
| 68 | + group: "{{ ansible_user_gid }}" |
| 69 | + |
| 70 | + - name: Verify built image exists |
| 71 | + ansible.builtin.stat: |
| 72 | + path: "{{ cifmw_nat64_build_dir }}/nat64_appliance/nat64-appliance.qcow2" |
| 73 | + register: _built_image |
| 74 | + failed_when: not _built_image.stat.exists |
| 75 | + |
| 76 | + - name: Show built image info |
| 77 | + ansible.builtin.debug: |
| 78 | + msg: "Built image: {{ _built_image.stat.path }} ({{ _built_image.stat.size }} bytes)" |
| 79 | + |
| 80 | + # ============================================================= |
| 81 | + # PHASE 2: Serve image via HTTP and download it |
| 82 | + # ============================================================= |
| 83 | + - name: Start HTTP server to serve the built image |
| 84 | + ansible.builtin.shell: | |
| 85 | + cd {{ cifmw_nat64_build_dir }}/nat64_appliance |
| 86 | + nohup python3 -m http.server {{ cifmw_nat64_http_port }} > /tmp/nat64_http_server.log 2>&1 & |
| 87 | + echo $! > /tmp/nat64_http_server.pid |
| 88 | + sleep 2 |
| 89 | +
|
| 90 | + - name: Verify HTTP server is running |
| 91 | + ansible.builtin.uri: |
| 92 | + url: "http://localhost:{{ cifmw_nat64_http_port }}/nat64-appliance.qcow2" |
| 93 | + method: HEAD |
| 94 | + register: _http_check |
| 95 | + until: _http_check.status == 200 |
| 96 | + retries: 5 |
| 97 | + delay: 2 |
| 98 | + |
| 99 | + - name: "PHASE 2: Download nat64 appliance image from HTTP server" |
| 100 | + vars: |
| 101 | + cifmw_basedir: "{{ cifmw_nat64_download_dir }}" |
| 102 | + cifmw_nat64_appliance_image_url: "http://localhost:{{ cifmw_nat64_http_port }}/nat64-appliance.qcow2" |
| 103 | + ansible.builtin.include_role: |
| 104 | + name: nat64_appliance |
| 105 | + |
| 106 | + - name: Verify downloaded image exists |
| 107 | + ansible.builtin.stat: |
| 108 | + path: "{{ cifmw_nat64_download_dir }}/nat64_appliance/nat64-appliance.qcow2" |
| 109 | + register: _downloaded_image |
| 110 | + failed_when: not _downloaded_image.stat.exists |
| 111 | + |
| 112 | + - name: Show downloaded image info |
| 113 | + ansible.builtin.debug: |
| 114 | + msg: "Downloaded image: {{ _downloaded_image.stat.path }} ({{ _downloaded_image.stat.size }} bytes)" |
| 115 | + |
| 116 | + - name: Verify both images have the same size |
| 117 | + ansible.builtin.assert: |
| 118 | + that: |
| 119 | + - _built_image.stat.size == _downloaded_image.stat.size |
| 120 | + fail_msg: "Image size mismatch! Built: {{ _built_image.stat.size }}, Downloaded: {{ _downloaded_image.stat.size }}" |
| 121 | + success_msg: "Both images have the same size ({{ _built_image.stat.size }} bytes)" |
| 122 | + |
| 123 | + # ============================================================= |
| 124 | + # PHASE 3: Test the downloaded image (deploy and verify) |
| 125 | + # ============================================================= |
| 126 | + - name: "Deploy the nat64 appliance using downloaded image" |
| 127 | + vars: |
| 128 | + cifmw_basedir: "{{ cifmw_nat64_download_dir }}" |
| 129 | + cifmw_nat64_appliance_ssh_pub_keys: |
| 130 | + - "{{ _test_key.public_key }}" |
| 131 | + ansible.builtin.include_role: |
| 132 | + name: nat64_appliance |
| 133 | + tasks_from: deploy.yml |
| 134 | + |
| 135 | + - name: Verify nat64-appliance VM is running |
| 136 | + community.libvirt.virt: |
| 137 | + command: status |
| 138 | + name: nat64-appliance |
| 139 | + uri: 'qemu:///system' |
| 140 | + register: _vm_status |
| 141 | + failed_when: _vm_status.status != "running" |
| 142 | + |
| 143 | + always: |
| 144 | + - name: Stop HTTP server |
| 145 | + ansible.builtin.shell: | |
| 146 | + if [ -f /tmp/nat64_http_server.pid ]; then |
| 147 | + kill $(cat /tmp/nat64_http_server.pid) || true |
| 148 | + rm -f /tmp/nat64_http_server.pid |
| 149 | + fi |
| 150 | + ignore_errors: true |
0 commit comments