-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17951 from d-m-u/fixing_system_retirement_user
Add retirement initiator context
- Loading branch information
Showing
5 changed files
with
226 additions
and
194 deletions.
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
245 changes: 127 additions & 118 deletions
245
spec/models/orchestration_stack/retirement_management_spec.rb
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 |
---|---|---|
@@ -1,153 +1,162 @@ | ||
describe "Service Retirement Management" do | ||
let(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") } | ||
before do | ||
@miq_server = EvmSpecHelper.local_miq_server | ||
@stack = FactoryGirl.create(:orchestration_stack) | ||
end | ||
let!(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") } | ||
context "with zone/ems" do | ||
before do | ||
@miq_server = EvmSpecHelper.local_miq_server | ||
@zone = @miq_server.zone | ||
ems = FactoryGirl.create(:ext_management_system, :zone => @zone) | ||
@stack = FactoryGirl.create(:orchestration_stack, :ext_management_system => ems) | ||
end | ||
|
||
it "#retirement_check" do | ||
User.with_user(user) do | ||
it "#retirement_check" do | ||
expect(MiqEvent).to receive(:raise_evm_event) | ||
@stack.update_attributes(:retires_on => 90.days.ago, :retirement_warn => 60, :retirement_last_warn => nil) | ||
expect(@stack.retirement_last_warn).to be_nil | ||
@stack.retirement_check | ||
@stack.reload | ||
expect(@stack.retirement_last_warn).not_to be_nil | ||
end | ||
end | ||
|
||
it "#start_retirement" do | ||
expect(@stack.retirement_state).to be_nil | ||
@stack.start_retirement | ||
@stack.reload | ||
expect(@stack.retirement_state).to eq("retiring") | ||
end | ||
|
||
it "#retire_now" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
@stack.retire_now | ||
@stack.reload | ||
end | ||
it "#start_retirement" do | ||
expect(@stack.retirement_state).to be_nil | ||
@stack.start_retirement | ||
@stack.reload | ||
expect(@stack.retirement_state).to eq("retiring") | ||
end | ||
|
||
it "#retire_now with userid" do | ||
expect(@stack.retirement_state).to be_nil | ||
event_name = 'request_orchestration_stack_retire' | ||
event_hash = {:orchestration_stack => @stack, :type => "OrchestrationStack", | ||
:retirement_initiator => "user", :userid => "freddy"} | ||
it "#retire_now" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
@stack.retire_now | ||
@stack.reload | ||
end | ||
|
||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
it "#retire_now with userid" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
|
||
@stack.retire_now('freddy') | ||
@stack.reload | ||
end | ||
@stack.retire_now('freddy') | ||
@stack.reload | ||
end | ||
|
||
it "#retire_now without userid" do | ||
expect(@stack.retirement_state).to be_nil | ||
event_name = 'request_orchestration_stack_retire' | ||
event_hash = {:orchestration_stack => @stack, :type => "OrchestrationStack", | ||
:retirement_initiator => "system"} | ||
it "#retire_now without userid" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
|
||
expect(OrchestrationStackRetireRequest).to_not receive(:make_request) | ||
@stack.retire_now | ||
@stack.reload | ||
end | ||
|
||
@stack.retire_now | ||
@stack.reload | ||
end | ||
it "#retire warn" do | ||
expect(AuditEvent).to receive(:success).once | ||
options = {} | ||
options[:warn] = 2.days.to_i | ||
@stack.retire(options) | ||
@stack.reload | ||
expect(@stack.retirement_warn).to eq(options[:warn]) | ||
end | ||
|
||
it "#retire warn" do | ||
expect(AuditEvent).to receive(:success).once | ||
options = {} | ||
options[:warn] = 2.days.to_i | ||
@stack.retire(options) | ||
@stack.reload | ||
expect(@stack.retirement_warn).to eq(options[:warn]) | ||
end | ||
it "#retire date" do | ||
expect(AuditEvent).to receive(:success).once | ||
options = {} | ||
options[:date] = Time.zone.today | ||
@stack.retire(options) | ||
@stack.reload | ||
expect(@stack.retires_on).to eq(options[:date]) | ||
end | ||
|
||
it "#retire date" do | ||
expect(AuditEvent).to receive(:success).once | ||
options = {} | ||
options[:date] = Time.zone.today | ||
@stack.retire(options) | ||
@stack.reload | ||
expect(@stack.retires_on).to eq(options[:date]) | ||
end | ||
it "#finish_retirement" do | ||
expect(@stack.retirement_state).to be_nil | ||
@stack.finish_retirement | ||
@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) | ||
expect(@stack.retirement_state).to eq("retired") | ||
end | ||
|
||
it "#finish_retirement" do | ||
expect(@stack.retirement_state).to be_nil | ||
@stack.finish_retirement | ||
@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) | ||
expect(@stack.retirement_state).to eq("retired") | ||
end | ||
it "#retiring - false" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(@stack.retiring?).to be_falsey | ||
end | ||
|
||
it "#retiring - false" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(@stack.retiring?).to be_falsey | ||
end | ||
it "#retiring - true" do | ||
@stack.update_attributes(:retirement_state => 'retiring') | ||
expect(@stack.retiring?).to be_truthy | ||
end | ||
|
||
it "#retiring - true" do | ||
@stack.update_attributes(:retirement_state => 'retiring') | ||
expect(@stack.retiring?).to be_truthy | ||
end | ||
it "#error_retiring - false" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(@stack.error_retiring?).to be_falsey | ||
end | ||
|
||
it "#error_retiring - false" do | ||
expect(@stack.retirement_state).to be_nil | ||
expect(@stack.error_retiring?).to be_falsey | ||
end | ||
it "#error_retiring - true" do | ||
@stack.update_attributes(:retirement_state => 'error') | ||
expect(@stack.error_retiring?).to be_truthy | ||
end | ||
|
||
it "#error_retiring - true" do | ||
@stack.update_attributes(:retirement_state => 'error') | ||
expect(@stack.error_retiring?).to be_truthy | ||
end | ||
it "#retires_on - today" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.retires_on = Time.zone.today | ||
expect(@stack.retirement_due?).to be_truthy | ||
end | ||
|
||
it "#retires_on - today" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.retires_on = Time.zone.today | ||
expect(@stack.retirement_due?).to be_truthy | ||
end | ||
it "#retires_on - tomorrow" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.retires_on = Time.zone.today + 1 | ||
expect(@stack.retirement_due?).to be_falsey | ||
end | ||
|
||
it "#retires_on - tomorrow" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.retires_on = Time.zone.today + 1 | ||
expect(@stack.retirement_due?).to be_falsey | ||
end | ||
it "#retirement_due?" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
|
||
it "#retirement_due?" do | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.update_attributes(:retires_on => Time.zone.today + 1.day) | ||
expect(@stack.retirement_due?).to be_falsey | ||
|
||
@stack.update_attributes(:retires_on => Time.zone.today + 1.day) | ||
expect(@stack.retirement_due?).to be_falsey | ||
@stack.update_attributes(:retires_on => Time.zone.today) | ||
expect(@stack.retirement_due?).to be_truthy | ||
|
||
@stack.update_attributes(:retires_on => Time.zone.today) | ||
expect(@stack.retirement_due?).to be_truthy | ||
@stack.update_attributes(:retires_on => Time.zone.today - 1.day) | ||
expect(@stack.retirement_due?).to be_truthy | ||
end | ||
|
||
@stack.update_attributes(:retires_on => Time.zone.today - 1.day) | ||
expect(@stack.retirement_due?).to be_truthy | ||
end | ||
it "#raise_retirement_event" do | ||
event_name = 'foo' | ||
event_hash = { | ||
:userid => nil, | ||
:orchestration_stack => @stack, | ||
:type => "OrchestrationStack", | ||
} | ||
|
||
it "#raise_retirement_event" do | ||
event_name = 'foo' | ||
event_hash = { | ||
:orchestration_stack => @stack, | ||
:type => "OrchestrationStack", | ||
:retirement_initiator => "system" | ||
} | ||
expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, :zone => @zone.name) | ||
@stack.raise_retirement_event(event_name) | ||
end | ||
|
||
expect(MiqEvent).to receive(:raise_evm_event).with(@stack, event_name, event_hash, {}) | ||
@stack.raise_retirement_event(event_name) | ||
it "#raise_audit_event" do | ||
event_name = 'foo' | ||
message = 'bar' | ||
event_hash = { | ||
:target_class => "OrchestrationStack", | ||
:target_id => @stack.id.to_s, | ||
:event => event_name, | ||
:message => message | ||
} | ||
expect(AuditEvent).to receive(:success).with(event_hash) | ||
@stack.raise_audit_event(event_name, message) | ||
end | ||
end | ||
|
||
it "#raise_audit_event" do | ||
event_name = 'foo' | ||
message = 'bar' | ||
event_hash = { | ||
:target_class => "OrchestrationStack", | ||
:target_id => @stack.id.to_s, | ||
:event => event_name, | ||
:message => message | ||
} | ||
expect(AuditEvent).to receive(:success).with(event_hash) | ||
@stack.raise_audit_event(event_name, message) | ||
context "without zone/ems" do | ||
it "#raise_retirement_event" do | ||
stack_without_zone = FactoryGirl.create(:orchestration_stack, :ext_management_system => nil) | ||
event_name = 'foo' | ||
event_hash = { | ||
:userid => nil, | ||
:orchestration_stack => stack_without_zone, | ||
:type => "OrchestrationStack", | ||
} | ||
|
||
expect(MiqEvent).to receive(:raise_evm_event).with(stack_without_zone, event_name, event_hash, {}) | ||
stack_without_zone.raise_retirement_event(event_name) | ||
end | ||
end | ||
end |
Oops, something went wrong.