From 34de6c3b00023c1a725ffcf34a6dd87e84f45a91 Mon Sep 17 00:00:00 2001 From: Marek Aufart Date: Mon, 29 Jan 2018 15:25:47 +0100 Subject: [PATCH] Fix CloudTenant Vm targeted refresh Vm tagreted refresh queued related Cloud Tenant refresh, that could fail due to keystone v3 backend in fog or an issue in fog/openstack method get_project_by_id. Adding custom method to get_project derived from list_project. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1538741 --- .../openstack/inventory/collector/target_collection.rb | 4 ++-- .../openstack/legacy/openstack_handle/identity_delegate.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/manageiq/providers/openstack/inventory/collector/target_collection.rb b/app/models/manageiq/providers/openstack/inventory/collector/target_collection.rb index d71239425..9ea606da8 100644 --- a/app/models/manageiq/providers/openstack/inventory/collector/target_collection.rb +++ b/app/models/manageiq/providers/openstack/inventory/collector/target_collection.rb @@ -124,7 +124,7 @@ def tenants def memoized_get_tenant(tenant_id) return nil if tenant_id.blank? @tenant_memo ||= Hash.new do |h, key| - h[key] = safe_get { identity_service.tenants.find_by_id(key) } + h[key] = safe_get { identity_service.respond_to?(:projects) ? identity_service.projects_get_by_id(key) : identity_service.tenants.find_by_id(key) } end @tenant_memo[tenant_id] end @@ -254,7 +254,7 @@ def infer_related_cloud_tenant_ems_refs_db! def infer_related_cloud_tenant_ems_refs_api! tenants.each do |tenant| - add_simple_target(:cloud_tenants, tenant.try(:parent_id)) unless tenant.try(:parent_id).blank? + add_simple_target!(:cloud_tenants, tenant.try(:parent_id)) unless tenant.try(:parent_id).blank? end end diff --git a/lib/manageiq/providers/openstack/legacy/openstack_handle/identity_delegate.rb b/lib/manageiq/providers/openstack/legacy/openstack_handle/identity_delegate.rb index f539524c7..02c502bd3 100644 --- a/lib/manageiq/providers/openstack/legacy/openstack_handle/identity_delegate.rb +++ b/lib/manageiq/providers/openstack/legacy/openstack_handle/identity_delegate.rb @@ -144,5 +144,11 @@ def list_project_tenant_user_roles(project_id, user_id) list_roles_for_user_on_tenant(project_id, user_id).body["roles"] end end + + # Remove this method once fog/openstack allows get_project correctly + def projects_get_by_id(id) + @all_projects ||= projects.all + @all_projects.find { |project| project.id == id } + end end end