-
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 pre_retirement method #259
Merged
mkanoor
merged 2 commits into
ManageIQ:master
from
pkomanek:refactoring_cloud_vm_retirement_statemachines_methods_PreRetirement_method
Jun 5, 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
37 changes: 32 additions & 5 deletions
37
...te/ManageIQ/Cloud/VM/Retirement/StateMachines/Methods.class/__methods__/pre_retirement.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,10 +1,37 @@ | ||
# | ||
# Description: This method stops a cloud Instance | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module VM | ||
module Retirement | ||
module StateMachines | ||
module Methods | ||
class PreRetirement | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
vm = $evm.root['vm'] | ||
if vm && vm.power_state == 'on' | ||
ems = vm.ext_management_system | ||
$evm.log('info', "Stopping Instance <#{vm.name}> in EMS <#{ems.try(:name)}>") | ||
vm.stop if ems | ||
def main | ||
vm = @handle.root['vm'] | ||
if vm && vm.power_state == 'on' | ||
ems = vm.ext_management_system | ||
if ems | ||
@handle.log('info', "Stopping Instance <#{vm.name}> in EMS <#{ems.name}>") | ||
vm.stop | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::PreRetirement.new.main | ||
end |
30 changes: 0 additions & 30 deletions
30
spec/automation/unit/method_validation/pre_retirement_spec.rb
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...nageIQ/Cloud/VM/Retirement/StateMachines/Methods.class/__methods__/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,39 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::PreRetirement do | ||
let(:svc_vm) { MiqAeMethodService::MiqAeServiceVm.find(vm.id) } | ||
let(:ems) { FactoryGirl.create(:ems_microsoft) } | ||
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) } | ||
let(:root_hash) { { 'vm' => svc_vm } } | ||
let(:vm) do | ||
FactoryGirl.create(:vm_microsoft, :ems_id => ems.id) | ||
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 | ||
|
||
it 'powers off a vm in a \'powered_on\' state' do | ||
expect(svc_vm).to receive(:stop) | ||
described_class.new(ae_service).main | ||
end | ||
|
||
it 'does not stop a vm in \'powered_off\' state' do | ||
vm.update_attributes(:raw_power_state => "PowerOff") | ||
expect(svc_vm).to_not receive(:stop) | ||
described_class.new(ae_service).main | ||
end | ||
|
||
context 'nil ems' do | ||
let(:vm) { FactoryGirl.create(:vm_microsoft) } | ||
|
||
it 'does not stop a vm without ems' do | ||
expect(svc_vm).to_not receive(:stop) | ||
described_class.new(ae_service).main | ||
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.
@tinaafitz if the ems is missing and the vm is powered on, should we be raising an exception and stopping the workflow or should we keep continuing. I remember we had some corner cases that we were trying to solve where a failed retirement is restarted. If there is no ems should we log the fact that its an orphaned vm.
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.
@mkanoor We should continue processing if the ems is nil and the VM will have the power state of "unknown" in that case