Skip to content
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 check_removed_from_provider method #320

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

This file was deleted.

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