From 5e9638c869225bb32608bd56d7fcd370edcfcc3a Mon Sep 17 00:00:00 2001 From: Evert Mulder Date: Fri, 25 Oct 2019 15:46:13 +0200 Subject: [PATCH] ManageIQ Ivanchuk fixes (#63948) - manageiq-group: better handling if key not present - manageiq-tenant: ivanchuk api now returns ids as strings --- .../manageiq/manageiq_group.py | 19 ++++++++----------- .../manageiq/manageiq_tenant.py | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/ansible/modules/remote_management/manageiq/manageiq_group.py b/lib/ansible/modules/remote_management/manageiq/manageiq_group.py index abd616b3406..166f3421a13 100644 --- a/lib/ansible/modules/remote_management/manageiq/manageiq_group.py +++ b/lib/ansible/modules/remote_management/manageiq/manageiq_group.py @@ -411,11 +411,7 @@ class ManageIQgroup(object): filters_updated = False new_filters_resource = {} - # Process belongsto filters - if 'belongsto' in current_filters: - current_belongsto_set = set(current_filters['belongsto']) - else: - current_belongsto_set = set() + current_belongsto_set = current_filters.get('belongsto', set()) if belongsto_filters: new_belongsto_set = set(belongsto_filters) @@ -501,11 +497,12 @@ class ManageIQgroup(object): @staticmethod def manageiq_filters_to_sorted_dict(current_filters): - if 'managed' not in current_filters: + current_managed_filters = current_filters.get('managed') + if not current_managed_filters: return None res = {} - for tag_list in current_filters['managed']: + for tag_list in current_managed_filters: tag_list.sort() key = tag_list[0].split('/')[2] res[key] = tag_list @@ -547,11 +544,11 @@ class ManageIQgroup(object): belongsto_filters = None if 'filters' in group['entitlement']: filters = group['entitlement']['filters'] - if 'belongsto' in filters: - belongsto_filters = filters['belongsto'] - if 'managed' in filters: + belongsto_filters = filters.get('belongsto') + group_managed_filters = filters.get('managed') + if group_managed_filters: managed_filters = {} - for tag_list in filters['managed']: + for tag_list in group_managed_filters: key = tag_list[0].split('/')[2] tags = [] for t in tag_list: diff --git a/lib/ansible/modules/remote_management/manageiq/manageiq_tenant.py b/lib/ansible/modules/remote_management/manageiq/manageiq_tenant.py index 0b0e4b16d6d..4cf1bee7335 100644 --- a/lib/ansible/modules/remote_management/manageiq/manageiq_tenant.py +++ b/lib/ansible/modules/remote_management/manageiq/manageiq_tenant.py @@ -221,7 +221,7 @@ class ManageIQTenant(object): self.module.fail_json(msg="Multiple parent tenants not found in manageiq with name '%s" % parent) parent_tenant = parent_tenant_res[0] - parent_id = parent_tenant['id'] + parent_id = int(parent_tenant['id']) tenants = self.client.collections.tenants.find_by(name=name) for tenant in tenants: @@ -448,7 +448,7 @@ class ManageIQTenant(object): try: ancestry = tenant['ancestry'] - tenant_parent_id = int(ancestry.split("/")[-1]) + tenant_parent_id = ancestry.split("/")[-1] except AttributeError: # The root tenant does not return the ancestry attribute tenant_parent_id = None