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

[GAPRINDASHVILI] Add mark_retired method to not reset retirement_requester #18376

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
7 changes: 6 additions & 1 deletion app/models/mixins/retirement_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,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) { FactoryGirl.create(:user) }
let(:orchestration_stack) { FactoryBot.create(:orchestration_stack) }
before(:each) do
@miq_server = EvmSpecHelper.local_miq_server
@stack = FactoryGirl.create(:orchestration_stack)
Expand Down Expand Up @@ -71,8 +72,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 @@ -143,8 +143,17 @@
end

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

@service.finish_retirement

expect(@service.retirement_state).to eq("retired")
end

it "#mark_retired" do
expect(@service.retirement_state).to be_nil
@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
12 changes: 11 additions & 1 deletion spec/models/vm/retirement_management_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe "VM Retirement Management" do
let(:user) { FactoryGirl.create(:user) }
let(:vm) { FactoryGirl.create(:vm) }
before(:each) do
miq_server = EvmSpecHelper.local_miq_server
@zone = miq_server.zone
Expand Down Expand Up @@ -90,8 +91,17 @@
end

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

vm.finish_retirement

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

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

expect(@vm.retired).to eq(true)
Expand Down