-
Notifications
You must be signed in to change notification settings - Fork 121
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 #320 from pkomanek/refactoring_cloud_vm_retirement…
…_statemachines_methods_CheckRemovedFromProvider_method Refactoring cloud vm retirement check_removed_from_provider method
- Loading branch information
Showing
3 changed files
with
62 additions
and
36 deletions.
There are no files selected for viewing
40 changes: 32 additions & 8 deletions
40
...loud/VM/Retirement/StateMachines/Methods.class/__methods__/check_removed_from_provider.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,15 +1,39 @@ | ||
# | ||
# Description: This method checks to see if the VM has been removed from the provider | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module VM | ||
module Retirement | ||
module StateMachines | ||
module Methods | ||
class CheckRemovedFromProvider | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
vm = $evm.root['vm'] | ||
def main | ||
vm = @handle.root['vm'] | ||
@handle.root['ae_result'] = 'ok' | ||
|
||
$evm.root['ae_result'] = 'ok' | ||
|
||
if vm && $evm.get_state_var('vm_removed_from_provider') | ||
if vm.ext_management_system | ||
vm.refresh | ||
$evm.root['ae_result'] = 'retry' | ||
$evm.root['ae_retry_interval'] = '1.minute' | ||
if vm && @handle.get_state_var('vm_removed_from_provider') | ||
if vm.ext_management_system | ||
vm.refresh | ||
@handle.root['ae_result'] = 'retry' | ||
@handle.root['ae_retry_interval'] = '1.minute' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::CheckRemovedFromProvider.new.main | ||
end |
28 changes: 0 additions & 28 deletions
28
spec/automation/unit/method_validation/check_removed_from_provider_spec.rb
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...VM/Retirement/StateMachines/Methods.class/__methods__/check_removed_from_provider_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,30 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::CheckRemovedFromProvider do | ||
let(:svc_vm) { MiqAeMethodService::MiqAeServiceVm.find(vm.id) } | ||
let(:ems) { FactoryGirl.create(:ems_vmware) } | ||
let(:vm) { FactoryGirl.create(:vm_vmware, :ems_id => ems.id) } | ||
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) } | ||
let(:root_hash) { { 'vm' => svc_vm } } | ||
|
||
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 "returns 'ok'" do | ||
described_class.new(ae_service).main | ||
expect(ae_service.root['ae_result']).to(eq('ok')) | ||
end | ||
|
||
it "returns 'retry'" do | ||
ae_service.set_state_var('vm_removed_from_provider', true) | ||
allow(svc_vm).to receive(:refresh) | ||
described_class.new(ae_service).main | ||
expect(ae_service.root['ae_result']).to(eq('retry')) | ||
expect(ae_service.root['ae_retry_interval']).to(eq('1.minute')) | ||
end | ||
end |