diff --git a/.zuul.yaml b/.zuul.yaml index 54613032..737b314a 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -95,6 +95,7 @@ object_container port project + project_info recordset role_assignment security_group diff --git a/ci/roles/project_info/tasks/main.yml b/ci/roles/project_info/tasks/main.yml new file mode 100644 index 00000000..3c5c1d78 --- /dev/null +++ b/ci/roles/project_info/tasks/main.yml @@ -0,0 +1,46 @@ +--- +- name: List admin project + openstack.cloud.project_info: + cloud: "{{ cloud }}" + name: 'admin' + register: project_admin + +- name: List admin project with filter + openstack.cloud.project_info: + cloud: "{{ cloud }}" + filters: + name: 'admin' + +- name: Check output of list admin project + assert: + that: + - project_admin.openstack_projects | length == 1 + +- name: List all projects + openstack.cloud.project_info: + cloud: "{{ cloud }}" + register: all_projects + +- name: Check output of list all projects + assert: + that: + - all_projects.openstack_projects | length > 0 + +- name: List admin project with domain + openstack.cloud.project_info: + cloud: "{{ cloud }}" + name: 'admin' + domain: 'default' + register: project_domain + +- name: Check output of list admin project with admin domain + assert: + that: + - project_domain.openstack_projects | length == 1 + +- name: Assert fields on SDK 1.* + assert: + that: + - '["description", "domain_id", "is_domain", "is_enabled", "options", + "parent_id", "id", "name", "tags"] | + difference(project_admin.openstack_projects.0.keys()) | length == 0' diff --git a/ci/run-collection.yml b/ci/run-collection.yml index 2e26349c..be4337e8 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -52,6 +52,7 @@ - { role: object, tags: object } - { role: port, tags: port } - { role: project, tags: project } + - { role: project_info, tags: project_info } - { role: recordset, tags: recordset } - { role: role_assignment, tags: role_assignment } - { role: router, tags: router } diff --git a/plugins/modules/project_info.py b/plugins/modules/project_info.py index fb1e2767..0a0c357c 100644 --- a/plugins/modules/project_info.py +++ b/plugins/modules/project_info.py @@ -22,8 +22,9 @@ options: type: str filters: description: - - A dictionary of meta data to use for further filtering. Elements of - this dictionary may be additional dictionaries. + - A dictionary of meta data to use for filtering projects. Elements of + this dictionary are parsed as queries for openstack identity api in + the new openstacksdk. type: dict requirements: - "python >= 3.6" @@ -64,7 +65,7 @@ EXAMPLES = ''' name: demoproject domain: admindomain filters: - enabled: False + is_enabled: False register: result - debug: msg: "{{ result.openstack_projects }}" @@ -74,8 +75,9 @@ EXAMPLES = ''' RETURN = ''' openstack_projects: description: has all the OpenStack information about projects - returned: always, but can be null - type: complex + elements: dict + returned: always, but can be empty + type: list contains: id: description: Unique UUID. @@ -89,7 +91,7 @@ openstack_projects: description: Description of the project returned: success type: str - enabled: + is_enabled: description: Flag to indicate if the project is enabled returned: success type: bool @@ -97,6 +99,22 @@ openstack_projects: description: Domain ID containing the project (keystone v3 clouds only) returned: success type: bool + tags: + description: A list of simple strings assigned to a project + returned: success + type: list + parent_id: + description: The ID of the parent for the project + returned: success + type: str + is_domain: + description: Indicates whether the project also acts as a domain. + returned: success + type: bool + options: + description: Set of options for the project + returned: success + type: dict ''' from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule @@ -117,34 +135,16 @@ class IdentityProjectInfoModule(OpenStackModule): def run(self): name = self.params['name'] domain = self.params['domain'] - filters = self.params['filters'] - is_old_facts = self.module_name == 'openstack.cloud.project_facts' + filters = self.params['filters'] or {} if domain: - try: - # We assume admin is passing domain id - dom = self.conn.get_domain(domain)['id'] - domain = dom - except Exception: - # If we fail, maybe admin is passing a domain name. - # Note that domains have unique names, just like id. - dom = self.conn.search_domains(filters={'name': domain}) - if dom: - domain = dom[0]['id'] - else: - self.fail_json(msg='Domain name or ID does not exist') + filters['domain_id'] = self.conn.identity.find_domain( + domain, ignore_missing=False).id - if not filters: - filters = {} + projects = self.conn.search_projects(name, filters=filters) + projects = [p.to_dict(computed=False) for p in projects] - filters['domain_id'] = domain - - projects = self.conn.search_projects(name, filters) - if is_old_facts: - self.exit_json(changed=False, ansible_facts=dict( - openstack_projects=projects)) - else: - self.exit_json(changed=False, openstack_projects=projects) + self.exit_json(changed=False, openstack_projects=projects) def main():