-
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 #319 from pkomanek/refactoring_cloud_vm_retirement…
…_statemachines_methods_DeleteFromVmdb_method Refactoring cloud vm retirement delete_from_vmdb method
- Loading branch information
Showing
2 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
35 changes: 30 additions & 5 deletions
35
.../ManageIQ/Cloud/VM/Retirement/StateMachines/Methods.class/__methods__/delete_from_vmdb.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,11 +1,36 @@ | ||
# | ||
# Description: This method removes the VM from the VMDB database | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module VM | ||
module Retirement | ||
module StateMachines | ||
module Methods | ||
class DeleteFromVmdb | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
vm = $evm.root['vm'] | ||
def main | ||
vm = @handle.root['vm'] | ||
|
||
if vm && $evm.get_state_var('vm_removed_from_provider') | ||
$evm.log('info', "Removing VM <#{vm.name}> from VMDB") | ||
vm.remove_from_vmdb | ||
$evm.root['vm'] = nil | ||
if vm && @handle.get_state_var('vm_removed_from_provider') | ||
@handle.log('info', "Removing VM <#{vm.name}> from VMDB") | ||
vm.remove_from_vmdb | ||
@handle.root['vm'] = nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if $PROGRAM_NAME == __FILE__ | ||
ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::DeleteFromVmdb.new.main | ||
end |
37 changes: 37 additions & 0 deletions
37
...geIQ/Cloud/VM/Retirement/StateMachines/Methods.class/__methods__/delete_from_vmdb_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,37 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::VM::Retirement::StateMachines::Methods::DeleteFromVmdb 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 'removes vm from vmdb' do | ||
ae_service.set_state_var('vm_removed_from_provider', true) | ||
expect(svc_vm).to(receive(:remove_from_vmdb)) | ||
described_class.new(ae_service).main | ||
end | ||
|
||
context 'does not remove vm from vmdb' do | ||
it '#nil vm' do | ||
root_hash['vm'] = nil | ||
expect(ae_service).not_to(receive(:log)) | ||
described_class.new(ae_service).main | ||
end | ||
|
||
it '#without vm_removed_from_provider state_var' do | ||
expect(svc_vm).not_to(receive(:remove_from_provider)) | ||
expect(ae_service).not_to(receive(:log)) | ||
described_class.new(ae_service).main | ||
end | ||
end | ||
end |