Skip to content

Commit

Permalink
Merge pull request #162 from billfitzgerald0120/check_completed
Browse files Browse the repository at this point in the history
Support TTL (Time To Live) value for services.
  • Loading branch information
gmcculloug authored Aug 9, 2017
2 parents 6e7535b + 220fa1e commit 7d66b4b
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Generic
module StateMachines
module GenericLifecycle
class CheckCompleted
MIN_RETRY_INTERVAL = 1
def initialize(handle = $evm)
@handle = handle
end
Expand Down Expand Up @@ -42,6 +43,23 @@ def service_action
end
end

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

def retry_interval
@handle.root['ae_retry_interval'] = 1.minute
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.minutes
end
end

def check_completed(service)
done, message = service.check_completed(service_action)
if done
Expand All @@ -55,7 +73,7 @@ def check_completed(service)
end
else
@handle.root['ae_result'] = 'retry'
@handle.root['ae_retry_interval'] = 1.minute
retry_interval
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@
it_behaves_like "check_completed"
end

context "returns retry when job launching is not done" do
let(:status_and_message) { [false, "retry"] }
let(:ae_result) { "retry" }
it_behaves_like "check_completed"
end

context "invalid service_action" do
let(:status_and_message) { [true, ""] }
let(:errormsg) { 'Invalid service_action' }
Expand All @@ -71,4 +65,93 @@
end
it_behaves_like "check_completed_error"
end

context "retry ttl" do
let(:service_ansible_tower) { FactoryGirl.create(:service_ansible_tower, :job_template => job_template, :options => config_info_options) }
let(:config_info_options) do
{
:config_info => {
:provision => {
:execution_ttl => ttl
},
:retirement => {
:execution_ttl => ttl
}
}
}
end
shared_examples_for "#ttl" do
it "check" do
allow(svc_service).to receive(:check_completed).and_return([false, "retry"])

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

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

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

context "60 ttl, 100 retries interval 1.minute" do
let(:ae_retry_interval) { 1.minute }
let(:ttl) { 60 }
it_behaves_like "#ttl"
end

context "0 ttl, 100 retries, interval 1.minute" do
let(:ae_retry_interval) { 1.minute }
let(:ttl) { 0 }
it_behaves_like "#ttl"
end
end
context "Retirement tests " do
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Retirement', 'ae_state_max_retries' => 100)
end

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

context "60 ttl, 100 retries interval 1.minute" do
let(:ae_retry_interval) { 1.minute }
let(:ttl) { 60 }
it_behaves_like "#ttl"
end

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

context "Start 600 ttl, 50 retries eq interval 6" do
let(:ae_retry_interval) { 12.minutes }
let(:ttl) { 600 }
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 600 ttl, 0 retries eq interval 1.minute" do
let(:ae_retry_interval) { 1.minute }
let(:ttl) { 600 }
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
end

0 comments on commit 7d66b4b

Please sign in to comment.