@@ -28,7 +28,7 @@ def platform_to_cloud_request_parameters(platform, cloud, region, zone)
2828end
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
8485end
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 }
139140end
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)
159160action = params [ 'action' ]
160161vars = params [ 'vars' ]
161162node_name = params [ 'node_name' ]
163+ retry_attempts = params [ 'retry_attempts' ]
162164inventory_location = sanitise_inventory_location ( params [ 'inventory' ] )
163165
164166begin
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