Skip to content

Commit

Permalink
Merge pull request #17866 from mansam/cleanup-mapped-tenants-after-em…
Browse files Browse the repository at this point in the history
…s-destroy

Clean up mapped tenants after a CloudManager is destroyed

(cherry picked from commit 89a1ebf)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1547740
  • Loading branch information
agrare authored and simaishi committed Oct 17, 2018
1 parent 9b78d52 commit 051d05f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/models/manageiq/providers/cloud_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class << model_name
include HasNetworkManagerMixin
include HasManyOrchestrationStackMixin

after_destroy :destroy_mapped_tenants

# Development helper method for Rails console for opening a browser to the EMS.
#
# This method is NOT meant to be called from production code.
Expand Down Expand Up @@ -142,5 +144,13 @@ def create_cloud_tenant(options)
def self.display_name(number = 1)
n_('Cloud Manager', 'Cloud Managers', number)
end

def destroy_mapped_tenants
if source_tenant
source_tenant.all_subtenants.destroy_all
source_tenant.all_subprojects.destroy_all
source_tenant.destroy
end
end
end
end
11 changes: 11 additions & 0 deletions spec/models/manageiq/providers/cloud_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ def expect_created_tenant_tree
expect_created_tenant_tree
end

it "cleans up created tenant tree when the ems is destroyed" do
ems_cloud.sync_cloud_tenants_with_tenants
expect_created_tenant_tree
# 4 cloud tenants, plus the provider tenant and root tenant
expect(Tenant.count).to eq(6)
ems_cloud.destroy
# only the root tenant should remain after destroying the ems
expect(Tenant.count).to eq(1)
expect(Tenant.first.name).to eq("My Company")
end

let(:vm_5) { FactoryGirl.create(:vm_openstack) }

let(:ct_5) do
Expand Down

0 comments on commit 051d05f

Please sign in to comment.