Skip to content

Commit

Permalink
Merge pull request #20047 from kbrock/infra_clusterless_hosts
Browse files Browse the repository at this point in the history
introduce clusterless hosts as an association

(cherry picked from commit 7320484)
  • Loading branch information
jrafanie authored and simaishi committed Apr 16, 2020
1 parent 3d4f6cf commit 0295f09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions app/models/manageiq/providers/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class InfraManager < BaseManager
has_many :networks, :through => :hardwares
has_many :guest_devices, :through => :hardwares
has_many :ems_custom_attributes, :through => :vms_and_templates
has_many :clusterless_hosts, -> { where(:ems_cluster =>nil) }, :class_name => "Host", :foreign_key => "ems_id", :inverse_of => :ext_management_system

include HasManyOrchestrationStackMixin

Expand Down Expand Up @@ -65,10 +66,6 @@ def self.ems_timeouts(type, service = nil)
def validate_authentication_status
{:available => true, :message => nil}
end

def clusterless_hosts
hosts.where(:ems_cluster => nil)
end
end

def self.display_name(number = 1)
Expand Down
10 changes: 10 additions & 0 deletions spec/models/manageiq/providers/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
expect(described_class.ems_timeouts(:ems_redhat, :InVentory)).to eq [5.hours, nil]
end
end

describe '.clusterless_hosts' do
it "hosts with no ems" do
ems = FactoryBot.create(:ems_infra)
host = FactoryBot.create(:host, :ext_management_system => ems)
FactoryBot.create(:host, :ext_management_system => ems, :ems_cluster => FactoryBot.create(:ems_cluster))

expect(ems.clusterless_hosts).to eq([host])
end
end
end

0 comments on commit 0295f09

Please sign in to comment.