Skip to content

Commit

Permalink
Add provisioned? lifecycle status info to retireable? check
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jul 16, 2019
1 parent 42a55cc commit 664e915
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def request_type
end

def retireable?
return false unless provisioned?

# top level services do not have types; this method is used only in creating tasks for child services which always have types
# please see https://github.com/ManageIQ/manageiq/pull/17317#discussion_r186528878
parent.present? ? true : type.present?
end

Expand Down
20 changes: 15 additions & 5 deletions spec/models/service_retire_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe ServiceRetireTask do
let(:user) { FactoryBot.create(:user_with_group) }
let(:vm) { FactoryBot.create(:vm) }
let(:service) { FactoryBot.create(:service) }
let(:service) { FactoryBot.create(:service, :lifecycle_state => 'provisioned') }
let(:miq_request) { FactoryBot.create(:service_retire_request, :requester => user, :source => service) }
let(:service_retire_task) { FactoryBot.create(:service_retire_task, :source => service, :miq_request => miq_request, :options => {:src_ids => [service.id] }) }
let(:reason) { "Why Not?" }
Expand Down Expand Up @@ -109,13 +109,21 @@
end

it "creates service retire subtask" do
service.add_resource!(FactoryBot.create(:service))
service.add_resource!(FactoryBot.create(:service, :lifecycle_state => 'provisioned'))
service_retire_task.after_request_task_create

expect(service_retire_task.description).to eq("Service Retire for: #{service.name}")
expect(ServiceRetireTask.count).to eq(2)
end

it "doesn't create service retire subtask for unprovisioned service" do
service.add_resource!(FactoryBot.create(:service))
service_retire_task.after_request_task_create

expect(service_retire_task.description).to eq("Service Retire for: #{service.name}")
expect(ServiceRetireTask.count).to eq(1)
end

it "creates stack retire subtask" do
service.add_resource!(FactoryBot.create(:orchestration_stack))
service_retire_task.after_request_task_create
Expand Down Expand Up @@ -175,18 +183,20 @@
end
end

context "bundled service retires all children" do
let(:service_c1) { FactoryBot.create(:service) }
context "bundled service retires all valid children" do
let(:service_c1) { FactoryBot.create(:service, :lifecycle_state => 'provisioned') }
let(:service_c2) { FactoryBot.create(:service) }

before do
service.add_resource!(service_c1)
service.add_resource!(service_c2)
service.add_resource!(FactoryBot.create(:service_template))
@miq_request = FactoryBot.create(:service_retire_request, :requester => user)
@miq_request.approve(approver, reason)
@service_retire_task = FactoryBot.create(:service_retire_task, :source => service, :miq_request => @miq_request, :options => {:src_ids => [service.id] })
end

it "creates subtask for services but not templates" do
it "creates subtask for provisioned services but not templates" do
@service_retire_task.after_request_task_create

expect(ServiceRetireTask.count).to eq(2)
Expand Down
4 changes: 3 additions & 1 deletion spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@
describe "#retireable?" do
let(:service_with_type) { FactoryBot.create(:service, :type => "thing") }
let(:service_without_type) { FactoryBot.create(:service, :type => nil) }
let(:service_with_parent) { FactoryBot.create(:service, :service => FactoryBot.create(:service)) }
let(:service_with_parent) { FactoryBot.create(:service, :service => FactoryBot.create(:service), :lifecycle_state => 'provisioned') }
let(:unprovisioned_service_with_parent) { FactoryBot.create(:service, :service => FactoryBot.create(:service)) }
context "with no parent" do
context "with type" do
it "true" do
Expand All @@ -694,6 +695,7 @@
context "with parent" do
it "true" do
expect(service_with_parent.retireable?).to be(true)
expect(unprovisioned_service_with_parent.retireable?).to be(false)
end
end
end
Expand Down

0 comments on commit 664e915

Please sign in to comment.