Skip to content

Commit

Permalink
Merge pull request #148 from billfitzgerald0120/timetolive
Browse files Browse the repository at this point in the history
Support TTL (Time To Live) value for services.
(cherry picked from commit 148e5a6)

https://bugzilla.redhat.com/show_bug.cgi?id=1479407
  • Loading branch information
gmcculloug authored and simaishi committed Aug 8, 2017
1 parent f7c06ed commit e972d62
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Generic
module StateMachines
module GenericLifecycle
class Start
MIN_RETRY_INTERVAL = 1.minute
def initialize(handle = $evm)
@handle = handle
end
Expand All @@ -17,6 +18,7 @@ def main
@handle.log('info', msg)
@handle.create_notification(:level => 'info', :subject => service, :message => msg)
@handle.root['ae_result'] = 'ok'
retry_interval
end

private
Expand All @@ -30,6 +32,22 @@ def service
end
end

def execution_ttl
service.options[:config_info][service_action.downcase.to_sym][:execution_ttl].to_i
end

def retry_interval
ttl = execution_ttl
max_retry_count = @handle.root['ae_state_max_retries']
return if ttl.zero? || max_retry_count.zero?

interval = ttl / max_retry_count
if interval > MIN_RETRY_INTERVAL
@handle.log('info', "Setting retry interval to #{interval} time to live #{ttl} / #{max_retry_count}")
@handle.root['ae_retry_interval'] = interval
end
end

def service_action
@handle.root["service_action"].tap do |action|
unless %w(Provision Retirement Reconfigure).include?(action)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,106 @@
require_domain_file

describe ManageIQ::Automate::Service::Generic::StateMachines::GenericLifecycle::Start do
let(:admin) { FactoryGirl.create(:user_admin) }
let(:request) { FactoryGirl.create(:service_template_provision_request, :requester => admin) }
let(:ansible_tower_manager) { FactoryGirl.create(:automation_manager) }
let(:job_template) { FactoryGirl.create(:ansible_configuration_script, :manager => ansible_tower_manager) }
let(:service_ansible_tower) { FactoryGirl.create(:service_ansible_tower, :job_template => job_template) }
let(:task) { FactoryGirl.create(:service_template_provision_task, :destination => service_ansible_tower, :miq_request => request) }
let(:svc_task) { MiqAeMethodService::MiqAeServiceServiceTemplateProvisionTask.find(task.id) }
let(:request) { FactoryGirl.create(:service_template_provision_request, :requester => FactoryGirl.create(:user_admin)) }
let(:job_template) { FactoryGirl.create(:ansible_configuration_script, :manager => FactoryGirl.create(:automation_manager)) }
let(:service_ansible_tower) { FactoryGirl.create(:service_ansible_tower, :job_template => job_template, :options => config_info_options) }
let(:svc_service) { MiqAeMethodService::MiqAeServiceServiceAnsibleTower.find(service_ansible_tower.id) }
let(:root_object) { Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Provision') }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Provision',
'ae_state_max_retries' => 100)
end
let(:ae_service) { Spec::Support::MiqAeMockService.new(root_object) }
let(:config_info_options) do
{
:config_info => {
:provision => {
:execution_ttl => ttl
},
:retirement => {
:execution_ttl => ttl
}
}
}
end

context "Start" do
it "creates notification " do
shared_examples_for "#ttl" do
it "check" do
allow(ae_service).to receive(:create_notification)

described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq("ok")
expect(ae_service.root['ae_retry_interval']).to eq(ae_retry_interval)
end
end

context "Start 7700 ttl, 100 retries eq interval 77" do
let(:ae_retry_interval) { 77 }
let(:ttl) { 7700 }
it_behaves_like "#ttl"
end

context "Start 60000 ttl, 100 retries eq interval 600" do
let(:ae_retry_interval) { 600 }
let(:ttl) { 60_000 }
it_behaves_like "#ttl"
end

context "Start 600 ttl, 100 retries interval nil" do
let(:ae_retry_interval) { nil }
let(:ttl) { 600 }
it_behaves_like "#ttl"
end

context "Start 0 ttl, 100 retries, interval nil" do
let(:ae_retry_interval) { nil }
let(:ttl) { 0 }
it_behaves_like "#ttl"
end

context "Start retirement tests, " do
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Retirement', 'ae_state_max_retries' => 100)
end

context " 7700 ttl, 100 retries eq interval 77" do
let(:ae_retry_interval) { 77 }
let(:ttl) { 7700 }
it_behaves_like "#ttl"
end

context " 60000 ttl, 100 retries eq interval 600" do
let(:ae_retry_interval) { 600 }
let(:ttl) { 60_000 }
it_behaves_like "#ttl"
end

context " 600 ttl, 100 retries eq interval nil" do
let(:ae_retry_interval) { nil }
let(:ttl) { 600 }
it_behaves_like "#ttl"
end

context " 0 ttl, 100 retries, interval nil" do
let(:ae_retry_interval) { nil }
let(:ttl) { 0 }
it_behaves_like "#ttl"
end
end

context "Start 6000 ttl, 50 retries eq interval 120" do
let(:ae_retry_interval) { 120 }
let(:ttl) { 6000 }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Provision', 'ae_state_max_retries' => 50)
end
it_behaves_like "#ttl"
end

context "Start 6000 ttl, 0 retries eq interval nil" do
let(:ae_retry_interval) { nil }
let(:ttl) { 6000 }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Provision', 'ae_state_max_retries' => 0)
end
it_behaves_like "#ttl"
end
end

0 comments on commit e972d62

Please sign in to comment.