Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Finish VM Task to error state when EMS paused
For example Power on/off operations.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1740285
  • Loading branch information
slemrmartin committed Aug 20, 2019
1 parent e1ed394 commit 8c161a4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/mixins/process_tasks_mixin.rb
Expand Up @@ -201,8 +201,13 @@ def validate_tasks(options)
return instances, tasks
end

# default: validate retirement, can be overridden
# default: validate retirement and maintenance zone, can be overridden
def validate_task(task, instance, options)
if instance.try(:ext_management_system)&.zone == Zone.maintenance_zone
task.error("#{instance.ext_management_system.name} is paused")
return false
end

return true unless options[:task] == "retire_now" && instance.retired?
task.error("#{instance.name} is already retired")
false
Expand Down
27 changes: 27 additions & 0 deletions spec/models/mixins/process_tasks_mixin_spec.rb
Expand Up @@ -341,4 +341,31 @@ def test_method
end
end
end

describe '.validate_task' do
let(:ext_management_system) { double("ExtManagementSystem") }
let(:instance) { double("Target") }
let(:task) { double("Task") }
before do
Zone.seed

allow(instance).to receive(:ext_management_system).and_return(ext_management_system)
end

it 'validates task when EMS not paused' do
allow(ext_management_system).to receive_messages(:name => 'My provider',
:zone => Zone.default_zone)

expect(task).not_to receive(:error).with("#{ext_management_system.name} is paused")
test_class.send(:validate_task, task, instance, {})
end

it 'marks task as invalid when EMS paused' do
allow(ext_management_system).to receive_messages(:name => 'My provider',
:zone => Zone.maintenance_zone)

expect(task).to receive(:error).with("#{ext_management_system.name} is paused")
test_class.send(:validate_task, task, instance, {})
end
end
end
2 changes: 2 additions & 0 deletions spec/models/vm_spec.rb
Expand Up @@ -114,7 +114,9 @@

context "#invoke_tasks_local" do
before do
Zone.seed
EvmSpecHelper.create_guid_miq_server_zone

@host = FactoryBot.create(:host)
@vm = FactoryBot.create(:vm_vmware, :host => @host)
end
Expand Down

0 comments on commit 8c161a4

Please sign in to comment.