Skip to content

Commit 4beb5aa

Browse files
authored
Merge pull request #194 from BartoszBlizniak/main
(SUP-2952) (Issue #193) - Retry if provisioning target returns a 500
2 parents 8074e50 + 1c706db commit 4beb5aa

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

.fixtures.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fixtures:
22
repositories:
3-
"facts": "git://github.com/puppetlabs/puppetlabs-facts.git"
4-
"puppet_agent": "git://github.com/puppetlabs/puppetlabs-puppet_agent.git"
5-
"puppet_conf": "git://github.com/puppetlabs/puppetlabs-puppet_conf.git"
3+
"facts": "https://github.com/puppetlabs/puppetlabs-facts.git"
4+
"puppet_agent": "https://github.com/puppetlabs/puppetlabs-puppet_agent.git"
5+
"puppet_conf": "https://github.com/puppetlabs/puppetlabs-puppet_conf.git"
66
symlinks:
77
"provision": "#{source_dir}"

pdk.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
ignore: []

tasks/provision_service.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"vars": {
2424
"description": "The address of the provisioning service",
2525
"type": "Optional[String[1]]"
26+
},
27+
"retry_attempts": {
28+
"description": "The number of times to retry the provisioning if it fails",
29+
"type": "Optional[Integer[1]]",
30+
"default": 5
2631
}
2732
},
2833
"files": [

tasks/provision_service.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def platform_to_cloud_request_parameters(platform, cloud, region, zone)
2828
end
2929

3030
# curl -X POST https://facade-validation-6f3kfepqcq-ew.a.run.app/v1/provision --data @test_machines.json
31-
def invoke_cloud_request(params, uri, job_url, verb)
31+
def invoke_cloud_request(params, uri, job_url, verb, retry_attempts)
3232
headers = {
3333
'Accept' => 'application/json',
3434
'Content-Type' => 'application/json',
@@ -62,6 +62,7 @@ def invoke_cloud_request(params, uri, job_url, verb)
6262
req_options = {
6363
use_ssl: uri.scheme == 'https',
6464
read_timeout: 60 * 5, # timeout reads after 5 minutes - that's longer than the backend service would keep the request open
65+
max_retries: retry_attempts, # retry up to 5 times before throwing an error
6566
}
6667

6768
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
@@ -83,7 +84,7 @@ def invoke_cloud_request(params, uri, job_url, verb)
8384
# rubocop:enable Style/GuardClause
8485
end
8586

86-
def provision(platform, inventory_location, vars)
87+
def provision(platform, inventory_location, vars, retry_attempts)
8788
# Call the provision service with the information necessary and write the inventory file locally
8889

8990
if ENV['GITHUB_RUN_ID']
@@ -102,7 +103,7 @@ def provision(platform, inventory_location, vars)
102103
inventory_full_path = File.join(inventory_location, '/spec/fixtures/litmus_inventory.yaml')
103104

104105
params = platform_to_cloud_request_parameters(platform, cloud, region, zone)
105-
response = invoke_cloud_request(params, uri, job_url, 'post')
106+
response = invoke_cloud_request(params, uri, job_url, 'post', retry_attempts)
106107
response_hash = YAML.safe_load(response)
107108

108109
unless vars.nil?
@@ -138,7 +139,7 @@ def provision(platform, inventory_location, vars)
138139
}
139140
end
140141

141-
def tear_down(platform, inventory_location, _vars)
142+
def tear_down(platform, inventory_location, _vars, retry_attempts)
142143
# remove all provisioned resources
143144
uri = URI.parse(ENV['SERVICE_URL'] || default_uri)
144145

@@ -148,7 +149,7 @@ def tear_down(platform, inventory_location, _vars)
148149
inventory_hash = inventory_hash_from_inventory_file(inventory_full_path)
149150
facts = facts_from_node(inventory_hash, platform)
150151
job_id = facts['uuid']
151-
response = invoke_cloud_request(job_id, uri, '', 'delete')
152+
response = invoke_cloud_request(job_id, uri, '', 'delete', retry_attempts)
152153
response.to_json
153154
end
154155
# rubocop:enable Style/GuardClause
@@ -159,16 +160,17 @@ def tear_down(platform, inventory_location, _vars)
159160
action = params['action']
160161
vars = params['vars']
161162
node_name = params['node_name']
163+
retry_attempts = params['retry_attempts']
162164
inventory_location = sanitise_inventory_location(params['inventory'])
163165

164166
begin
165167
case action
166168
when 'provision'
167169
raise 'specify a platform when provisioning' if platform.nil?
168-
result = provision(platform, inventory_location, vars)
170+
result = provision(platform, inventory_location, vars, retry_attempts)
169171
when 'tear_down'
170172
raise 'specify a node_name when tearing down' if node_name.nil?
171-
result = tear_down(node_name, inventory_location, vars)
173+
result = tear_down(node_name, inventory_location, vars, retry_attempts)
172174
else
173175
result = { _error: { kind: 'provision_service/argument_error', msg: "Unknown action '#{action}'" } }
174176
end

0 commit comments

Comments
 (0)