-
Notifications
You must be signed in to change notification settings - Fork 896
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
Add child retirement task methods #17234
Merged
mkanoor
merged 2 commits into
ManageIQ:master
from
d-m-u:adding_service_task_retirement
Apr 17, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
describe ServiceRetireTask do | ||
let(:user) { FactoryGirl.create(:user_with_group) } | ||
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(:reason) { "Why Not?" } | ||
let(:approver) { FactoryGirl.create(:user_miq_request_approver) } | ||
let(:zone) { FactoryGirl.create(:zone, :name => "fred") } | ||
|
||
it "should initialize properly" do | ||
expect(service_retire_task.state).to eq('pending') | ||
expect(service_retire_task.status).to eq('Ok') | ||
end | ||
|
||
describe "respond to update_and_notify_parent" do | ||
context "state queued" do | ||
it "should not call task_finished" do | ||
service_retire_task.update_and_notify_parent(:state => "queued", :status => "Ok", :message => "yabadabadoo") | ||
|
||
expect(service_retire_task.message).to eq("yabadabadoo") | ||
end | ||
end | ||
|
||
context "state finished" do | ||
it "should call task_finished" do | ||
service_retire_task.update_and_notify_parent(:state => "finished", :status => "Ok", :message => "yabadabadoo") | ||
|
||
expect(service_retire_task.status).to eq("Completed") | ||
end | ||
end | ||
end | ||
|
||
describe "#after_request_task_create" do | ||
context "sans resource" do | ||
it "doesn't create subtask" do | ||
service_retire_task.after_request_task_create | ||
|
||
expect(service_retire_task.description).to eq("Service Retire for: #{service.name} - ") | ||
expect(VmRetireTask.count).to eq(0) | ||
end | ||
end | ||
|
||
context "with resource" do | ||
before do | ||
allow(MiqServer).to receive(:my_zone).and_return(Zone.seed.name) | ||
miq_request.approve(approver, reason) | ||
end | ||
|
||
it "creates subtask" do | ||
resource = FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service.id, :resource_id => vm.id) | ||
service.service_resources << resource | ||
service_retire_task.after_request_task_create | ||
|
||
expect(service_retire_task.description).to eq("Service Retire for: #{service.name} - ") | ||
expect(VmRetireTask.count).to eq(1) | ||
end | ||
end | ||
end | ||
|
||
describe "deliver_to_automate" do | ||
before do | ||
allow(MiqServer).to receive(:my_zone).and_return(Zone.seed.name) | ||
miq_request.approve(approver, reason) | ||
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', | ||
:message => 'Automation Starting' | ||
) | ||
service_retire_task.deliver_to_automate | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the collect is expected to be an array of tasks, you'll need
new_task
to be the last line in the block. As it is, this will collect whateverdeliver_to_automate
returns