mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 22:34:12 +00:00
Merge "Update federation_mapping_info module to be compatible with new sdk"
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
expected_fields:
|
||||||
|
- id
|
||||||
|
- name
|
||||||
|
- rules
|
||||||
mapping_name: 'ansible-test-mapping'
|
mapping_name: 'ansible-test-mapping'
|
||||||
mapping_name_2: 'ansible-test-mapping-2'
|
mapping_name_2: 'ansible-test-mapping-2'
|
||||||
mapping_rules_1:
|
mapping_rules_1:
|
||||||
|
|||||||
@@ -33,10 +33,9 @@
|
|||||||
openstack.cloud.federation_mapping_info:
|
openstack.cloud.federation_mapping_info:
|
||||||
name: '{{ mapping_name }}'
|
name: '{{ mapping_name }}'
|
||||||
register: mapping_info
|
register: mapping_info
|
||||||
ignore_errors: yes
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- mapping_info is failed
|
- mapping_info.mappings | length == 0
|
||||||
|
|
||||||
- name: 'Create mapping'
|
- name: 'Create mapping'
|
||||||
openstack.cloud.federation_mapping:
|
openstack.cloud.federation_mapping:
|
||||||
@@ -64,15 +63,17 @@
|
|||||||
- mapping_info is successful
|
- mapping_info is successful
|
||||||
- '"mappings" in mapping_info'
|
- '"mappings" in mapping_info'
|
||||||
- mapping_info.mappings | length == 1
|
- mapping_info.mappings | length == 1
|
||||||
- '"id" in mapping_0'
|
|
||||||
- '"name" in mapping_0'
|
|
||||||
- '"rules" in mapping_0'
|
|
||||||
- mapping_0.id == mapping_name
|
- mapping_0.id == mapping_name
|
||||||
- mapping_0.name == mapping_name
|
- mapping_0.name == mapping_name
|
||||||
- mapping_0.rules | length == 1
|
- mapping_0.rules | length == 1
|
||||||
vars:
|
vars:
|
||||||
mapping_0: '{{ mapping_info.mappings[0] }}'
|
mapping_0: '{{ mapping_info.mappings[0] }}'
|
||||||
|
|
||||||
|
- name: Verify returned values
|
||||||
|
assert:
|
||||||
|
that: item in mapping_info.mappings[0]
|
||||||
|
loop: "{{ expected_fields }}"
|
||||||
|
|
||||||
- name: 'Fetch mapping info - without name'
|
- name: 'Fetch mapping info - without name'
|
||||||
openstack.cloud.federation_mapping_info: {}
|
openstack.cloud.federation_mapping_info: {}
|
||||||
register: mapping_info
|
register: mapping_info
|
||||||
@@ -83,13 +84,8 @@
|
|||||||
# In CI we generally have a clean slate, but this might
|
# In CI we generally have a clean slate, but this might
|
||||||
# not be true for everyone...
|
# not be true for everyone...
|
||||||
- mapping_info.mappings | length >= 1
|
- mapping_info.mappings | length >= 1
|
||||||
- '"id" in mapping_0'
|
|
||||||
- '"name" in mapping_0'
|
|
||||||
- '"rules" in mapping_0'
|
|
||||||
- mapping_name in (mapping_info.mappings | map(attribute='id'))
|
- mapping_name in (mapping_info.mappings | map(attribute='id'))
|
||||||
- mapping_name in (mapping_info.mappings | map(attribute='name'))
|
- mapping_name in (mapping_info.mappings | map(attribute='name'))
|
||||||
vars:
|
|
||||||
mapping_0: '{{ mapping_info.mappings[0] }}'
|
|
||||||
|
|
||||||
- name: 'Create mapping (retry - no change) - CHECK_MODE'
|
- name: 'Create mapping (retry - no change) - CHECK_MODE'
|
||||||
openstack.cloud.federation_mapping:
|
openstack.cloud.federation_mapping:
|
||||||
@@ -113,9 +109,6 @@
|
|||||||
that:
|
that:
|
||||||
- create_mapping is successful
|
- create_mapping is successful
|
||||||
- create_mapping is not changed
|
- create_mapping is not changed
|
||||||
- '"id" in create_mapping.mapping'
|
|
||||||
- '"name" in create_mapping.mapping'
|
|
||||||
- '"rules" in create_mapping.mapping'
|
|
||||||
- create_mapping.mapping.id == mapping_name
|
- create_mapping.mapping.id == mapping_name
|
||||||
- create_mapping.mapping.name == mapping_name
|
- create_mapping.mapping.name == mapping_name
|
||||||
- create_mapping.mapping.rules | length == 1
|
- create_mapping.mapping.rules | length == 1
|
||||||
@@ -192,9 +185,6 @@
|
|||||||
- mapping_info is successful
|
- mapping_info is successful
|
||||||
- '"mappings" in mapping_info'
|
- '"mappings" in mapping_info'
|
||||||
- mapping_info.mappings | length == 1
|
- mapping_info.mappings | length == 1
|
||||||
- '"id" in mapping_0'
|
|
||||||
- '"name" in mapping_0'
|
|
||||||
- '"rules" in mapping_0'
|
|
||||||
- mapping_0.id == mapping_name_2
|
- mapping_0.id == mapping_name_2
|
||||||
- mapping_0.name == mapping_name_2
|
- mapping_0.name == mapping_name_2
|
||||||
- mapping_0.rules | length == 1
|
- mapping_0.rules | length == 1
|
||||||
@@ -211,19 +201,10 @@
|
|||||||
# In CI we generally have a clean slate, but this might
|
# In CI we generally have a clean slate, but this might
|
||||||
# not be true for everyone...
|
# not be true for everyone...
|
||||||
- mapping_info.mappings | length >= 2
|
- mapping_info.mappings | length >= 2
|
||||||
- '"id" in mapping_0'
|
|
||||||
- '"name" in mapping_0'
|
|
||||||
- '"rules" in mapping_0'
|
|
||||||
- '"id" in mapping_1'
|
|
||||||
- '"name" in mapping_1'
|
|
||||||
- '"rules" in mapping_1'
|
|
||||||
- mapping_name in (mapping_info.mappings | map(attribute='id'))
|
- mapping_name in (mapping_info.mappings | map(attribute='id'))
|
||||||
- mapping_name in (mapping_info.mappings | map(attribute='name'))
|
- mapping_name in (mapping_info.mappings | map(attribute='name'))
|
||||||
- mapping_name_2 in (mapping_info.mappings | map(attribute='id'))
|
- mapping_name_2 in (mapping_info.mappings | map(attribute='id'))
|
||||||
- mapping_name_2 in (mapping_info.mappings | map(attribute='name'))
|
- mapping_name_2 in (mapping_info.mappings | map(attribute='name'))
|
||||||
vars:
|
|
||||||
mapping_0: '{{ mapping_info.mappings[0] }}'
|
|
||||||
mapping_1: '{{ mapping_info.mappings[1] }}'
|
|
||||||
|
|
||||||
- name: 'Delete mapping - CHECK_MODE'
|
- name: 'Delete mapping - CHECK_MODE'
|
||||||
openstack.cloud.federation_mapping:
|
openstack.cloud.federation_mapping:
|
||||||
@@ -271,10 +252,9 @@
|
|||||||
openstack.cloud.federation_mapping_info:
|
openstack.cloud.federation_mapping_info:
|
||||||
name: '{{ mapping_name }}'
|
name: '{{ mapping_name }}'
|
||||||
register: mapping_info
|
register: mapping_info
|
||||||
ignore_errors: True
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- mapping_info is failed
|
- mapping_info.mappings | length == 0
|
||||||
|
|
||||||
- name: 'Delete second mapping'
|
- name: 'Delete second mapping'
|
||||||
openstack.cloud.federation_mapping:
|
openstack.cloud.federation_mapping:
|
||||||
|
|||||||
@@ -10,18 +10,16 @@ module: federation_mapping_info
|
|||||||
short_description: Get the information about the available federation mappings
|
short_description: Get the information about the available federation mappings
|
||||||
author: OpenStack Ansible SIG
|
author: OpenStack Ansible SIG
|
||||||
description:
|
description:
|
||||||
- Fetch a federation mapping.
|
- Fetch federation mappings.
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- The name of the mapping to fetch.
|
- The name of the mapping to fetch.
|
||||||
- If I(name) is specified, the module will return failed if the mapping
|
|
||||||
doesn't exist.
|
|
||||||
type: str
|
type: str
|
||||||
aliases: ['id']
|
aliases: ['id']
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk >= 0.44"
|
- "openstacksdk"
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- openstack.cloud.openstack
|
- openstack.cloud.openstack
|
||||||
'''
|
'''
|
||||||
@@ -38,6 +36,27 @@ EXAMPLES = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
mappings:
|
||||||
|
description:
|
||||||
|
- List of federation mappings
|
||||||
|
type: list
|
||||||
|
elements: dict
|
||||||
|
returned: always
|
||||||
|
contains:
|
||||||
|
id:
|
||||||
|
description:
|
||||||
|
- The id of the mapping
|
||||||
|
type: str
|
||||||
|
sample: "ansible-test-mapping"
|
||||||
|
name:
|
||||||
|
description:
|
||||||
|
- The name of the mapping
|
||||||
|
type: str
|
||||||
|
sample: "ansible-test-mapping"
|
||||||
|
rules:
|
||||||
|
description:
|
||||||
|
- List of rules for the mapping
|
||||||
|
type: list
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
@@ -47,38 +66,29 @@ class IdentityFederationMappingInfoModule(OpenStackModule):
|
|||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name=dict(aliases=['id']),
|
name=dict(aliases=['id']),
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = dict(
|
module_kwargs = dict(
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
module_min_sdk_version = "0.44"
|
|
||||||
|
|
||||||
def normalize_mapping(self, mapping):
|
|
||||||
"""
|
|
||||||
Normalizes the mapping definitions so that the outputs are consistent with the
|
|
||||||
parameters
|
|
||||||
|
|
||||||
- "name" (parameter) == "id" (SDK)
|
|
||||||
"""
|
|
||||||
if mapping is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
_mapping = mapping.to_dict()
|
|
||||||
_mapping['name'] = mapping['id']
|
|
||||||
return _mapping
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Module entry point """
|
# name is defined as id for mappings
|
||||||
name = self.params.get('name')
|
id = self.params['name']
|
||||||
|
|
||||||
if name:
|
if id:
|
||||||
mapping = self.normalize_mapping(
|
# handle id parameter separately because self.conn.identity.\
|
||||||
self.conn.identity.get_mapping(name))
|
# mappings() does not allow to filter by id
|
||||||
self.exit_json(changed=False, mappings=[mapping])
|
# Ref.: https://review.opendev.org/c/openstack/
|
||||||
|
# openstacksdk/+/858522
|
||||||
|
mapping = self.conn.identity.find_mapping(name_or_id=id,
|
||||||
|
ignore_missing=True)
|
||||||
|
mappings = [mapping] if mapping else []
|
||||||
else:
|
else:
|
||||||
mappings = list(map(
|
mappings = self.conn.identity.mappings()
|
||||||
self.normalize_mapping, self.conn.identity.mappings()))
|
|
||||||
self.exit_json(changed=False, mappings=mappings)
|
self.exit_json(changed=False,
|
||||||
|
mappings=[mapping.to_dict(computed=False)
|
||||||
|
for mapping in mappings])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user