Skip to content

Commit

Permalink
Fixed tenant_identity to handle storage that does not belong to an EMS
Browse files Browse the repository at this point in the history
- Removed #tenant_identity method in place of mixing version that already handles nil EMS
- Storages belong to an EMS indirectly through the hosts to which it is attached. If a storage is not attached to any hosts the EMS will be nil.
In that case the root tenant will be used for the tenant_identity.

https://bugzilla.redhat.com/show_bug.cgi?id=1365688
  • Loading branch information
gtanzillo committed Aug 11, 2016
1 parent b9ac0c8 commit 3ce925b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/models/storage.rb
Expand Up @@ -47,6 +47,7 @@ class Storage < ApplicationRecord
include AsyncDeleteMixin
include AvailabilityMixin
include SupportsFeatureMixin
include TenantIdentityMixin

virtual_column :v_used_space, :type => :integer
virtual_column :v_used_space_percent_of_total, :type => :integer
Expand Down Expand Up @@ -888,10 +889,6 @@ def self.batch_operation_supported?(operation, ids)
end
end

def tenant_identity
ext_management_system.tenant_identity
end

# @param [String, Storage] store_type upcased version of the storage type
def self.supports?(store_type)
Storage::SUPPORTED_STORAGE_TYPES.include?(store_type)
Expand Down
24 changes: 24 additions & 0 deletions spec/models/storage_spec.rb
Expand Up @@ -536,4 +536,28 @@
expect(storage.storage_clusters).to match_array([])
end
end

context "#tenant_identity" do
let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") }
let(:tenant) { FactoryGirl.create(:tenant) }
let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) }
let(:host) { FactoryGirl.create(:host, :ext_management_system => ems) }

before { admin }
it "has tenant from provider" do
storage = FactoryGirl.create(:storage, :hosts => [host])

expect(storage.tenant_identity).to eq(admin)
expect(storage.tenant_identity.current_group).to eq(ems.tenant.default_miq_group)
expect(storage.tenant_identity.current_tenant).to eq(ems.tenant)
end

it "without a provider, has tenant from root tenant" do
storage = FactoryGirl.create(:storage)

expect(storage.tenant_identity).to eq(admin)
expect(storage.tenant_identity.current_group).to eq(Tenant.root_tenant.default_miq_group)
expect(storage.tenant_identity.current_tenant).to eq(Tenant.root_tenant)
end
end
end

0 comments on commit 3ce925b

Please sign in to comment.