Add a role to convert diskimages between formats
This adds a role convert-diskimage which uses the qemu-img tool to convert diskimages from one format to another. Currently supported image formats are raw and qcow2. Change-Id: I4770af04c37f39e0cce23d5dd59ead744bed7d74
This commit is contained in:
parent
dded8d0853
commit
5c10b708f0
@ -3,3 +3,4 @@ Diskimage-Builder Roles
|
||||
|
||||
.. zuul:autorole:: ensure-dib
|
||||
.. zuul:autorole:: build-diskimage
|
||||
.. zuul:autorole:: convert-diskimage
|
||||
|
19
roles/convert-diskimage/README.rst
Normal file
19
roles/convert-diskimage/README.rst
Normal file
@ -0,0 +1,19 @@
|
||||
This role converts diskimages from one format to other using the qemu-img tool.
|
||||
|
||||
Currently, only Ubuntu and Debian distributions are supported.
|
||||
|
||||
**Role variables**
|
||||
|
||||
.. zuul:rolevar:: convert_diskimage_source_image
|
||||
|
||||
The path to the source image file.
|
||||
|
||||
.. zuul:rolevar:: convert_diskimage_target_image
|
||||
|
||||
The path of the desired target image file.
|
||||
|
||||
.. zuul:rolevar:: convert_diskimage_target_image_formats
|
||||
:type: list
|
||||
|
||||
The desired formats of the target image.
|
||||
Supported values are "raw" and "qcow2".
|
32
roles/convert-diskimage/tasks/main.yaml
Normal file
32
roles/convert-diskimage/tasks/main.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
- name: Make sure the role is run on Debian or Ubuntu
|
||||
fail:
|
||||
msg: "This role supports Debian and Ubuntu distributions only"
|
||||
when: ansible_distribution not in ["Debian", "Ubuntu"]
|
||||
|
||||
- name: Make sure required variables are set
|
||||
assert:
|
||||
that:
|
||||
- convert_diskimage_source_image is defined
|
||||
- convert_diskimage_target_image is defined
|
||||
- convert_diskimage_target_formats is defined
|
||||
|
||||
- name: Make sure target formats are supported
|
||||
assert:
|
||||
that: zj_format in convert_diskimage_supported_formats
|
||||
loop: "{{ convert_diskimage_target_formats }}"
|
||||
loop_control:
|
||||
loop_var: zj_format
|
||||
|
||||
- name: Install qemu tools
|
||||
become: true
|
||||
package:
|
||||
state: present
|
||||
name: qemu-utils
|
||||
|
||||
- name: Convert image to the given formats
|
||||
command: >
|
||||
qemu-img convert {{ convert_diskimage_source_image }}
|
||||
-O {{ zj_format }} {{ convert_diskimage_target_image }}.{{ zj_format }}
|
||||
loop: "{{ convert_diskimage_target_formats }}"
|
||||
loop_control:
|
||||
loop_var: zj_format
|
3
roles/convert-diskimage/vars/main.yaml
Normal file
3
roles/convert-diskimage/vars/main.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
convert_diskimage_supported_formats:
|
||||
- raw
|
||||
- qcow2
|
21
test-playbooks/diskimage-builder/convert-diskimage.yaml
Normal file
21
test-playbooks/diskimage-builder/convert-diskimage.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
- hosts: all
|
||||
roles:
|
||||
- ensure-dib
|
||||
- role: build-diskimage
|
||||
build_diskimage_image_name: foo-ubuntu-image
|
||||
build_diskimage_formats: ["raw"]
|
||||
build_diskimage_elements: ["vm", "ubuntu"]
|
||||
environment:
|
||||
DIB_RELEASE: "noble"
|
||||
- role: convert-diskimage
|
||||
convert_diskimage_source_image: "/home/zuul/dib-images/foo-ubuntu-image.raw"
|
||||
convert_diskimage_target_image: "/home/zuul/dib-images/foo-ubuntu-image"
|
||||
convert_diskimage_target_formats: ["qcow2"]
|
||||
tasks:
|
||||
- name: Gather image file info
|
||||
stat:
|
||||
path: "/home/zuul/dib-images/foo-ubuntu-image.qcow2"
|
||||
register: image_file
|
||||
- name: Assert image file exists
|
||||
assert:
|
||||
that: image_file.stat.exists
|
@ -116,6 +116,67 @@
|
||||
- name: ubuntu-noble
|
||||
label: ubuntu-noble
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage
|
||||
description: Test the convert-diskimage role
|
||||
files:
|
||||
- roles/convert-diskimage/.*
|
||||
- test-playbooks/diskimage-builder/.*
|
||||
run: test-playbooks/diskimage-builder/convert-diskimage.yaml
|
||||
required-projects:
|
||||
- openstack/diskimage-builder
|
||||
tags: debuntu-platforms
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage-debian-bookworm
|
||||
description: Test the convert-diskimage role on debian-bookworm
|
||||
parent: zuul-jobs-test-convert-diskimage
|
||||
tags: auto-generated
|
||||
nodeset:
|
||||
nodes:
|
||||
- name: debian-bookworm
|
||||
label: debian-bookworm
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage-debian-bullseye
|
||||
description: Test the convert-diskimage role on debian-bullseye
|
||||
parent: zuul-jobs-test-convert-diskimage
|
||||
tags: auto-generated
|
||||
nodeset:
|
||||
nodes:
|
||||
- name: debian-bullseye
|
||||
label: debian-bullseye
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage-ubuntu-focal
|
||||
description: Test the convert-diskimage role on ubuntu-focal
|
||||
parent: zuul-jobs-test-convert-diskimage
|
||||
tags: auto-generated
|
||||
nodeset:
|
||||
nodes:
|
||||
- name: ubuntu-focal
|
||||
label: ubuntu-focal
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage-ubuntu-jammy
|
||||
description: Test the convert-diskimage role on ubuntu-jammy
|
||||
parent: zuul-jobs-test-convert-diskimage
|
||||
tags: auto-generated
|
||||
nodeset:
|
||||
nodes:
|
||||
- name: ubuntu-jammy
|
||||
label: ubuntu-jammy
|
||||
|
||||
- job:
|
||||
name: zuul-jobs-test-convert-diskimage-ubuntu-noble
|
||||
description: Test the convert-diskimage role on ubuntu-noble
|
||||
parent: zuul-jobs-test-convert-diskimage
|
||||
tags: auto-generated
|
||||
nodeset:
|
||||
nodes:
|
||||
- name: ubuntu-noble
|
||||
label: ubuntu-noble
|
||||
|
||||
- project:
|
||||
check:
|
||||
jobs: &id001
|
||||
@ -129,6 +190,11 @@
|
||||
- zuul-jobs-test-build-diskimage-ubuntu-focal
|
||||
- zuul-jobs-test-build-diskimage-ubuntu-jammy
|
||||
- zuul-jobs-test-build-diskimage-ubuntu-noble
|
||||
- zuul-jobs-test-convert-diskimage-debian-bookworm
|
||||
- zuul-jobs-test-convert-diskimage-debian-bullseye
|
||||
- zuul-jobs-test-convert-diskimage-ubuntu-focal
|
||||
- zuul-jobs-test-convert-diskimage-ubuntu-jammy
|
||||
- zuul-jobs-test-convert-diskimage-ubuntu-noble
|
||||
gate:
|
||||
jobs: *id001
|
||||
periodic-weekly:
|
||||
|
Loading…
Reference in New Issue
Block a user