Files
ansible-collections-openstack/ci/roles/keystone_federation_protocol/tasks/main.yml
Jakob Meng 114bc855c0 Refactored keystone_federation_protocol{,_info} modules
Change-Id: I6f9eef184538df4feff49dd6ed659a9b9ac1289f
2022-11-10 19:39:51 +01:00

324 lines
10 KiB
YAML

---
# General run of tests
# - Make change - Check mode
# - Make change
# - Retry change (noop) - Check mode
# - Retry change (noop)
#
- module_defaults:
group/openstack.cloud.openstack:
cloud: "{{ cloud }}"
openstack.cloud.keystone_federation_protocol:
cloud: "{{ cloud }}" # Backward compatibility with Ansible 2.9
idp_id: "{{ idp_name }}"
openstack.cloud.keystone_federation_protocol_info:
cloud: "{{ cloud }}" # Backward compatibility with Ansible 2.9
idp_id: "{{ idp_name }}"
# Backward compatibility with Ansible 2.9
openstack.cloud.identity_domain:
cloud: "{{ cloud }}"
openstack.cloud.federation_idp:
cloud: "{{ cloud }}"
openstack.cloud.federation_mapping:
cloud: "{{ cloud }}"
block:
# ========================================================================
# Initial setup
- name: 'Create test Domain'
openstack.cloud.identity_domain:
name: '{{ domain_name }}'
register: create_domain
- name: 'Create test Identity Provider'
openstack.cloud.federation_idp:
state: 'present'
name: '{{ idp_name }}'
domain_id: '{{ create_domain.id }}'
- name: 'Create test mapping (1)'
openstack.cloud.federation_mapping:
state: 'present'
name: '{{ mapping_name_1 }}'
rules: '{{ mapping_rules_1 }}'
- name: 'Create test mapping (2)'
openstack.cloud.federation_mapping:
state: 'present'
name: '{{ mapping_name_2 }}'
rules: '{{ mapping_rules_2 }}'
# We *should* have a blank slate to start with, but we also shouldn't
# explode if I(state=absent) and the IDP doesn't exist
- name: "Ensure Protocol doesn't exist to start"
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
# ========================================================================
# Creation
- name: 'Create protocol - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_1 }}'
register: create_protocol
- assert:
that:
- create_protocol is changed
- name: 'Fetch Protocol info (should be absent)'
openstack.cloud.keystone_federation_protocol_info:
name: '{{ protocol_name }}'
register: protocol_info
- assert:
that:
- protocol_info.protocols | length == 0
- name: 'Create protocol'
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_1 }}'
register: create_protocol
- assert:
that:
- create_protocol is changed
- create_protocol.protocol.id == protocol_name
- create_protocol.protocol.name == protocol_name
- create_protocol.protocol.mapping_id == mapping_name_1
- name: assert return values of keystone_federation_protocol module
assert:
that:
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(create_protocol.protocol.keys())|length == 0
- name: 'Create protocol (retry - no change) - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_1 }}'
register: create_protocol
- assert:
that:
- create_protocol is not changed
- name: 'Create protocol (retry - no change)'
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_1 }}'
register: create_protocol
- assert:
that:
- create_protocol is not changed
- create_protocol.protocol.id == protocol_name
- create_protocol.protocol.name == protocol_name
- create_protocol.protocol.mapping_id == mapping_name_1
# ========================================================================
# Update
- name: 'Update protocol - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_2 }}'
register: update_protocol
- assert:
that:
- update_protocol is changed
- name: 'Update protocol'
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_2 }}'
register: update_protocol
- assert:
that:
- update_protocol is changed
- update_protocol.protocol.id == protocol_name
- update_protocol.protocol.name == protocol_name
- update_protocol.protocol.mapping_id == mapping_name_2
- name: 'Update protocol (retry - no change) - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_2 }}'
register: update_protocol
- assert:
that:
- update_protocol is not changed
- name: 'Update protocol (retry - no change)'
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name }}'
mapping_id: '{{ mapping_name_2 }}'
register: update_protocol
- assert:
that:
- update_protocol is not changed
- update_protocol.protocol.id == protocol_name
- update_protocol.protocol.name == protocol_name
- update_protocol.protocol.mapping_id == mapping_name_2
# ========================================================================
# Create second protocol to test openstack.cloud.keystone_federation_protocol_info
- name: 'Create protocol (2)'
openstack.cloud.keystone_federation_protocol:
state: 'present'
name: '{{ protocol_name_2 }}'
mapping_id: '{{ mapping_name_1 }}'
register: create_protocol_2
- assert:
that:
- create_protocol_2 is changed
- create_protocol_2.protocol.id == protocol_name_2
- create_protocol_2.protocol.name == protocol_name_2
- create_protocol_2.protocol.mapping_id == mapping_name_1
# ========================================================================
# Basic tests of openstack.cloud.keystone_federation_protocol_info
- name: 'Fetch Protocol info (a specific protocol)'
openstack.cloud.keystone_federation_protocol_info:
name: '{{ protocol_name }}'
register: protocol_info
- name: Check info about protocols
assert:
that:
- protocol_info.protocols|length > 0
# allow new fields to be introduced but prevent fields from being removed
- expected_fields|difference(protocol_info.protocols[0].keys())|length == 0
- assert:
that:
- protocol_info.protocols[0].id == protocol_name
- protocol_info.protocols[0].name == protocol_name
- protocol_info.protocols[0].mapping_id == mapping_name_2
- name: 'Fetch Protocol info (all protocols on our test IDP)'
openstack.cloud.keystone_federation_protocol_info: {}
# idp_id defined in defaults at the start
register: protocol_info
- assert:
that:
# We created the IDP, and we're going to delete it:
# we should be able to trust what's attached to it
- protocol_info.protocols | length == 2
- protocol_name in (protocol_info.protocols | map(attribute='id'))
- protocol_name in (protocol_info.protocols | map(attribute='id'))
- protocol_name_2 in (protocol_info.protocols | map(attribute='name'))
- protocol_name_2 in (protocol_info.protocols | map(attribute='name'))
- mapping_name_1 in (protocol_info.protocols | map(attribute='mapping_id'))
- mapping_name_2 in (protocol_info.protocols | map(attribute='mapping_id'))
vars:
protocol_1: '{{ protocol_info.protocols[0] }}'
protocol_2: '{{ protocol_info.protocols[1] }}'
# ========================================================================
# Deletion
- name: 'Delete protocol - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
register: update_protocol
- assert:
that:
- update_protocol is changed
- name: 'Delete protocol'
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
register: update_protocol
- assert:
that:
- update_protocol is changed
- name: 'Delete protocol (retry - no change) - CHECK MODE'
check_mode: yes
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
register: update_protocol
- assert:
that:
- update_protocol is not changed
- name: 'Delete protocol (retry - no change)'
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
register: update_protocol
- assert:
that:
- update_protocol is not changed
# ========================================================================
# Clean up after ourselves
always:
- name: 'Delete protocol'
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name }}'
idp_id: '{{ idp_name }}'
ignore_errors: yes
- name: 'Delete protocol (2)'
openstack.cloud.keystone_federation_protocol:
state: 'absent'
name: '{{ protocol_name_2 }}'
idp_id: '{{ idp_name }}'
ignore_errors: yes
- name: 'Delete mapping 1'
openstack.cloud.federation_mapping:
state: 'absent'
name: '{{ mapping_name_1 }}'
ignore_errors: yes
- name: 'Delete mapping 2'
openstack.cloud.federation_mapping:
state: 'absent'
name: '{{ mapping_name_2 }}'
ignore_errors: yes
- name: 'Delete idp'
openstack.cloud.federation_idp:
state: 'absent'
name: '{{ idp_name }}'
ignore_errors: yes
- name: 'Delete domain'
openstack.cloud.identity_domain:
state: 'absent'
name: '{{ domain_name }}'
ignore_errors: yes