Files
ansible-collections-openstack/ci/roles/image/tasks/main.yml
Rafael Castillo 2419b5ab19 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
2022-06-28 10:55:34 -07:00

248 lines
5.8 KiB
YAML

---
- 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
- 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: 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:
cloud: "{{ cloud }}"
image: "{{ image_name }}"
register: image_info_result
- name: Verify image info
assert:
that:
- "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:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
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: 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:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
- name: Try to get details of deleted image
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: "{{ image_name }}"
register: deleted_image_info_result
- name: Verify image is deleted
assert:
that:
- not deleted_image_info_result.images
- name: Create owner project
openstack.cloud.project:
cloud: "{{ cloud }}"
state: present
name: image_owner_project
description: Project owning test image
domain_id: default
enabled: True
register: owner_project
- name: Create raw image (owner by project name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
disk_format: raw
tags: "{{ image_tags }}"
project: image_owner_project
register: returned_image
- name: Get details of created image (owner by project name)
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: "{{ image_name }}"
register: image_info_result
- name: Verify image owner (owner by project name)
assert:
that:
- image_info_result.images[0].owner == owner_project.project.id
- name: Delete raw image (owner by project name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
- name: Create raw image (owner by project name and domain name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: present
name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}"
disk_format: raw
tags: "{{ image_tags }}"
project: image_owner_project
project_domain: default
register: returned_image
- name: Get details of created image (owner by project name and domain name)
openstack.cloud.image_info:
cloud: "{{ cloud }}"
image: "{{ image_name }}"
register: image_info_result
- name: Verify image owner (owner by project name and domain name)
assert:
that:
- image_info_result.images[0].owner == owner_project.project.id
- name: Delete raw image (owner by project name and domain name)
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
- name: Delete owner project
openstack.cloud.project:
cloud: "{{ cloud }}"
state: absent
name: image_owner_project
domain_id: default
- name: Delete test image file
file:
name: "{{ tmp_file.stdout }}"
state: absent