[cloud] Follow up on FIXMEs in ec2_ami & ec2_ami tests (#32337)

* Several tests were marked as FIXME and should have been fixed with
the boto3 move.

* Improved tags output. Add purge_tags option (default: no)

* Allow description and tags update

* Return launch_permissions

* Allow empty launch permissions for image creation

* Empty launch permissions should work the same way for image
creation as no launch permissions

* Cope with ephemeral devices in AMI block device mapping

* Ephemeral devices can appear in AMI block devices, and this information should be returned

* Fix notation for creating sets from comprehensions
This commit is contained in:
Will Thames 2017-10-30 17:45:11 +10:00 committed by Ryan S. Brown
parent 1eae3b6b59
commit 60b29cf57d
2 changed files with 223 additions and 192 deletions

View file

@ -101,7 +101,6 @@
Name: '{{ ec2_ami_name }}_ami'
wait: yes
root_device_name: /dev/xvda
ignore_errors: true
register: result
- name: assert that image has been created
@ -109,8 +108,7 @@
that:
- "result.changed"
- "result.image_id.startswith('ami-')"
# FIXME: tags are not currently shown in the results
#- "result.tags == '{Name: {{ ec2_ami_name }}_ami}'"
- "'Name' in result.tags and result.tags.Name == ec2_ami_name + '_ami'"
- name: set image id fact for deletion later
set_fact:
@ -188,6 +186,8 @@
name: '{{ ec2_ami_name }}_ami'
description: '{{ ec2_ami_description }}'
state: present
launch_permissions:
user_ids: []
tags:
Name: '{{ ec2_ami_name }}_ami'
root_device_name: /dev/xvda
@ -213,39 +213,37 @@
# ============================================================
# FIXME: this only works if launch permissions are specified and if they are not an empty list
# - name: test idempotence
# ec2_ami:
# ec2_region: '{{ec2_region}}'
# ec2_access_key: '{{ec2_access_key}}'
# ec2_secret_key: '{{ec2_secret_key}}'
# security_token: '{{security_token}}'
# description: '{{ ec2_ami_description }}'
# state: present
# tags:
# Name: '{{ ec2_ami_name }}_ami'
# root_device_name: /dev/xvda
# image_id: '{{ result.image_id }}'
# launch_permissions:
# user_ids:
# -
# device_mapping:
# - device_name: /dev/xvda
# volume_type: gp2
# size: 8
# delete_on_termination: true
# snapshot_id: '{{ setup_snapshot.snapshot_id }}'
# register: result
- name: test default launch permissions idempotence
ec2_ami:
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
description: '{{ ec2_ami_description }}'
state: present
name: '{{ ec2_ami_name }}_ami'
tags:
Name: '{{ ec2_ami_name }}_ami'
root_device_name: /dev/xvda
image_id: '{{ result.image_id }}'
launch_permissions:
user_ids: []
device_mapping:
- device_name: /dev/xvda
volume_type: gp2
size: 8
delete_on_termination: true
snapshot_id: '{{ setup_snapshot.snapshot_id }}'
register: result
# - name: assert a new ami has been created
# assert:
# that:
# - "not result.changed"
# - "result.image_id.startswith('ami-')"
- name: assert a new ami has not been created
assert:
that:
- "not result.changed"
- "result.image_id.startswith('ami-')"
# ============================================================
# FIXME: tags are not currently shown in the results
- name: add a tag to the AMI
ec2_ami:
ec2_region: '{{ec2_region}}'
@ -258,14 +256,34 @@
name: '{{ ec2_ami_name }}_ami'
tags:
New: Tag
launch_permissions:
group_names: ['all']
register: result
#
# - name: assert a tag was added
# assert:
# that:
# - "result.tags == '{Name: {{ ec2_ami_name }}_ami}, New: Tag'"
- name: assert a tag was added
assert:
that:
- "'Name' in result.tags and result.tags.Name == ec2_ami_name + '_ami'"
- "'New' in result.tags and result.tags.New == 'Tag'"
- name: use purge_tags to remove a tag from the AMI
ec2_ami:
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
state: present
description: '{{ ec2_ami_description }}'
image_id: '{{ result.image_id }}'
name: '{{ ec2_ami_name }}_ami'
tags:
New: Tag
purge_tags: yes
register: result
- name: assert a tag was removed
assert:
that:
- "'Name' not in result.tags"
- "'New' in result.tags and result.tags.New == 'Tag'"
# ============================================================
@ -315,29 +333,25 @@
# ============================================================
# FIXME: currently the module doesn't remove launch permissions correctly
# - name: remove public launch permissions
# ec2_ami:
# ec2_region: '{{ec2_region}}'
# ec2_access_key: '{{ec2_access_key}}'
# ec2_secret_key: '{{ec2_secret_key}}'
# security_token: '{{security_token}}'
# state: present
# image_id: '{{ result.image_id }}'
# name: '{{ ec2_ami_name }}_ami'
# tags:
# Name: '{{ ec2_ami_name }}_ami'
# launch_permissions:
# group_names:
# -
#
# register: result
# ignore_errors: true
#
# - name: assert launch permissions were updated
# assert:
# that:
# - "result.changed"
- name: remove public launch permissions
ec2_ami:
ec2_region: '{{ec2_region}}'
ec2_access_key: '{{ec2_access_key}}'
ec2_secret_key: '{{ec2_secret_key}}'
security_token: '{{security_token}}'
state: present
image_id: '{{ result.image_id }}'
name: '{{ ec2_ami_name }}_ami'
tags:
Name: '{{ ec2_ami_name }}_ami'
launch_permissions:
group_names: []
register: result
- name: assert launch permissions were updated
assert:
that:
- "result.changed"
# ============================================================
@ -391,16 +405,13 @@
tags:
Name: '{{ ec2_ami_name }}_ami'
wait: yes
ignore_errors: true
register: result
# FIXME: currently deleting an already deleted image fails
# It should succeed, with changed: false
# - name: assert that image does not exist
# assert:
# that:
# - not result.changed
# - not result.failed
- name: assert that image does not exist
assert:
that:
- not result.changed
- not result.failed
# ============================================================