Skip to content

Commit 11ceb03

Browse files
committed
[nat64_appliance] Add support for downloading pre-built images
Introduce cifmw_nat64_appliance_image_url parameter to download pre-built NAT64 images, with optional checksum verification support. Signed-off-by: Miguel Angel Nieto Jimenez <[email protected]>
1 parent 5f5393f commit 11ceb03

File tree

13 files changed

+328
-48
lines changed

13 files changed

+328
-48
lines changed

docs/dictionary/en-custom.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ dib
153153
dicts
154154
dirs
155155
disablecertificateverification
156+
diskimage
156157
disksize
157158
distro
158159
dlrn

roles/nat64_appliance/README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,38 @@
2525
* `cifmw_nat64_appliance_memory`: (Integer) Memory in GiB for the nat64 appliance VM. Defaults to: `2`.
2626
* `cifmw_nat64_appliance_cpus`: (Integer) Virtual CPUs for the nat64 appliance VM. Defaults to: `2`.
2727
* `cifmw_nat64_appliance_ssh_pub_keys`: (List) List of SSH public key for the nat64 appliance VM. Defaults to: `[]`.
28+
* `cifmw_nat64_appliance_image_url`: (String) URL to download a pre-built NAT64 appliance image. If empty, the image will be built from source using diskimage-builder. Defaults to: `""`.
29+
* `cifmw_nat64_appliance_image_checksum`: (String) Optional checksum for the downloaded image in the format `algorithm:hash` (e.g., `sha256:xxxxx`). Only used when `cifmw_nat64_appliance_image_url` is set. Defaults to: undefined.
30+
* `cifmw_nat64_appliance_download_timeout`: (Integer) Timeout in seconds for image download. Only used when `cifmw_nat64_appliance_image_url` is set. Defaults to: `600`.
2831
* `cifmw_nat64_ipv6_prefix`: (String) IPv6 prefix for nat64. Defaults to: `fc00:abcd:abcd:fc00::/64`.
2932
* `cifmw_nat64_ipv6_tayga_address`: (String) Tayga IPv6 address. Defaults to: `fc00:abcd:abcd:fc00::3`.
3033

3134
## Building the image
3235

3336
Include the `nat64_appliance` role in a playbook. For example:
3437

38+
### Build from source
39+
40+
```yaml
41+
- name: Build nat64-appliance from source
42+
hosts: "{{ cifmw_target_host | default('localhost') }}"
43+
roles:
44+
- nat64_appliance
3545
```
36-
- name: Build nat64-appliance
46+
47+
### Download pre-built image
48+
49+
```yaml
50+
- name: Download pre-built nat64-appliance image
3751
hosts: "{{ cifmw_target_host | default('localhost') }}"
52+
vars:
53+
cifmw_nat64_appliance_image_url: "http://example.com/nat64-appliance.qcow2"
54+
# cifmw_nat64_appliance_image_checksum: "sha256:xxxxx" # Optional
3855
roles:
3956
- nat64_appliance
4057
```
4158
42-
The built image will be in: `{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2`
59+
The image will be in: `{{ cifmw_nat64_appliance_workdir }}/nat64-appliance.qcow2`
4360

4461
## Using the nat64-appliance
4562

roles/nat64_appliance/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ cifmw_nat64_appliance_memory: 2
4040
cifmw_nat64_appliance_cpus: 2
4141
cifmw_nat64_appliance_ssh_pub_keys: []
4242

43+
# Image download configuration
44+
# Set cifmw_nat64_appliance_image_url to download a pre-built image
45+
cifmw_nat64_appliance_image_url: ""
46+
cifmw_nat64_appliance_download_timeout: 600 # 10 minutes
4347

4448
cifmw_nat64_ipv6_prefix: "2620:cf:cf:fc00::/64"
4549
cifmw_nat64_ipv6_tayga_address: "2620:cf:cf:fc00::3"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
- name: Cleanup
18+
hosts: instance
19+
vars:
20+
cifmw_basedir: "{{ ansible_user_dir }}/ci-framework-data"
21+
tasks:
22+
- name: Stop HTTP server if running
23+
ansible.builtin.shell: |
24+
if [ -f /tmp/nat64_http_server.pid ]; then
25+
kill $(cat /tmp/nat64_http_server.pid) || true
26+
rm -f /tmp/nat64_http_server.pid /tmp/nat64_http_server.log
27+
fi
28+
pkill -f "python3 -m http.server 8765" || true
29+
ignore_errors: true
30+
31+
- name: Cleanup nat64 appliance
32+
ansible.builtin.include_role:
33+
name: nat64_appliance
34+
tasks_from: cleanup.yml
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
# Scenario to test both build and download modes
3+
# 1. Build image from source
4+
# 2. Serve it via HTTP
5+
# 3. Download and test it
6+
log: true
7+
8+
provisioner:
9+
name: ansible
10+
log: true

0 commit comments

Comments
 (0)