forked from ManageIQ/manageiq-content
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ManageIQ#91 from pkomanek/refactoring_cloud_orches…
…tration_retirement_delete_from_vmdb_method Refactoring cloud orchestration retirement delete_from_vmdb method (cherry picked from commit 3a9bd0a)
- Loading branch information
Showing
2 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
36 changes: 31 additions & 5 deletions
36
...loud/Orchestration/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,37 @@ | ||
# | ||
# Description: This method removes the stack from the VMDB database | ||
# | ||
module ManageIQ | ||
module Automate | ||
module Cloud | ||
module Orchestration | ||
module Retirement | ||
module StateMachines | ||
module Methods | ||
class DeleteFromVmdb | ||
|
||
stack = $evm.root['orchestration_stack'] | ||
def initialize(handle = $evm) | ||
@handle = handle | ||
end | ||
|
||
if stack && !$evm.get_state_var('stack_exists_in_provider') | ||
$evm.log('info', "Removing stack <#{stack.name}> from VMDB") | ||
stack.remove_from_vmdb | ||
$evm.root['orchestration_stack'] = nil | ||
def main | ||
stack = @handle.root['orchestration_stack'] | ||
|
||
if stack && !@handle.get_state_var('stack_exists_in_provider') | ||
@handle.log('info', "Removing stack <#{stack.name}> from VMDB") | ||
stack.remove_from_vmdb | ||
@handle.root['orchestration_stack'] = nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
if __FILE__ == $PROGRAM_NAME | ||
ManageIQ::Automate::Cloud::Orchestration::Retirement::StateMachines::Methods::DeleteFromVmdb.new.main | ||
end |
33 changes: 33 additions & 0 deletions
33
...Orchestration/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,33 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::Cloud::Orchestration::Retirement::StateMachines::Methods::DeleteFromVmdb do | ||
let(:stack) { FactoryGirl.create(:orchestration_stack_amazon) } | ||
let(:service_orchestration) { FactoryGirl.create(:service_orchestration) } | ||
let(:svc_model_service) { MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) } | ||
let(:svc_model_stack) { MiqAeMethodService::MiqAeServiceOrchestrationStack.find(stack.id) } | ||
|
||
let(:root_hash) do | ||
{ 'service_template' => MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) } | ||
end | ||
|
||
let(:root_object) do | ||
obj = Spec::Support::MiqAeMockObject.new(root_hash) | ||
obj["orchestration_stack"] = svc_model_stack | ||
obj | ||
end | ||
|
||
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 stack from vmdb" do | ||
ae_service.set_state_var('stack_exists_in_provider', false) | ||
described_class.new(ae_service).main | ||
|
||
expect(ae_service.root['orchestration_stack']).to eq(nil) | ||
end | ||
end |