Files
ansible-collections-openstack/ci/roles/image/tasks/main.yml
T
Moritz Tanner 34a99f549b image: do a web-download import when uri is given
The module documents and accepts import_method and uri, but nothing ever
acts on them for a URL-based import. Its only import_image() call is
hardcoded to glance-direct, so asking Glance to fetch an image itself is
not possible.

Worse, the two options are listed in attr_params, so they are handed to
conn.create_image() as unrecognised keyword arguments and end up stored
on the image as arbitrary properties. With no filename the create call
then reaches the direct upload endpoint with no data, which Glance
rejects:

  HttpException: 415: Client Error for url:
  .../v2/images/<id>/file, Unsupported Media Type
  Image disk_format qcow2 does not match stream data raw

Import a queued image from its uri instead, defaulting the method to
web-download, and drop the three behavioural options from attr_params so
they stop becoming image properties. When creating the image, do not let
create_image() wait for it to become active, since it stays queued until
the import is started.

Remove glance-download from the import_method choices. The module never
used it. The glance-download method takes a remote region and a remote
image ID, and the module has no options for these yet.

Closes-Bug: #2167999
Change-Id: I11fa064567c36012cd51c78e4bca2c46152990d3
Signed-off-by: Moritz Tanner <moritz.tanner@linbit.com>
2026-10-22 15:12:20 +02:00

424 lines
11 KiB
YAML

---
- name: Test images
block:
- name: List all images
openstack.cloud.image_info:
cloud: "{{ cloud }}"
register: images
- name: Assert existence of CirrOS image
assert:
that:
- images.images | length > 0
- name: Ensure clean environment
ansible.builtin.set_fact:
tmp_file: !!null
- name: Create a test image file
ansible.builtin.tempfile:
register: tmp_file
- name: Fill test image file to 1MB
community.general.filesize:
path: '{{ tmp_file.path }}'
size: 1M
- name: Calculating file checksum
ansible.builtin.stat:
path: "{{ tmp_file.path }}"
checksum_algorithm: sha512
get_checksum: true
register: image_details
- name: Ensure mock kernel and ramdisk images (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ item }}"
filename: "{{ tmp_file.path }}"
disk_format: raw
loop:
- cirros-vmlinuz
- cirros-initrd
- name: Create raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
filename: "{{ tmp_file.path }}"
is_protected: true
checksum: "{{ image_details.stat.checksum }}"
disk_format: raw
tags:
- test
- ansible
register: image
- name: Assert changed
assert:
that:
- image is changed
- name: Assert return values of image module
assert:
that:
- image is changed
- image.image.name == 'ansible_image'
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(image.image.keys())|length == 0
- name: Get details of created image
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: ansible_image
register: images
- name: Assert return values of image_info module
assert:
that:
- images.images | length > 0
- images.images.0.name == "ansible_image"
- images.images.0.tags | sort == ['test', 'ansible'] | sort
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(images.images.0.keys())|length == 0
- name: Create raw image again (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
filename: "{{ tmp_file.path }}"
is_protected: true
disk_format: raw
tags:
- test
- ansible
register: image
- name: Assert not changed
assert:
that:
- image is not changed
- name: Update is_protected on raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
is_protected: false
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.is_protected == false
- name: Assert changed
assert:
that:
- image is changed
- name: Update visibility on raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
is_public: false
register: image
- name: Assert changed
assert:
that:
- image.image.visibility == 'private'
- name: Update again visibility on raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
is_public: true
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.visibility == 'public'
- name: Define visibility on raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
visibility: shared
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.visibility == 'shared'
- name: Rename raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
id: "{{ image.image.id }}"
name: 'ansible_image-changed'
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.name == 'ansible_image-changed'
- name: Deactivate raw image
openstack.cloud.image:
cloud: "{{ cloud }}"
state: inactive
id: "{{ image.image.id }}"
name: 'ansible_image-changed'
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.status == 'deactivated'
- name: Reactivate raw image
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
id: "{{ image.image.id }}"
name: 'ansible_image-changed'
register: image
- name: Assert changed
assert:
that:
- image is changed
- image.image.status == 'active'
- name: Rename back raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
id: "{{ image.image.id }}"
name: ansible_image
register: image
- name: Delete raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image
register: image
- name: assert image changed
assert:
that:
- image is changed
- name: Delete raw image again (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image
register: image
- name: assert image not changed
assert:
that:
- image is not changed
- name: Create raw image (complex)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
filename: "{{ tmp_file.path }}"
disk_format: raw
is_public: True
min_disk: 10
min_ram: 1024
# TODO(rcastillo): upload cirros-vmlinuz, cirros-initrd in test setup
kernel: cirros-vmlinuz
ramdisk: cirros-initrd
properties:
cpu_arch: x86_64
distro: ubuntu
register: image
- name: Assert visibility
assert:
that:
- image.image.visibility == 'public'
- name: Delete raw image (complex)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image
- name: Try to get details of deleted image
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: ansible_image
register: images
- name: Verify image is deleted
assert:
that:
- images.images | length == 0
- name: Create owner project
openstack.cloud.project:
cloud: "{{ cloud }}"
state: present
name: ansible_project
description: Project owning test image
domain: default
is_enabled: True
register: project
- name: Create raw image (owner by project name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
filename: "{{ tmp_file.path }}"
disk_format: raw
tags:
- test
- ansible
project: ansible_project
register: image
- name: Get details of created image (owner by project name)
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: ansible_image
register: images
- name: Verify image owner (owner by project name)
assert:
that:
- images.images.0.owner == project.project.id
- name: Delete raw image (owner by project name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image
- name: Create raw image (owner by project name and domain name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image
filename: "{{ tmp_file.path }}"
disk_format: raw
tags:
- test
- ansible
project: ansible_project
project_domain: default
register: image
- name: Get details of created image (owner by project name and domain name)
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: ansible_image
register: images
- name: Verify image owner (owner by project name and domain name)
assert:
that:
- images.images.0.owner == project.project.id
- name: Delete raw image (owner by project name and domain name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image
- name: Delete owner project
openstack.cloud.project:
cloud: "{{ cloud }}"
state: absent
name: ansible_project
domain: default
- name: Delete mock kernel and ramdisk images
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ item }}"
loop:
- cirros-vmlinuz
- cirros-initrd
- name: Delete test image file
file:
name: "{{ tmp_file.path }}"
state: absent
- name: Import an image with web-download
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image_web_download
container_format: bare
disk_format: qcow2
import_method: web-download
uri: "{{ image_web_download_uri }}"
register: web_download_image
- name: Assert the image was fetched by the Image service
assert:
that:
- web_download_image is changed
- web_download_image.image.status == 'active'
- web_download_image.image.size > 0
- name: Assert import options were not stored as image properties
assert:
that:
- "'uri' not in web_download_image.image.properties"
- "'import_method' not in web_download_image.image.properties"
- "'use_import' not in web_download_image.image.properties"
- name: Import the same image again
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: ansible_image_web_download
container_format: bare
disk_format: qcow2
import_method: web-download
uri: "{{ image_web_download_uri }}"
register: web_download_image
- name: Assert the second import did not change anything
assert:
that:
- web_download_image is not changed
- name: Delete the web-download image
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: ansible_image_web_download
always:
- name: Remove temporary image file
ansible.builtin.file:
path: "{{ tmp_file.path }}"
state: absent
when: tmp_file is defined and 'path' in tmp_file