Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions libpermian/plugins/testing_farm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def execute(self):

try:
self.request_id = self.submit_test()
except requests.HTTPError as e:
LOGGER.error(f'Can\'t submit test {e}')
except requests.RequestException as e:
LOGGER.error(f'Can\'t submit test: {e}')
self.reportResult(Result('not started', 'ERROR', final=True))
return

Expand Down Expand Up @@ -174,8 +174,8 @@ def execute(self):
elif state in state2state_map and self.crc.result.state != state2state_map[state]:
self.reportResult(Result(state2state_map[state]))

except requests.HTTPError as e:
LOGGER.error(f'Can\'t get test status {e}')
except requests.RequestException as e:
LOGGER.error(f'Can\'t get test status: {e}')
status_attempts += 1
if status_attempts == self.max_status_retry:
self.reportResult(Result('DNF', 'ERROR', final=True))
Expand Down Expand Up @@ -220,7 +220,7 @@ def terminate(self):
self.delete_request()
self.reportResult(Result('canceled', None, final=True))
return True
except requests.HTTPError as e:
except requests.RequestException as e:
LOGGER.error(f"Test termination failed: {e}")
self.reportResult(Result('canceled', 'ERROR', final=True))
return False
Expand Down Expand Up @@ -250,13 +250,15 @@ def submit_test(self):
"""
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.api_token}"
"Authorization": f"Bearer {self.api_token}",
"Connection": "close"
}

response = requests.post(
f"{self.api_url}/requests",
headers=headers,
json=self.payload
json=self.payload,
timeout=(10, 60)
)
response.raise_for_status()

Expand All @@ -274,12 +276,14 @@ def get_status(self):
requests.HTTPError: If the API request fails.
"""
headers = {
"Authorization": f"Bearer {self.api_token}"
"Authorization": f"Bearer {self.api_token}",
"Connection": "close"
}

response = requests.get(
f"{self.api_url}/requests/{self.request_id}",
headers=headers
headers=headers,
timeout=(10, 30)
)
response.raise_for_status()

Expand All @@ -293,12 +297,14 @@ def delete_request(self):
requests.HTTPError: If the cancellation request fails.
"""
headers = {
"Authorization": f"Bearer {self.api_token}"
"Authorization": f"Bearer {self.api_token}",
"Connection": "close"
}

response = requests.delete(
f"{self.api_url}/requests/{self.request_id}",
headers=headers
headers=headers,
timeout=(10, 30)
)
response.raise_for_status()

Expand All @@ -312,9 +318,9 @@ def collect_artifacts(self, artifacts_url):
artifacts_url (str): URL to the artifacts directory listing.
"""
try:
response = requests.get(artifacts_url)
response = requests.get(artifacts_url, timeout=(10, 30))
response.raise_for_status()
except requests.HTTPError as e:
except requests.RequestException as e:
LOGGER.error(f"Can\'t collect artifacts: {e}")
return

Expand Down
8 changes: 6 additions & 2 deletions libpermian/plugins/testing_farm/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def test_submit_test_success(self, mock_post):
call_args = mock_post.call_args
self.assertEqual(call_args[0][0], 'https://api.testing-farm.io/v0.1/requests')
self.assertEqual(call_args[1]['headers']['Authorization'], 'Bearer test-token')
self.assertEqual(call_args[1]['headers']['Connection'], 'close')
self.assertEqual(call_args[1]['json'], workflow.payload)
self.assertEqual(call_args[1]['timeout'], (10, 60))


@patch('libpermian.plugins.testing_farm.requests.get')
Expand All @@ -156,7 +158,8 @@ def test_get_status(self, mock_get):
self.assertEqual(status['state'], 'running')
mock_get.assert_called_once_with(
'https://api.testing-farm.io/v0.1/requests/request-123',
headers={'Authorization': 'Bearer test-token'}
headers={'Authorization': 'Bearer test-token', 'Connection': 'close'},
timeout=(10, 30)
)

@patch('libpermian.plugins.testing_farm.requests.delete')
Expand All @@ -172,7 +175,8 @@ def test_delete_request(self, mock_delete):

mock_delete.assert_called_once_with(
'https://api.testing-farm.io/v0.1/requests/request-123',
headers={'Authorization': 'Bearer test-token'}
headers={'Authorization': 'Bearer test-token', 'Connection': 'close'},
timeout=(10, 30)
)

@patch('libpermian.plugins.testing_farm.requests.get')
Expand Down
Loading