Skip to content

Commit

Permalink
Clean up mapped tenants after an EMS is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam committed Oct 8, 2018
1 parent d1ccb82 commit f58bfc9
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 @@ -40,6 +40,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 @@ -140,5 +142,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 f58bfc9

Please sign in to comment.