|
55 | 55 | retries: 60 |
56 | 56 | delay: 10 |
57 | 57 |
|
| 58 | + # Build the image |
58 | 59 | - name: Build nat64 appliance image |
59 | 60 | vars: |
60 | 61 | # TODO(hjensas): Running as root should not be required here. |
|
85 | 86 | owner: "{{ ansible_user_id }}" |
86 | 87 | group: "{{ ansible_user_gid }}" |
87 | 88 |
|
| 89 | + # Test download functionality |
| 90 | + - name: Set download test directory |
| 91 | + ansible.builtin.set_fact: |
| 92 | + cifmw_nat64_download_dir: "{{ cifmw_basedir }}/nat64_download" |
| 93 | + cifmw_nat64_http_port: 8765 |
| 94 | + |
| 95 | + - name: Start HTTP server to serve the built image |
| 96 | + ansible.builtin.shell: | |
| 97 | + cd {{ cifmw_basedir }}/nat64_appliance |
| 98 | + nohup python3 -m http.server {{ cifmw_nat64_http_port }} > /tmp/nat64_http_server.log 2>&1 & |
| 99 | + echo $! > /tmp/nat64_http_server.pid |
| 100 | + sleep 2 |
| 101 | +
|
| 102 | + - name: Verify HTTP server is running |
| 103 | + ansible.builtin.uri: |
| 104 | + url: "http://localhost:{{ cifmw_nat64_http_port }}/nat64-appliance.qcow2" |
| 105 | + method: HEAD |
| 106 | + register: _http_check |
| 107 | + until: _http_check.status == 200 |
| 108 | + retries: 5 |
| 109 | + delay: 2 |
| 110 | + |
| 111 | + - name: Download nat64 appliance image from HTTP server |
| 112 | + vars: |
| 113 | + cifmw_nat64_appliance_basedir: "{{ cifmw_nat64_download_dir }}" |
| 114 | + cifmw_nat64_appliance_image_url: "http://localhost:{{ cifmw_nat64_http_port }}/nat64-appliance.qcow2" |
| 115 | + ansible.builtin.include_role: |
| 116 | + name: nat64_appliance |
| 117 | + |
| 118 | + - name: Verify downloaded image exists |
| 119 | + ansible.builtin.stat: |
| 120 | + path: "{{ cifmw_nat64_download_dir }}/nat64_appliance/nat64-appliance.qcow2" |
| 121 | + checksum_algorithm: sha256 |
| 122 | + register: _downloaded_image |
| 123 | + failed_when: not _downloaded_image.stat.exists |
| 124 | + |
| 125 | + - name: Get built image info with checksum |
| 126 | + ansible.builtin.stat: |
| 127 | + path: "{{ cifmw_basedir }}/nat64_appliance/nat64-appliance.qcow2" |
| 128 | + checksum_algorithm: sha256 |
| 129 | + register: _built_image |
| 130 | + |
| 131 | + - name: Show download test results |
| 132 | + ansible.builtin.debug: |
| 133 | + msg: |
| 134 | + - "Built image: {{ _built_image.stat.path }} ({{ _built_image.stat.size }} bytes, SHA256: {{ _built_image.stat.checksum }})" |
| 135 | + - "Downloaded image: {{ _downloaded_image.stat.path }} ({{ _downloaded_image.stat.size }} bytes, SHA256: {{ _downloaded_image.stat.checksum }})" |
| 136 | + |
| 137 | + - name: Verify images are identical using checksum |
| 138 | + ansible.builtin.assert: |
| 139 | + that: |
| 140 | + - _downloaded_image.stat.size > 0 |
| 141 | + - _built_image.stat.size > 0 |
| 142 | + - _downloaded_image.stat.checksum == _built_image.stat.checksum |
| 143 | + fail_msg: | |
| 144 | + Downloaded image differs from built image! |
| 145 | + Built: {{ _built_image.stat.size }} bytes, SHA256: {{ _built_image.stat.checksum }} |
| 146 | + Downloaded: {{ _downloaded_image.stat.size }} bytes, SHA256: {{ _downloaded_image.stat.checksum }} |
| 147 | + success_msg: "Images are identical - SHA256: {{ _built_image.stat.checksum }} ({{ _built_image.stat.size }} bytes)" |
| 148 | + |
| 149 | + - name: Stop HTTP server |
| 150 | + ansible.builtin.shell: | |
| 151 | + if [ -f /tmp/nat64_http_server.pid ]; then |
| 152 | + kill $(cat /tmp/nat64_http_server.pid) || true |
| 153 | + rm -f /tmp/nat64_http_server.pid |
| 154 | + fi |
| 155 | +
|
| 156 | + # Deploy nat64 appliance for testing |
| 157 | + - name: Copy downloaded image to working location for deployment |
| 158 | + ansible.builtin.copy: |
| 159 | + src: "{{ cifmw_nat64_download_dir }}/nat64_appliance/nat64-appliance.qcow2" |
| 160 | + dest: "{{ cifmw_basedir }}/nat64_appliance/nat64-appliance.qcow2" |
| 161 | + remote_src: true |
| 162 | + mode: "0644" |
| 163 | + |
88 | 164 | - name: "Deploy the nat64 appliance and networks" |
89 | 165 | vars: |
90 | 166 | cifmw_nat64_appliance_ssh_pub_keys: |
|
0 commit comments