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

Change retire_now to pass zone_name to raise_retirement_event. #15026

Merged
merged 1 commit into from
May 10, 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
10 changes: 9 additions & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 8 additions & 4 deletions spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down