Customize downloaded Ubuntu images

Instead of making tobiko customize Ubuntu images during test execution,
the Tobiko ansible roles run before that will do it.

Related: #TOBIKO-126

Change-Id: I5c6746c6ad488eb4b27164faea67a5c0253f15f3
This commit is contained in:
Eduardo Olivares 2024-11-28 18:16:48 +01:00
parent 24b9dc019b
commit 8466581e52
3 changed files with 41 additions and 1 deletions

View File

@ -59,6 +59,18 @@ test_collect_dir: '{{ test_src_dir | realpath }}/{{ test_report_name }}'
# --- download-images options -------------------------------------------------
download_images_dir: "{{ ansible_user_dir }}/.downloaded-images"
download_images:
ubuntu-minimal:
ubuntu-customized:
type: ubuntu
url: "https://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64.img"
customized: false
customize_command_pattern: >
LIBGUESTFS_BACKEND=direct virt-customize -a $TMPPATH
--firstboot-command 'sh -c "hostname > /var/www/html/id"'
--install iperf3,iputils-ping,ncat,nginx,vlan
--run-command 'echo "[Unit]\nDescription=iperf3 server on port %i\nAfter=syslog.target network.target\n\n[Service]\nExecStart=/usr/bin/iperf3 -s -p %i\nRestart=always\nUser=root\n\n[Install]\nWantedBy=multi-user.target\nDefaultInstance=5201\n"
> /etc/systemd/system/iperf3-server@.service'
--run-command 'systemctl enable iperf3-server@5201'
--run-command 'echo "8021q" >> /etc/modules'
--run-command
'echo "network:\n version: 2\n vlans:\n vlan101:\n dhcp4: true\n dhcp4-overrides:\n use-routes: false\n dhcp6: true\n dhcp6-overrides:\n use-routes: false\n id: 101\n link: ens3\n"
> /etc/netplan/75-tobiko-vlan.yaml'

View File

@ -25,6 +25,11 @@
- section: "{{ dict_value.type }}"
option: image_url
value: "file://{{ download_images_dir }}/{{ file_name }}"
{% if dict_value.customized | default(False) | bool or dict_value.customize_command_pattern is defined %}
- section: "{{ dict_value.type }}"
option: customized_image_provided
value: True
{% endif %}
{% endfor %}
vars:
sections: "{{ test_default_conf | combine(test_conf, recursive=True) }}"

View File

@ -13,3 +13,26 @@
retries: 5
until: download is success
with_dict: "{{ download_images }}"
- name: install libguestfs-tools
become: true
package:
name: libguestfs-tools
- name: customize images
# root needed to avoid the supermin issue:
# https://github.com/virt-manager/virt-bootstrap/issues/9
become: yes
vars:
image_file_path: "{{ download_images_dir }}/{{ item.key }}"
shell: |
set -xe
TMPPATH=$(mktemp)
cp {{ image_file_path }} $TMPPATH
{{ item.value.customize_command_pattern }}
mv $TMPPATH {{ image_file_path }}
chmod a+r {{ image_file_path }}
when:
- not (item.value.customized | default(False) | bool)
- item.value.customize_command_pattern is defined
with_dict: "{{ download_images }}"