Refactored tests for keystone_federation_protocol{,_info} modules

Change-Id: I9665f04e6c0d5a84d6c20a73ef7b0dfdc7bd8159
This commit is contained in:
Jakob Meng
2023-01-16 12:08:00 +01:00
parent f507465c9e
commit 546f24940f
3 changed files with 175 additions and 195 deletions

View File

@@ -1,40 +1,4 @@
protocol_name: 'test-protocol'
protocol_name_2: 'test-protocol-2'
# Minimal IDP definition
idp_name: 'test-idp'
idp_remote_ids:
- 'https://auth.example.com/auth/realms/ExampleRealm'
# Minimal Domain definition
domain_name: 'test-domain'
expected_fields: expected_fields:
- id - id
- mapping_id - mapping_id
- name - name
# Minimal Mapping definition
mapping_name_1: 'ansible-test-mapping-1'
mapping_name_2: 'ansible-test-mapping-2'
mapping_rules_1:
- local:
- group:
domain:
name: example_domain
name: example-group
remote:
- type: HTTP_OIDC_GROUPS
any_one_of:
- group1
- group2
mapping_rules_2:
- local:
- group:
domain:
name: example_domain
name: example_group
remote:
- type: HTTP_OIDC_GROUPS
any_one_of:
- group1

View File

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

View File

@@ -25,9 +25,7 @@
- { role: image, tags: image } - { role: image, tags: image }
- { role: keypair, tags: keypair } - { role: keypair, tags: keypair }
- { role: keystone_idp, tags: keystone_idp } - { role: keystone_idp, tags: keystone_idp }
- role: keystone_federation_protocol - { role: keystone_federation_protocol, tags: keystone_federation_protocol }
tags: keystone_federation_protocol
when: sdk_version is version(0.44, '>=')
- { role: logging, tags: logging } - { role: logging, tags: logging }
- { role: network, tags: network } - { role: network, tags: network }
- { role: neutron_rbac_policy, tags: neutron_rbac_policy } - { role: neutron_rbac_policy, tags: neutron_rbac_policy }