From dd5eb70c6bc0ad8eeaa40634d8ce6a40a4dbacfc Mon Sep 17 00:00:00 2001 From: d-m-u Date: Tue, 21 Jan 2020 05:50:50 -0500 Subject: [PATCH] Fix issue with orch stacks still having references to deleted ems Introduced in https://github.com/ManageIQ/manageiq-schema/pull/288 Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1793112 --- ..._migrate_orch_stacks_to_have_ownership_concept.rb | 2 +- ...ate_orch_stacks_to_have_ownership_concept_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/db/migrate/20181016140921_migrate_orch_stacks_to_have_ownership_concept.rb b/db/migrate/20181016140921_migrate_orch_stacks_to_have_ownership_concept.rb index 81a232628..064cdcdb7 100644 --- a/db/migrate/20181016140921_migrate_orch_stacks_to_have_ownership_concept.rb +++ b/db/migrate/20181016140921_migrate_orch_stacks_to_have_ownership_concept.rb @@ -114,7 +114,7 @@ def up OrchestrationStack.find_each do |stack| user = if stack.service.present? stack.service.tenant_identity - elsif !stack.ems_id.nil? + elsif stack.ext_management_system stack.ext_management_system.tenant_identity else User.super_admin diff --git a/spec/migrations/20181016140921_migrate_orch_stacks_to_have_ownership_concept_spec.rb b/spec/migrations/20181016140921_migrate_orch_stacks_to_have_ownership_concept_spec.rb index c4bd3fd3b..05d3ead78 100644 --- a/spec/migrations/20181016140921_migrate_orch_stacks_to_have_ownership_concept_spec.rb +++ b/spec/migrations/20181016140921_migrate_orch_stacks_to_have_ownership_concept_spec.rb @@ -30,6 +30,18 @@ expect(stack).to have_attributes(:tenant_id => ext_ms.tenant_id, :evm_owner_id => ext_ms.tenant_identity.id, :miq_group_id => ext_ms.tenant_identity.current_group.id) end + it "sets owner, tenant, and group from the user if the ems was deleted but the stack ems id is still set" do + ext_ms = ems.create!(:tenant => tenant) + stack = orchestration_stack.create!(:ext_management_system => ext_ms) + ext_ms.destroy + expect(orchestration_stack.count).to eq(1) + + migrate + stack.reload + + expect(stack).to have_attributes(:tenant_id => user.current_tenant.id, :evm_owner_id => user.id, :miq_group_id => user.current_group.id) + end + it "sets owner, tenant, and group from the service if the service exists and ems doesn't" do svc = service.create!(:tenant_id => tenant.id, :miq_group_id => group.id) stack = orchestration_stack.create!(:direct_services => [svc])