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

Add provisioned? lifecycle status info to retireable? check #18943

Merged
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
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
8 changes: 7 additions & 1 deletion spec/models/mixins/ci_feature_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
end

it "service is retireable" do
FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower))
FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower, :lifecycle_state => 'provisioned'))

expect(service.service_resources.first.resource.retireable?).to eq(true)
end

it "unprov'd service is not retireable" do
FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower))

expect(service.service_resources.first.resource.retireable?).to eq(false)
end
end
end
30 changes: 24 additions & 6 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 @@ -70,10 +70,18 @@
miq_request.approve(approver, reason)
end

it "creates service retire subtask" do
it "doesn't create service retire subtask for unprov'd service" do
service.add_resource!(FactoryBot.create(:service_orchestration))
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 service retire subtask" do
service.add_resource!(FactoryBot.create(:service_orchestration, :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
Expand Down Expand Up @@ -109,13 +117,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 +191,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
11 changes: 9 additions & 2 deletions spec/models/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,20 @@
end

describe "#retireable?" do
let(:service_with_type) { FactoryBot.create(:service, :type => "thing") }
let(:service_with_type) { FactoryBot.create(:service, :type => "thing", :lifecycle_state => 'provisioned') }
let(:unprovd_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
expect(service_with_type.retireable?).to be(true)
end

it "true" do
expect(unprovd_service_with_type.retireable?).to be(false)
end
end

context "without type" do
Expand All @@ -694,6 +700,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