Skip to content

Commit

Permalink
Service#my_zone should only reference a VM associated to a provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcculloug committed Apr 10, 2017
1 parent 396826f commit 46b7f9f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def queue_group_action(action, group_idx, direction, deliver_delay)
end

def my_zone
first_vm = vms.first
first_vm.ext_management_system.zone.name unless first_vm.nil?
# Verify the VM has a provider or my_zone will return the miq_server zone by default
vms.detect(&:ext_management_system).try(:my_zone)
end

def service_action(requested, service_resource)
Expand Down
35 changes: 35 additions & 0 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,41 @@
end
end

describe '#my_zone' do
let(:service) { FactoryGirl.create(:service) }

it 'returns nil without any resources' do
expect(service.my_zone).to be_nil
end

it 'returns nil zone when VM is archived' do
vm = FactoryGirl.build(:vm_vmware)

service.add_resource!(vm)
expect(service.my_zone).to be_nil
end

it 'returns the EMS zone when the VM is connected to a EMS' do
ems = FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone))
vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems)

service.add_resource!(vm)

expect(service.my_zone).to eq(ems.my_zone)
end

it 'returns the EMS zone with one VM connected to a EMS and one archived' do
service.add_resource!(FactoryGirl.build(:vm_vmware))

ems = FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone))
vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems)

service.add_resource!(vm)

expect(service.my_zone).to eq(ems.my_zone)
end
end

def create_deep_tree
@service = FactoryGirl.create(:service)
@service_c1 = FactoryGirl.create(:service, :service => @service)
Expand Down

0 comments on commit 46b7f9f

Please sign in to comment.