From 8ea6c77f97f3e43daaa90f8e667215d43dac2530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Wed, 7 Jun 2017 10:25:22 +0200 Subject: [PATCH] Limit CloudTenants' related VMs to the non-archived ones https://bugzilla.redhat.com/show_bug.cgi?id=1456031 --- app/models/cloud_tenant.rb | 2 +- app/models/vm_or_template.rb | 2 ++ .../save_inventory/single_inventory_collection_spec.rb | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/cloud_tenant.rb b/app/models/cloud_tenant.rb index 7e7aa63ee61..2c82ca99f76 100644 --- a/app/models/cloud_tenant.rb +++ b/app/models/cloud_tenant.rb @@ -12,7 +12,7 @@ class CloudTenant < ApplicationRecord has_many :cloud_subnets has_many :network_ports has_many :network_routers - has_many :vms + has_many :vms, -> { active } has_many :vms_and_templates has_many :miq_templates has_many :floating_ips diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index 8401a5eede3..6e970a6cc82 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -185,6 +185,8 @@ class VmOrTemplate < ApplicationRecord before_validation :set_tenant_from_group after_save :save_genealogy_information + scope :active, -> { where.not(:ems_id => nil) } + alias_method :datastores, :storages # Used by web-services to return datastores as the property name alias_method :parent_cluster, :ems_cluster diff --git a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb index ab50739f456..35aebd0c1a9 100644 --- a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb +++ b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb @@ -600,14 +600,14 @@ # Assert that saved data have the new VM and miss the deleted VM assert_all_records_match_hashes( - [Vm.all, cloud_tenant.vms], + [Vm.all], {:id => @vm1.id, :ems_ref => "vm_ems_ref_1", :name => "vm_changed_name_1", :location => "vm_location_1"}, {:id => anything, :ems_ref => "vm_ems_ref_3", :name => "vm_changed_name_3", :location => "vm_location_3"} ) # Assert that ems relation exists only for the updated VM assert_all_records_match_hashes( - @ems.vms, + [@ems.vms, cloud_tenant.vms], :id => @vm1.id, :ems_ref => "vm_ems_ref_1", :name => "vm_changed_name_1", :location => "vm_location_1" ) end @@ -639,7 +639,7 @@ # Assert that saved data have the new VM and miss the deleted VM assert_all_records_match_hashes( - [Vm.all, cloud_tenant.vms], + [Vm.all], {:id => @vm1.id, :ems_ref => "vm_ems_ref_1", :name => "vm_changed_name_1", :location => "vm_location_1"}, {:id => @vm2.id, :ems_ref => "vm_ems_ref_2", :name => "vm_name_2", :location => "vm_location_2"}, {:id => anything, :ems_ref => "vm_ems_ref_3", :name => "vm_changed_name_3", :location => "vm_location_3"} @@ -647,9 +647,9 @@ # Assert that ems relation exists only for the updated VM assert_all_records_match_hashes( - @ems.vms, + [@ems.vms, cloud_tenant.vms], {:id => @vm1.id, :ems_ref => "vm_ems_ref_1", :name => "vm_changed_name_1", :location => "vm_location_1"}, - {:id => @vm2.id, :ems_ref => "vm_ems_ref_2", :name => "vm_name_2", :location => "vm_location_2"} + {:id => @vm2.id, :ems_ref => "vm_ems_ref_2", :name => "vm_name_2", :location => "vm_location_2"}, ) end end