Skip to content

Commit

Permalink
Merge pull request #18085 from d-m-u/adding_tests_for_retire_tasks
Browse files Browse the repository at this point in the history
Test deliver_to_automate gets called in vms, services, orch stack retire tasks

(cherry picked from commit 9822d52)
  • Loading branch information
bdunne authored and simaishi committed Nov 2, 2018
1 parent b8e41be commit 77db974
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/models/orchestration_stack_retire_task.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class OrchestrationStackRetireTask < MiqRetireTask
default_value_for :request_type, "orchestration_stack_retire"

def self.base_model
OrchestrationStackRetireTask
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/service_retire_task.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ServiceRetireTask < MiqRetireTask
default_value_for :request_type, "service_retire"

def self.base_model
ServiceRetireTask
end
Expand Down
1 change: 1 addition & 0 deletions app/models/vm_retire_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class VmRetireTask < MiqRetireTask
alias_attribute :vm, :source
default_value_for :request_type, "vm_retire"

def self.base_model
VmRetireTask
Expand Down
15 changes: 11 additions & 4 deletions spec/factories/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@
state 'pending'
request_type 'clone_to_service'
end
factory :service_retire_task, :parent => :miq_retire_task, :class => "ServiceRetireTask" do
request_type 'service_retire'
state 'pending'
end

factory :service_template_transformation_plan_task, :parent => :service_template_provision_task, :class => 'ServiceTemplateTransformationPlanTask' do
request_type 'transformation_plan'
end

# Retire Tasks
factory :service_retire_task, :parent => :miq_retire_task, :class => "ServiceRetireTask" do
state 'pending'
end
factory :vm_retire_task, :parent => :miq_retire_task, :class => "VmRetireTask" do
state 'pending'
end
factory :orchestration_stack_retire_task, :parent => :miq_retire_task, :class => "OrchestrationStackRetireTask" do
state 'pending'
end
end
27 changes: 27 additions & 0 deletions spec/models/orchestration_stack_retire_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe OrchestrationStackRetireTask do
let(:user) { FactoryGirl.create(:user_with_group) }
let(:orchestration_stack) { FactoryGirl.create(:orchestration_stack) }
let(:miq_request) { FactoryGirl.create(:orchestration_stack_retire_request, :requester => user) }
let(:orchestration_stack_retire_task) { FactoryGirl.create(:orchestration_stack_retire_task, :source => orchestration_stack, :miq_request => miq_request, :options => {:src_ids => [orchestration_stack.id] }) }
let(:approver) { FactoryGirl.create(:user_miq_request_approver) }

it "should initialize properly" do
expect(orchestration_stack_retire_task).to have_attributes(:state => "pending", :status => "Ok")
end

describe "deliver_to_automate" do
before do
allow(MiqServer).to receive(:my_zone).and_return(Zone.seed.name)
miq_request.approve(approver, "why not??")
end

it "updates the task state to pending" do
expect(orchestration_stack_retire_task).to receive(:update_and_notify_parent).with(
:state => 'pending',
:status => 'Ok',
:message => 'Automation Starting'
)
orchestration_stack_retire_task.deliver_to_automate
end
end
end
7 changes: 2 additions & 5 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
let(:vm) { FactoryGirl.create(:vm) }
let(:service) { FactoryGirl.create(:service) }
let(:miq_request) { FactoryGirl.create(:service_retire_request, :requester => user) }
let(:miq_request_task) { FactoryGirl.create(:miq_request_task, :miq_request_id => miq_request.id) }
let(:service_retire_task) { FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => miq_request_task.id, :miq_request_id => miq_request.id, :options => {:src_ids => [service.id] }) }
let(:service_retire_task) { FactoryGirl.create(:service_retire_task, :source => service, :miq_request => miq_request, :options => {:src_ids => [service.id] }) }
let(:reason) { "Why Not?" }
let(:approver) { FactoryGirl.create(:user_miq_request_approver) }
let(:zone) { FactoryGirl.create(:zone, :name => "fred") }
Expand All @@ -21,8 +20,7 @@
end

it "should initialize properly" do
expect(service_retire_task.state).to eq('pending')
expect(service_retire_task.status).to eq('Ok')
expect(service_retire_task).to have_attributes(:state => 'pending', :status => 'Ok')
end

describe "respond to update_and_notify_parent" do
Expand Down Expand Up @@ -104,7 +102,6 @@
end

it "updates the task state to pending" do
allow(MiqQueue).to receive(:put)
expect(service_retire_task).to receive(:update_and_notify_parent).with(
:state => 'pending',
:status => 'Ok',
Expand Down
27 changes: 27 additions & 0 deletions spec/models/vm_retire_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
describe VmRetireTask do
let(:user) { FactoryGirl.create(:user_with_group) }
let(:vm) { FactoryGirl.create(:vm) }
let(:miq_request) { FactoryGirl.create(:vm_retire_request, :requester => user) }
let(:vm_retire_task) { FactoryGirl.create(:vm_retire_task, :source => vm, :miq_request => miq_request, :options => {:src_ids => [vm.id] }) }
let(:approver) { FactoryGirl.create(:user_miq_request_approver) }

it "should initialize properly" do
expect(vm_retire_task).to have_attributes(:state => 'pending', :status => 'Ok')
end

describe "deliver_to_automate" do
before do
allow(MiqServer).to receive(:my_zone).and_return(Zone.seed.name)
miq_request.approve(approver, "why not??")
end

it "updates the task state to pending" do
expect(vm_retire_task).to receive(:update_and_notify_parent).with(
:state => 'pending',
:status => 'Ok',
:message => 'Automation Starting'
)
vm_retire_task.deliver_to_automate
end
end
end

0 comments on commit 77db974

Please sign in to comment.