Skip to content

Commit

Permalink
Add mark_retired method to not reset retirement_requester after end o…
Browse files Browse the repository at this point in the history
…f retirement
  • Loading branch information
d-m-u committed Jan 3, 2019
1 parent 4adc48b commit f787282
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,18 @@ def finish_retirement
raise _("%{name} already retired") % {:name => name} if retired?
$log.info("Finishing Retirement for [#{name}]")
requester = retirement_requester
update_attributes(:retires_on => Time.zone.now, :retired => true, :retirement_state => "retired")
mark_retired
message = "#{self.class.base_model.name}: [#{name}], Retires On: [#{retires_on.strftime("%x %R %Z")}], has been retired"
$log.info("Calling audit event for: #{message} ")
raise_audit_event(retired_event_name, message, requester)
$log.info("Called audit event for: #{message} ")
end

def mark_retired
self[:retires_on] = Time.zone.now
update_attributes(:retired => true, :retirement_state => "retired")
end

def start_retirement
return if retired? || retiring?
$log.info("Starting Retirement for [#{name}]")
Expand Down
12 changes: 11 additions & 1 deletion spec/models/orchestration_stack/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe "Service Retirement Management" do
let!(:user) { FactoryBot.create(:user_miq_request_approver, :userid => "admin") }
let(:orchestration_stack) { FactoryBot.create(:orchestration_stack) }
context "with zone/ems" do
before do
@miq_server = EvmSpecHelper.local_miq_server
Expand Down Expand Up @@ -67,8 +68,17 @@
end

it "#finish_retirement" do
message = "OrchestrationStack: [#{orchestration_stack.name}], Retires On: [#{Time.zone.now.strftime("%x %R %Z")}], has been retired"
expect(orchestration_stack).to receive(:raise_audit_event).with("orchestration_stack_retired", message, nil)

orchestration_stack.finish_retirement

expect(orchestration_stack.retirement_state).to eq("retired")
end

it "#mark_retired" do
expect(@stack.retirement_state).to be_nil
@stack.finish_retirement
@stack.mark_retired
@stack.reload
expect(@stack.retired).to be_truthy
expect(@stack.retires_on).to be_between(Time.zone.now - 1.hour, Time.zone.now + 1.second)
Expand Down
11 changes: 10 additions & 1 deletion spec/models/service/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@
end

it "#finish_retirement" do
message = "Service: [#{service3.name}], Retires On: [#{Time.zone.now.strftime("%x %R %Z")}], has been retired"
expect(service3).to receive(:raise_audit_event).with("service_retired", message, nil)

service3.finish_retirement

expect(service3.retirement_state).to eq("retired")
end

it "#mark_retired" do
expect(@service.retirement_state).to be_nil
@service.finish_retirement
@service.mark_retired
@service.reload
expect(@service.retired).to be_truthy
expect(@service.retires_on).to be_between(Time.zone.now - 1.hour, Time.zone.now + 1.second)
Expand Down
9 changes: 9 additions & 0 deletions spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@
end

it "#finish_retirement" do
message = "Vm: [#{vm2.name}], Retires On: [#{Time.zone.now.strftime("%x %R %Z")}], has been retired"
expect(vm2).to receive(:raise_audit_event).with("vm_retired", message, nil)

vm2.finish_retirement

expect(vm2.retirement_state).to eq("retired")
end

it "#mark_retired" do
expect(@vm.retirement_state).to be_nil
@vm.finish_retirement
@vm.reload
Expand Down

0 comments on commit f787282

Please sign in to comment.