-
Notifications
You must be signed in to change notification settings - Fork 120
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
Refactoring cloud vm retirement amazon_check_pre_retirement method #325
Merged
mkanoor
merged 2 commits into
ManageIQ:master
from
pkomanek:refactoring_cloud_vm_retirement_statemachines_methods_AmazonCheckPreRetirement_method
Jul 9, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 0 additions & 48 deletions
48
spec/automation/unit/method_validation/amazon_check_pre_retirement_spec.rb
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
...VM/Retirement/StateMachines/Methods.class/__methods__/amazon_check_pre_retirement_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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::AmazonCheckPreRetirement do | ||
let(:svc_vm) { MiqAeMethodService::MiqAeServiceVm.find(vm.id) } | ||
let(:ems) { FactoryGirl.create(:ems_amazon, :name => 'testEmsAmazon') } | ||
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) } | ||
let(:root_hash) { { 'vm' => svc_vm } } | ||
let(:vm) do | ||
FactoryGirl.create(:vm_amazon, :ems_id => ems.id, | ||
:name => 'testVmAmazon', | ||
:raw_power_state => "running", | ||
:registered => true) | ||
end | ||
let(:ebs_hardware) do | ||
FactoryGirl.create(:hardware, :bitness => 64, | ||
:virtualization_type => 'paravirtual', | ||
:root_device_type => 'ebs') | ||
end | ||
let(:is_hardware) do | ||
FactoryGirl.create(:hardware, :bitness => 64, | ||
:virtualization_type => 'paravirtual', | ||
:root_device_type => 'instance-store') | ||
end | ||
let(:ae_service) do | ||
Spec::Support::MiqAeMockService.new(root_object).tap do |service| | ||
current_object = Spec::Support::MiqAeMockObject.new | ||
current_object.parent = root_object | ||
service.object = current_object | ||
end | ||
end | ||
|
||
shared_examples_for "ae_method" do |ae_result, vm_power_state, ae_retry_interval| | ||
it "has valid output" do | ||
described_class.new(ae_service).main | ||
expect(ae_service.root['ae_result']).to eq(ae_result) if ae_result | ||
expect(ae_service.root['vm'].power_state).to eq(vm_power_state) if vm_power_state | ||
expect(ae_service.root['ae_retry_interval']).to eq(ae_retry_interval) if ae_retry_interval | ||
end | ||
end | ||
|
||
context "returns 'ok' for instance store instances even with power on" do | ||
before { vm.hardware = is_hardware } | ||
it_behaves_like 'ae_method', 'ok', 'on' | ||
end | ||
|
||
context "returns 'retry' for running ebs instances" do | ||
before do | ||
vm.hardware = ebs_hardware | ||
expect(svc_vm).to(receive(:refresh)) | ||
end | ||
it_behaves_like 'ae_method', 'retry', 'on', '60.seconds' | ||
end | ||
|
||
context "returns 'ok' for stopped ebs instances" do | ||
let(:vm) do | ||
FactoryGirl.create(:vm_amazon, :ems_id => ems.id, | ||
:raw_power_state => "off", | ||
:registered => true, | ||
:hardware => ebs_hardware) | ||
end | ||
it_behaves_like 'ae_method', 'ok', 'off' | ||
end | ||
|
||
context "returns 'ok' for ebs instance with unknown power state" do | ||
let(:vm) do | ||
FactoryGirl.create(:vm_amazon, :ems_id => ems.id, | ||
:raw_power_state => "unknown", | ||
:registered => true, | ||
:hardware => ebs_hardware) | ||
end | ||
it_behaves_like 'ae_method', 'ok', 'terminated' | ||
end | ||
|
||
context "returns 'error' for VM template" do | ||
let(:vm) do | ||
FactoryGirl.create(:template_amazon, :ems_id => ems.id, | ||
:hardware => ebs_hardware) | ||
end | ||
let(:svc_vm) { MiqAeMethodService::MiqAeServiceVmOrTemplate.find(vm.id) } | ||
|
||
it "raise error with template" do | ||
expect { described_class.new(ae_service).main }.to(raise_error('Trying to power off a template')) | ||
expect(ae_service.root['ae_result']).to(eq('error')) | ||
end | ||
end | ||
|
||
context "skips check" do | ||
before do | ||
message = "Skipping check pre retirement for Instance:"\ | ||
"<#{vm.try(:name)}> on EMS:<#{ems.try(:name)}>" | ||
expect(ae_service).to(receive(:log).with('info', message)) | ||
end | ||
|
||
context '#nil vm' do | ||
let(:vm) {} | ||
let(:svc_vm) {} | ||
let(:ems) {} | ||
it_behaves_like 'ae_method' | ||
end | ||
|
||
context '#nil ems' do | ||
let(:vm) { FactoryGirl.create(:vm_amazon, :name => 'testVmAmazon') } | ||
let(:ems) {} | ||
it_behaves_like 'ae_method' | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkomanek Should we raise an error here if someone is trying to power off a template?