-
Notifications
You must be signed in to change notification settings - Fork 120
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 #259 from pkomanek/refactoring_cloud_vm_retirement…
…_statemachines_methods_PreRetirement_method Refactoring cloud vm retirement pre_retirement method
- Loading branch information
Showing
3 changed files
with
71 additions
and
35 deletions.
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 |