Skip to content

Commit

Permalink
Merge pull request #317 from pkomanek/refactoring_cloud_vm_retirement…
Browse files Browse the repository at this point in the history
…_statemachines_methods_FinishRetirement_method

Refactoring cloud vm retirement finish_retirement method
  • Loading branch information
mkanoor authored Jun 5, 2018
2 parents a91443d + c14388d commit 91aa05b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#
# Description: This method marks the VM as retired
#
module ManageIQ
module Automate
module Cloud
module VM
module Retirement
module StateMachines
module Methods
class FinishRetirement
def initialize(handle = $evm)
@handle = handle
end

vm = $evm.root['vm']
vm.finish_retirement if vm
$evm.create_notification(:type => :vm_retired, :subject => vm) if vm
def main
vm = @handle.root['vm']
if vm
vm.finish_retirement
@handle.create_notification(:type => :vm_retired, :subject => vm)
end
end
end
end
end
end
end
end
end
end

if $PROGRAM_NAME == __FILE__
ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::FinishRetirement.new.main
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_domain_file

describe ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::FinishRetirement 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 "retires vm" do
expect(svc_vm).to receive(:finish_retirement)
expect(ae_service).to receive(:create_notification).with(:type => :vm_retired, :subject => svc_vm)
described_class.new(ae_service).main
end

describe "doesn't retire vm" do
let(:root_hash) {}

it 'vm is nil' do
expect(ae_service).not_to receive(:create_notification)
described_class.new(ae_service).main
end
end
end

0 comments on commit 91aa05b

Please sign in to comment.