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>
This commit is contained in:
Moritz Tanner
2026-10-22 15:12:20 +02:00
parent ad7205503e
commit 34a99f549b
4 changed files with 107 additions and 17 deletions
+3
View File
@@ -63,3 +63,6 @@ expected_fields:
- vm_mode
- vmware_adaptertype
- vmware_ostype
# Fetched by the Image service itself in the web-download test.
image_web_download_uri: https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img
+47
View File
@@ -368,6 +368,53 @@
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: