Skip to content

Commit

Permalink
Merge pull request ManageIQ#90 from pkomanek/refactoring_cloud_orches…
Browse files Browse the repository at this point in the history
…tration_retirement_check_removed_from_provider_method

Refactoring cloud orchestration retirement check_removed_from_provider method
  • Loading branch information
mkanoor authored Apr 28, 2017
2 parents 4bf5377 + 891b96a commit 222bb65
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
#
# Description: This method checks to see if the stack has been removed from the provider
#
$evm.root['ae_result'] = 'ok'
stack = $evm.root['orchestration_stack']
$evm.log("info", "Checking stack #{stack.try(:name)} removed from provider")
module ManageIQ
module Automate
module Cloud
module Orchestration
module Retirement
module StateMachines
module Methods
class CheckRemovedFromProvider

if stack && $evm.get_state_var('stack_exists_in_provider')
begin
status, _reason = stack.normalized_live_status
if status == 'not_exist' || status == 'delete_complete'
$evm.set_state_var('stack_exists_in_provider', false)
else
$evm.root['ae_result'] = 'retry'
$evm.root['ae_retry_interval'] = '1.minute'
def initialize(handle = $evm)
@handle = handle
end

def main
@handle.root['ae_result'] = 'ok'
stack = @handle.root['orchestration_stack']

if stack && @handle.get_state_var('stack_exists_in_provider')
begin
status, _reason = stack.normalized_live_status
if status == 'not_exist' || status == 'delete_complete'
@handle.set_state_var('stack_exists_in_provider', false)
else
@handle.root['ae_result'] = 'retry'
@handle.root['ae_retry_interval'] = '1.minute'
end
rescue => e
@handle.root['ae_result'] = 'error'
@handle.root['ae_reason'] = e.message
end
end
end
end
end
end
end
end
end
rescue => e
$evm.root['ae_result'] = 'error'
$evm.root['ae_reason'] = e.message
end
end

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

describe ManageIQ::Automate::Cloud::Orchestration::Retirement::StateMachines::Methods::CheckRemovedFromProvider 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

before do
ae_service.set_state_var('stack_exists_in_provider', 'stack_exists_in_provider_value')
end

it "sets ae_result to ok" do
allow(svc_model_stack).to receive(:normalized_live_status) { %w(not_exist reason) }
described_class.new(ae_service).main

expect(ae_service.root['ae_result']).to eq('ok')
expect(ae_service.get_state_var('stack_exists_in_provider')).to eq(false)
end

it "sets ae_result to retry" do
allow(svc_model_stack).to receive(:normalized_live_status) { %w(status reason) }
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

it "sets ae_result to error" do
allow(svc_model_stack).to receive(:normalized_live_status) { raise 'Exception!' }
described_class.new(ae_service).main

expect(ae_service.root['ae_result']).to eq('error')
expect(ae_service.root['ae_reason']).to eq('Exception!')
end
end

0 comments on commit 222bb65

Please sign in to comment.