Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return VMs and Templates for EMS prev_relats #15671

Merged
merged 1 commit into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/models/ems_refresh/metadata_relats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ def vmdb_relats_ems(ems, relats = nil)
next if p_type == :clusters && c_type == :vms
next if p_type == :hosts && c_type == :vms

# Handle default resource pools being called differently
c_meth = ([:hosts, :clusters].include?(p_type) && c_type == :resource_pools) ? :resource_pools_with_default : c_type
c_meth =
# Handle default resource pools being called differently
if [:hosts, :clusters].include?(p_type) && c_type == :resource_pools
:resource_pools_with_default
# Handle both Vm and Template child types
elsif c_type == :vms
:vms_and_templates
else
c_type
end

next unless x.respond_to?(c_meth)

ids = x.send(c_meth).collect(&:id).uniq
Expand Down
51 changes: 30 additions & 21 deletions spec/models/ems_refresh/metadata_relats_spec.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
describe EmsRefresh::MetadataRelats do
context ".vmdb_relats" do
before(:each) do
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_vmware, :zone => @zone)
@cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems)
@host = FactoryGirl.create(:host, :ext_management_system => @ems, :ems_cluster => @cluster)
@vm = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems, :ems_cluster => @cluster, :host => @host)

@rp = FactoryGirl.create(:resource_pool, :ext_management_system => @ems)
@folder = FactoryGirl.create(:ems_folder, :ext_management_system => @ems)
@folder.add_cluster(@cluster)
@zone = FactoryGirl.create(:zone)
@ems = FactoryGirl.create(:ems_vmware, :zone => @zone)

@cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems)
@host = FactoryGirl.create(:host, :ext_management_system => @ems, :ems_cluster => @cluster)
@vm = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems, :ems_cluster => @cluster, :host => @host)
@template = FactoryGirl.create(:template_vmware, :ext_management_system => @ems)
@rp = FactoryGirl.create(:resource_pool, :ext_management_system => @ems)
@host_folder = FactoryGirl.create(:vmware_folder_host, :ext_management_system => @ems)
@vm_folder = FactoryGirl.create(:vmware_folder_vm, :ext_management_system => @ems)

@host_folder.add_cluster(@cluster)
@cluster.add_resource_pool(@rp)
@rp.add_vm(@vm)

[@ems, @folder, @cluster, @rp, @host, @vm].each(&:reload)
@vm_folder.add_vm(@vm)
@vm_folder.add_vm(@template)

[@ems, @host_folder, @vm_folder, @cluster, @rp, @host, @vm, @template].each(&:reload)
MiqQueue.delete_all
end

it "with a Vm" do
expect(EmsRefresh.vmdb_relats(@vm)).to eq(:folders_to_clusters => {@folder.id => [@cluster.id]},
:clusters_to_resource_pools => {@cluster.id => [@rp.id]},
:resource_pools_to_vms => {@rp.id => [@vm.id]})
expect(EmsRefresh.vmdb_relats(@vm)).to eq(:folders_to_clusters => {@host_folder.id => [@cluster.id]},
:folders_to_vms => {@vm_folder.id => [@vm.id]},
:clusters_to_resource_pools => {@cluster.id => [@rp.id]},
:resource_pools_to_vms => {@rp.id => [@vm.id]})
end

it "with a Host" do
expect(EmsRefresh.vmdb_relats(@host)).to eq(:folders_to_clusters => {@folder.id => [@cluster.id]})
expect(EmsRefresh.vmdb_relats(@host)).to eq(:folders_to_clusters => {@host_folder.id => [@cluster.id]})
end

it "with an EMS" do
expect(EmsRefresh.vmdb_relats(@ems)).to eq(:folders_to_clusters => {@folder.id => [@cluster.id]},
:clusters_to_resource_pools => {@cluster.id => [@rp.id]},
:resource_pools_to_vms => {@rp.id => [@vm.id]})
expect(EmsRefresh.vmdb_relats(@ems)).to eq(:folders_to_clusters => {@host_folder.id => [@cluster.id]},
:folders_to_vms => {@vm_folder.id => [@template.id, @vm.id]},
:clusters_to_resource_pools => {@cluster.id => [@rp.id]},
:resource_pools_to_vms => {@rp.id => [@vm.id]})
end

context "with an invalid relats tree" do
before(:each) do
@rp2 = FactoryGirl.create(:resource_pool, :ext_management_system => @ems)
@host.set_child(@rp2)
@folder.add_host(@host)
@host_folder.add_host(@host)

[@folder, @host, @rp2].each(&:reload)
[@host_folder, @host, @rp2].each(&:reload)
MiqQueue.delete_all
end

it "with an EMS" do
expect(EmsRefresh.vmdb_relats(@ems)).to eq(:folders_to_hosts => {@folder.id => [@host.id]},
:folders_to_clusters => {@folder.id => [@cluster.id]},
expect(EmsRefresh.vmdb_relats(@ems)).to eq(:folders_to_hosts => {@host_folder.id => [@host.id]},
:folders_to_vms => {@vm_folder.id => [@template.id, @vm.id]},
:folders_to_clusters => {@host_folder.id => [@cluster.id]},
:clusters_to_resource_pools => {@cluster.id => [@rp.id]},
:hosts_to_resource_pools => {@host.id => [@rp2.id]},
:resource_pools_to_vms => {@rp.id => [@vm.id]})
Expand Down