Skip to content

Commit

Permalink
Merge pull request #15329 from skateman/cloud-tenant-active-vms
Browse files Browse the repository at this point in the history
Limit CloudTenants' related VMs to the non-archived ones
  • Loading branch information
blomquisg authored Jun 14, 2017
2 parents 4e2e528 + 8ea6c77 commit 9e19b17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/cloud_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -639,17 +639,17 @@

# 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"}
)

# 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
Expand Down

0 comments on commit 9e19b17

Please sign in to comment.