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

Refactor finish_retirement method for Infra VM Retirement. #599

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,7 +1,32 @@
#
##
# Description: This method marks the VM as retired
#
module ManageIQ
module Automate
module Infrastructure
module VM
module Retirement
module StateMachines
module Methods
class FinishRetirement
def initialize(handle = $evm)
@handle = handle
end

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

vm = $evm.root['vm']
vm.finish_retirement if vm
$evm.create_notification(:type => :vm_retired, :subject => vm) if vm
ManageIQ::Automate::Infrastructure::VM::Retirement::StateMachines::Methods::FinishRetirement.new.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_domain_file

describe ManageIQ::Automate::Infrastructure::VM::Retirement::StateMachines::Methods::FinishRetirement do
let(:svc_vm) { MiqAeMethodService::MiqAeServiceVm.find(vm.id) }
let(:ems) { FactoryBot.create(:ems_vmware) }
let(:vm) { FactoryBot.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