Always remove temporary files in volume's integration test

This will ensure proper cleanup when tests fail.

Change-Id: Ia5758ffeab43d92f670d3e159fe4f3747491ec94
This commit is contained in:
Jakob Meng 2022-10-26 20:07:02 +02:00
parent 4e1718db49
commit 2f87448567
2 changed files with 63 additions and 50 deletions

View File

@ -2,4 +2,7 @@
collections: collections:
- ansible.posix - ansible.posix
- ansible.utils - ansible.utils
- community.general - name: community.general
version: 4.8.8
# 5.0.0 dropped compatibility with ansible 2.9 and ansible-base 2.10
# Ref.: https://github.com/ansible-collections/community.general/commit/1a9b3214fdf1eaccba5cc9ee210cbc5b5070fe4b

View File

@ -97,60 +97,70 @@
- ansible_volume1 - ansible_volume1
- ansible_volume2 - ansible_volume2
- name: Create a test image file - name: Test images
shell: mktemp block:
register: tmp_file - name: Ensure clean environment
ansible.builtin.set_fact:
tmp_file: !!null
- name: Fill test image file to 1MB - name: Create a test image file
shell: truncate -s 1048576 {{ tmp_file.stdout }} ansible.builtin.tempfile:
register: tmp_file
- name: Create test image - name: Fill test image file to 1MB
openstack.cloud.image: community.general.filesize:
cloud: "{{ cloud }}" path: '{{ tmp_file.path }}'
state: present size: 1M
name: "{{ test_volume_image }}"
filename: "{{ tmp_file.stdout }}"
disk_format: raw
tags: "{{ image_tags }}"
register: returned_image
- name: Create volume from image - name: Create test image
openstack.cloud.volume: openstack.cloud.image:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
state: present state: present
size: 1 name: "{{ test_volume_image }}"
image: "{{ test_volume_image }}" filename: "{{ tmp_file.path }}"
name: ansible_volume2 disk_format: raw
description: Test volume tags: "{{ image_tags }}"
register: vol
- name: Delete volume from image - name: Create volume from image
openstack.cloud.volume: openstack.cloud.volume:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
name: ansible_volume2 state: present
state: absent size: 1
register: vol image: "{{ test_volume_image }}"
name: ansible_volume2
description: Test volume
- name: Create test shared image - name: Delete volume from image
openstack.cloud.image: openstack.cloud.volume:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
state: present name: ansible_volume2
name: "{{ image_name }}" state: absent
filename: "{{ tmp_file.stdout }}"
is_public: true
disk_format: raw
tags: "{{ image_tags }}"
register: returned_image
- name: Delete test shared image - name: Create test shared image
openstack.cloud.image: openstack.cloud.image:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
state: absent state: present
name: "{{ image_name }}" name: "{{ image_name }}"
filename: "{{ tmp_file.stdout }}" filename: "{{ tmp_file.path }}"
is_public: true is_public: true
disk_format: raw disk_format: raw
tags: "{{ image_tags }}" tags: "{{ image_tags }}"
register: returned_image
- name: Delete test shared image
openstack.cloud.image:
cloud: "{{ cloud }}"
state: absent
name: "{{ image_name }}"
filename: "{{ tmp_file.path }}"
is_public: true
disk_format: raw
tags: "{{ image_tags }}"
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
- include_tasks: volume_info.yml - include_tasks: volume_info.yml