From 2bac4be51677a1bd931ffc2a2f5d871dbf6d2cce Mon Sep 17 00:00:00 2001 From: Greg McCullough Date: Wed, 10 May 2017 10:42:12 -0400 Subject: [PATCH] Merge pull request #15026 from tinaafitz/add_zone_to_retirement Change retire_now to pass zone_name to raise_retirement_event. (cherry picked from commit 9e5df30604b9c0fb9fdbb91952a4d70f3fe7abf4) https://bugzilla.redhat.com/show_bug.cgi?id=1449753 --- app/models/mixins/retirement_mixin.rb | 10 +++++++++- .../retirement_management_spec.rb | 7 ++++--- spec/models/service/retirement_management_spec.rb | 6 +++--- spec/models/vm/retirement_management_spec.rb | 12 ++++++++---- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/models/mixins/retirement_mixin.rb b/app/models/mixins/retirement_mixin.rb index 9d53392ed7a..82537b85566 100644 --- a/app/models/mixins/retirement_mixin.rb +++ b/app/models/mixins/retirement_mixin.rb @@ -175,7 +175,7 @@ def retired_event_name def raise_retirement_event(event_name, requester = nil) $log.info("Raising Retirement Event for [#{name}]") - MiqEvent.raise_evm_event(self, event_name, setup_event_hash(requester)) + MiqEvent.raise_evm_event(self, event_name, setup_event_hash(requester), retire_queue_options) end def raise_audit_event(event_name, message) @@ -198,6 +198,14 @@ def error_retiring? private + def retire_queue_options + valid_zone? ? {:zone => my_zone} : {} + end + + def valid_zone? + respond_to?(:my_zone) && my_zone.present? + end + def setup_event_hash(requester) event_hash = {:retirement_initiator => "system"} event_hash[retirement_base_model_name.underscore.to_sym] = self diff --git a/spec/models/orchestration_stack/retirement_management_spec.rb b/spec/models/orchestration_stack/retirement_management_spec.rb index 78c28318bed..75c16059919 100644 --- a/spec/models/orchestration_stack/retirement_management_spec.rb +++ b/spec/models/orchestration_stack/retirement_management_spec.rb @@ -35,7 +35,7 @@ event_hash = {:orchestration_stack => @stack, :type => "OrchestrationStack", :retirement_initiator => "user", :userid => "freddy"} - expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, {}).once @stack.retire_now('freddy') @stack.reload @@ -47,7 +47,7 @@ event_hash = {:orchestration_stack => @stack, :type => "OrchestrationStack", :retirement_initiator => "system"} - expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, {}).once @stack.retire_now @stack.reload @@ -132,7 +132,8 @@ :type => "OrchestrationStack", :retirement_initiator => "system" } - expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash) + + expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, {}) @stack.raise_retirement_event(event_name) end diff --git a/spec/models/service/retirement_management_spec.rb b/spec/models/service/retirement_management_spec.rb index 199871f7b2a..7adc746fea8 100644 --- a/spec/models/service/retirement_management_spec.rb +++ b/spec/models/service/retirement_management_spec.rb @@ -35,7 +35,7 @@ event_hash = {:service => @service, :type => "Service", :retirement_initiator => "user", :userid => "freddy"} - expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {}).once @service.retire_now('freddy') @service.reload @@ -47,7 +47,7 @@ event_hash = {:service => @service, :type => "Service", :retirement_initiator => "system"} - expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {}).once @service.retire_now @service.reload @@ -165,7 +165,7 @@ it "#raise_retirement_event" do event_name = 'foo' event_hash = {:service => @service, :type => "Service", :retirement_initiator => "system"} - expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash) + expect(MiqEvent).to receive(:raise_evm_event).with(@service, event_name, event_hash, {}) @service.raise_retirement_event(event_name) end diff --git a/spec/models/vm/retirement_management_spec.rb b/spec/models/vm/retirement_management_spec.rb index 09427c43ee8..ceee92356dc 100644 --- a/spec/models/vm/retirement_management_spec.rb +++ b/spec/models/vm/retirement_management_spec.rb @@ -1,7 +1,8 @@ describe "VM Retirement Management" do before(:each) do miq_server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware, :zone => miq_server.zone) + @zone = miq_server.zone + @ems = FactoryGirl.create(:ems_vmware, :zone => @zone) @vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id) end @@ -34,8 +35,9 @@ event_name = 'request_vm_retire' event_hash = {:vm => @vm, :host => @vm.host, :type => "ManageIQ::Providers::Vmware::InfraManager::Vm", :retirement_initiator => "user", :userid => 'freddy'} + options = {:zone => @zone.name} - expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash, options).once @vm.retire_now('freddy') end @@ -44,8 +46,9 @@ event_name = 'request_vm_retire' event_hash = {:vm => @vm, :host => @vm.host, :type => "ManageIQ::Providers::Vmware::InfraManager::Vm", :retirement_initiator => "system"} + options = {:zone => @zone.name} - expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash, options).once @vm.retire_now end @@ -142,8 +145,9 @@ event_name = 'foo' event_hash = {:vm => @vm, :host => @vm.host, :type => "ManageIQ::Providers::Vmware::InfraManager::Vm", :retirement_initiator => "system"} + options = {:zone => @vm.my_zone} - expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash).once + expect(MiqEvent).to receive(:raise_evm_event).with(@vm, event_name, event_hash, options).once @vm.raise_retirement_event(event_name) end