mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-07-29 03:04:29 +00:00
Update identity_role_info for latest openstacksdk release
- Stop checking for to_dict, breaking compatibility with older sdk releases - Updates RETURN doc string with all the returned fields - Adds a new identity_role_info role to test the identity_role_info module. - Change the name of the module return value to remove 'openstack_' prefix Change-Id: If8a1145a31d685d41367383930e6fd08d64c6ae8
This commit is contained in:
committed by
Jakob Meng
parent
fdf4999747
commit
1d22a94a90
@@ -74,6 +74,7 @@
|
|||||||
identity_user
|
identity_user
|
||||||
identity_user_info
|
identity_user_info
|
||||||
identity_role
|
identity_role
|
||||||
|
identity_role_info
|
||||||
image
|
image
|
||||||
keypair
|
keypair
|
||||||
keystone_domain
|
keystone_domain
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
- name: Assert role found
|
- name: Assert role found
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- roles.openstack_roles | length == 1
|
- roles.roles | length == 1
|
||||||
- name: Assert role changed
|
- name: Assert role changed
|
||||||
assert:
|
assert:
|
||||||
that: role is changed
|
that: role is changed
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
that: role['role']['name'] == role_name
|
that: role['role']['name'] == role_name
|
||||||
- name: Assert retrieved values
|
- name: Assert retrieved values
|
||||||
assert:
|
assert:
|
||||||
that: roles.openstack_roles[0].name == role_name
|
that: roles.roles[0].name == role_name
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Create existing keystone role
|
- name: Create existing keystone role
|
||||||
@@ -80,4 +80,4 @@
|
|||||||
- name: Assert no role found
|
- name: Assert no role found
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- roles.openstack_roles | length == 0
|
- roles.roles | length == 0
|
||||||
|
|||||||
64
ci/roles/identity_role_info/tasks/main.yml
Normal file
64
ci/roles/identity_role_info/tasks/main.yml
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
- name: Ensure role does not exist before tests
|
||||||
|
openstack.cloud.identity_role:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: test_role
|
||||||
|
|
||||||
|
- name: Get unexistent role
|
||||||
|
openstack.cloud.identity_role_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: test_role
|
||||||
|
register: roleinfo
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: roleinfo
|
||||||
|
|
||||||
|
- name: Assert that no results were returned
|
||||||
|
assert:
|
||||||
|
that: not roleinfo.roles
|
||||||
|
|
||||||
|
- name: Create keystone role
|
||||||
|
openstack.cloud.identity_role:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: test_role
|
||||||
|
|
||||||
|
- name: Create second role
|
||||||
|
openstack.cloud.identity_role:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: test_role2
|
||||||
|
|
||||||
|
- name: Get role by name
|
||||||
|
openstack.cloud.identity_role_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: test_role
|
||||||
|
register: roleinfo
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
var: roleinfo
|
||||||
|
|
||||||
|
- name: Assert that only one result was returned
|
||||||
|
assert:
|
||||||
|
that: roleinfo.roles | length == 1
|
||||||
|
|
||||||
|
- name: Assert that roleinfo has fields
|
||||||
|
assert:
|
||||||
|
that: item in roleinfo.roles[0]
|
||||||
|
loop:
|
||||||
|
- description
|
||||||
|
- domain_id
|
||||||
|
- id
|
||||||
|
- links
|
||||||
|
- name
|
||||||
|
|
||||||
|
- name: Post-test cleanup
|
||||||
|
block:
|
||||||
|
- name: Clean up roles
|
||||||
|
openstack.cloud.identity_role:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: "{{ item }}"
|
||||||
|
loop:
|
||||||
|
- test_role
|
||||||
|
- test_role2
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
- { role: identity_user, tags: identity_user }
|
- { role: identity_user, tags: identity_user }
|
||||||
- { role: identity_user_info, tags: identity_user_info }
|
- { role: identity_user_info, tags: identity_user_info }
|
||||||
- { role: identity_role, tags: identity_role }
|
- { role: identity_role, tags: identity_role }
|
||||||
|
- { role: identity_role_info, tags: identity_role_info }
|
||||||
- { role: image, tags: image }
|
- { role: image, tags: image }
|
||||||
- { role: keypair, tags: keypair }
|
- { role: keypair, tags: keypair }
|
||||||
- { role: keystone_domain, tags: keystone_domain }
|
- { role: keystone_domain, tags: keystone_domain }
|
||||||
|
|||||||
@@ -7,19 +7,19 @@
|
|||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: identity_role_info
|
module: identity_role_info
|
||||||
short_description: Retrive information about roles
|
short_description: Retrieve information about roles
|
||||||
author: OpenStack Ansible SIG
|
author: OpenStack Ansible SIG
|
||||||
description:
|
description:
|
||||||
- Get information about identity roles in Openstack
|
- Get information about identity roles in Openstack
|
||||||
options:
|
options:
|
||||||
domain_id:
|
domain_id:
|
||||||
description:
|
description:
|
||||||
- List roles in specified domain only
|
- Domain ID which owns the role
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- List role speficied by name
|
- Name or ID of the role
|
||||||
type: str
|
type: str
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
@@ -32,26 +32,32 @@ extends_documentation_fragment:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
openstack_roles:
|
roles:
|
||||||
description: List of identity roles
|
description: List of identity roles
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
elements: dict
|
elements: dict
|
||||||
sample:
|
contains:
|
||||||
- domain_id: None
|
id:
|
||||||
id: 19bf514fdda84f808ccee8463bd85c1a
|
description: Unique ID for the role
|
||||||
location:
|
returned: success
|
||||||
cloud: mycloud
|
type: str
|
||||||
project:
|
name:
|
||||||
domain_id: None
|
description: Unique role name, within the owning domain.
|
||||||
domain_name: None
|
returned: success
|
||||||
id: None
|
type: str
|
||||||
name: None
|
description:
|
||||||
region_name: None
|
description: User-facing description of the role.
|
||||||
zone: None
|
returned: success
|
||||||
name: member
|
type: str
|
||||||
properties:
|
domain_id:
|
||||||
|
description: References the domain ID which owns the role.
|
||||||
|
returned: success
|
||||||
|
type: str
|
||||||
|
links:
|
||||||
|
description: The links for the service resources
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
@@ -75,23 +81,24 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O
|
|||||||
|
|
||||||
|
|
||||||
class IdentityRoleInfoModule(OpenStackModule):
|
class IdentityRoleInfoModule(OpenStackModule):
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
domain_id=dict(type='str', required=False),
|
domain_id=dict(type='str', required=False),
|
||||||
name=dict(type='str', required=False),
|
name=dict(type='str', required=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = dict(
|
module_kwargs = dict(
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
roles = self.conn.list_roles(domain_id=self.params['domain_id'])
|
params = {
|
||||||
# Dictionaries are supported from Train release
|
'domain_id': self.params['domain_id'],
|
||||||
roles = [item if isinstance(item, dict) else item.to_dict() for item in roles]
|
'name_or_id': self.params['name'],
|
||||||
# Filtering by name is supported from Wallaby release
|
}
|
||||||
if self.params['name']:
|
params = {k: v for k, v in params.items() if v is not None}
|
||||||
roles = [item for item in roles if self.params['name'] in (item['id'], item['name'])]
|
|
||||||
self.results.update({'openstack_roles': roles})
|
roles = [role.to_dict(computed=False) for role in self.conn.search_roles(**params)]
|
||||||
|
self.exit_json(changed=False, roles=roles)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user