Update image for new sdk

- Use proxy layer where possible
  - Image upload has some tricky logic so that stays in the cloud layer
- Convert return value to dict
- Document return values
- Update visibility logic for glance v2 api
- Increase test coverage
- General refactoring to bring more in line with rest of collection
- Deprecate is_public attribute which has been replaced with
  visibility.
- Deprecate volume attribute which has been made obsolete with
  openstack.cloud.volume module. Removed examples showing the volume
  attribute since users are encouraged to use openstack.cloud.volume
  module.

Change-Id: I1d8034a3b9a391444ea275b68b06ee3a291c73c3
This commit is contained in:
Rafael Castillo
2022-06-09 15:34:41 -07:00
parent caf1bc49da
commit 2419b5ab19
3 changed files with 586 additions and 98 deletions

View File

@@ -2,3 +2,68 @@ image_name: ansible_image
image_tags:
- test
- ansible
expected_fields:
- architecture
- checksum
- container_format
- created_at
- direct_url
- disk_format
- file
- has_auto_disk_config
- hash_algo
- hash_value
- hw_cpu_cores
- hw_cpu_policy
- hw_cpu_sockets
- hw_cpu_thread_policy
- hw_cpu_threads
- hw_disk_bus
- hw_machine_type
- hw_qemu_guest_agent
- hw_rng_model
- hw_scsi_model
- hw_serial_port_count
- hw_video_model
- hw_video_ram
- hw_vif_model
- hw_watchdog_action
- hypervisor_type
- id
- instance_type_rxtx_factor
- instance_uuid
- is_hidden
- is_hw_boot_menu_enabled
- is_hw_vif_multiqueue_enabled
- is_protected
- kernel_id
- locations
- metadata
- min_disk
- min_ram
- name
- needs_config_drive
- needs_secure_boot
- os_admin_user
- os_command_line
- os_distro
- os_require_quiesce
- os_shutdown_timeout
- os_type
- os_version
- owner
- owner_id
- properties
- ramdisk_id
- schema
- size
- status
- store
- tags
- updated_at
- url
- virtual_size
- visibility
- vm_mode
- vmware_adaptertype
- vmware_ostype

View File

@@ -1,4 +1,10 @@
---
- name: Ensure image does not exist before tests
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
- name: Create a test image file
shell: mktemp
register: tmp_file
@@ -6,15 +12,40 @@
- name: Fill test image file to 1MB
shell: truncate -s 1048576 {{ tmp_file.stdout }}
- name: ensure mock kernel and ramdisk images (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ item }}"
filename: "{{ tmp_file.stdout }}"
disk_format: raw
loop:
- cirros-vmlinuz
- cirros-initrd
- name: Create raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
is_protected: true
disk_format: raw
tags: "{{ image_tags }}"
register: image
register: returned_image
- debug:
var: returned_image
- name: Assert changed
assert:
that: returned_image is changed
- name: Assert fields
assert:
that:
- item in returned_image.image
loop: "{{ expected_fields }}"
- name: Get details of created image
openstack.cloud.image_info:
@@ -28,11 +59,68 @@
- "image_info_result.images[0].name == image_name"
- "image_info_result.images[0].tags | sort == image_tags | sort"
- name: Create raw image again (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
is_protected: true
disk_format: raw
tags: "{{ image_tags }}"
register: returned_image
- name: Assert not changed
assert:
that: returned_image is not changed
- name: Assert fields
assert:
that:
- item in returned_image.image
loop: "{{ expected_fields }}"
- name: Update raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
is_protected: false
register: returned_image
- name: Assert changed
assert:
that:
- returned_image is changed
- returned_image.image.is_protected == false
- name: Assert changed
assert:
that:
- returned_image is changed
- name: Delete raw image (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
register: returned_image
- name: assert image changed
assert:
that: returned_image is changed
- name: Delete raw image again (defaults)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
register: returned_image
- name: assert image not changed
assert:
that: returned_image is not changed
- name: Create raw image (complex)
openstack.cloud.image:
@@ -44,12 +132,23 @@
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
register: returned_image
- name: Assert visibility
assert:
that: returned_image.image.visibility == 'public'
- name: Assert fields
assert:
that:
- item in returned_image.image
loop: "{{ expected_fields }}"
- name: Delete raw image (complex)
openstack.cloud.image:
@@ -87,7 +186,7 @@
disk_format: raw
tags: "{{ image_tags }}"
project: image_owner_project
register: image
register: returned_image
- name: Get details of created image (owner by project name)
openstack.cloud.image_info:
@@ -116,7 +215,7 @@
tags: "{{ image_tags }}"
project: image_owner_project
project_domain: default
register: image
register: returned_image
- name: Get details of created image (owner by project name and domain name)
openstack.cloud.image_info: