Skip to content

Commit 02a4991

Browse files
Merge branch 'dev' into proj/dc-specific-pricing
2 parents 6d771aa + 9915f6d commit 02a4991

File tree

8 files changed

+157
-5
lines changed

8 files changed

+157
-5
lines changed

.github/workflows/e2e-test-pr.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,37 @@ jobs:
7878
env:
7979
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8080

81-
- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
82-
if: ${{ steps.validate-tests.outputs.match == '' }}
81+
- name: Run Integration tests
82+
run: |
83+
timestamp=$(date +'%Y%m%d%H%M')
84+
report_filename="${timestamp}_sdk_test_report.xml"
85+
status=0
86+
if ! python3 -m pytest test/integration/${INTEGRATION_TEST_PATH} --junitxml="${report_filename}"; then
87+
echo "Tests failed, but attempting to upload results anyway"
88+
fi
8389
env:
8490
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
8591

92+
- name: Set release version env
93+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
94+
95+
- name: Add additional information to XML report
96+
run: |
97+
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
98+
python test/script/add_to_xml_test_report.py \
99+
--branch_name "${{ env.RELEASE_VERSION }}" \
100+
--gha_run_id "$GITHUB_RUN_ID" \
101+
--gha_run_number "$GITHUB_RUN_NUMBER" \
102+
--xmlfile "${filename}"
103+
104+
- name: Upload test results
105+
run: |
106+
report_filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
107+
python3 test/script/test_report_upload_script.py "${report_filename}"
108+
env:
109+
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
110+
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
111+
86112
- uses: actions/github-script@v6
87113
id: update-check-run
88114
if: ${{ inputs.pull_request_number != '' && fromJson(steps.commit-hash.outputs.data).repository.pullRequest.headRef.target.oid == inputs.sha }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ lint: build
6262
testint:
6363
python3 -m pytest test/integration/${INTEGRATION_TEST_PATH}${MODEL_COMMAND} ${TEST_CASE_COMMAND}
6464

65+
@PHONEY: testunit
66+
testunit:
67+
python3 -m python test/unit
68+
6569
@PHONEY: smoketest
6670
smoketest:
6771
pytest -m smoke test/integration --disable-warnings

linode_api4/linode_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
retry_rate_limit_interval=1.0,
6363
retry_max=5,
6464
retry_statuses=None,
65+
ca_path=None,
6566
):
6667
"""
6768
The main interface to the Linode API.
@@ -96,11 +97,14 @@ def __init__(
9697
:param retry_statuses: Additional HTTP response statuses to retry on.
9798
By default, the client will retry on 408, 429, and 502
9899
responses.
100+
:param ca_path: The path to a CA file to use for API requests in this client.
101+
:type ca_path: str
99102
"""
100103
self.base_url = base_url
101104
self._add_user_agent = user_agent
102105
self.token = token
103106
self.page_size = page_size
107+
self.ca_path = ca_path
104108

105109
retry_forcelist = [408, 429, 502]
106110

@@ -267,7 +271,9 @@ def _api_call(
267271
if data is not None:
268272
body = json.dumps(data)
269273

270-
response = method(url, headers=headers, data=body)
274+
response = method(
275+
url, headers=headers, data=body, verify=self.ca_path or True
276+
)
271277

272278
warning = response.headers.get("Warning", None)
273279
if warning:

linode_api4/login_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ def serialize(scopes):
324324

325325
class LinodeLoginClient:
326326
def __init__(
327-
self, client_id, client_secret, base_url="https://login.linode.com"
327+
self,
328+
client_id,
329+
client_secret,
330+
base_url="https://login.linode.com",
331+
ca_path=None,
328332
):
329333
"""
330334
Create a new LinodeLoginClient. These clients do not make any requests
@@ -339,10 +343,13 @@ def __init__(
339343
:param base_url: The URL for Linode's OAuth server. This should not be
340344
changed.
341345
:type base_url: str
346+
:param ca_path: The path to the CA file to use for requests run by this client.
347+
:type ca_path: str
342348
"""
343349
self.base_url = base_url
344350
self.client_id = client_id
345351
self.client_secret = client_secret
352+
self.ca_path = ca_path
346353

347354
def _login_uri(self, path):
348355
return "{}{}".format(self.base_url, path)
@@ -423,6 +430,7 @@ def oauth_redirect():
423430
"client_id": self.client_id,
424431
"client_secret": self.client_secret,
425432
},
433+
verify=self.ca_path or True,
426434
)
427435

428436
if r.status_code != 200:
@@ -467,6 +475,7 @@ def refresh_oauth_token(self, refresh_token):
467475
"client_secret": self.client_secret,
468476
"refresh_token": refresh_token,
469477
},
478+
verify=self.ca_path or True,
470479
)
471480

472481
if r.status_code != 200:
@@ -501,6 +510,7 @@ def expire_token(self, token):
501510
"client_secret": self.client_secret,
502511
"token": token,
503512
},
513+
verify=self.ca_path or True,
504514
)
505515

506516
if r.status_code != 200:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import argparse
2+
import xml.etree.ElementTree as ET
3+
4+
# Parse command-line arguments
5+
parser = argparse.ArgumentParser(
6+
description="Modify XML with workflow information"
7+
)
8+
parser.add_argument("--branch_name", required=True)
9+
parser.add_argument("--gha_run_id", required=True)
10+
parser.add_argument("--gha_run_number", required=True)
11+
parser.add_argument(
12+
"--xmlfile", required=True
13+
) # Added argument for XML file path
14+
15+
args = parser.parse_args()
16+
17+
# Open and parse the XML file
18+
xml_file_path = args.xmlfile
19+
tree = ET.parse(xml_file_path)
20+
root = tree.getroot()
21+
22+
# Create new elements for the information
23+
branch_name_element = ET.Element("branch_name")
24+
branch_name_element.text = args.branch_name
25+
26+
gha_run_id_element = ET.Element("gha_run_id")
27+
gha_run_id_element.text = args.gha_run_id
28+
29+
gha_run_number_element = ET.Element("gha_run_number")
30+
gha_run_number_element.text = args.gha_run_number
31+
32+
# Add the new elements to the root of the XML
33+
root.append(branch_name_element)
34+
root.append(gha_run_id_element)
35+
root.append(gha_run_number_element)
36+
37+
# Save the modified XML
38+
modified_xml_file_path = xml_file_path # Overwrite it
39+
tree.write(modified_xml_file_path)
40+
41+
print(f"Modified XML saved to {modified_xml_file_path}")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
4+
import boto3
5+
from botocore.exceptions import NoCredentialsError
6+
7+
ACCESS_KEY = os.environ.get("LINODE_CLI_OBJ_ACCESS_KEY")
8+
SECRET_KEY = os.environ.get("LINODE_CLI_OBJ_SECRET_KEY")
9+
BUCKET_NAME = "dx-test-results"
10+
11+
linode_obj_config = {
12+
"aws_access_key_id": ACCESS_KEY,
13+
"aws_secret_access_key": SECRET_KEY,
14+
"endpoint_url": "https://us-southeast-1.linodeobjects.com",
15+
}
16+
17+
18+
def upload_to_linode_object_storage(file_name):
19+
try:
20+
s3 = boto3.client("s3", **linode_obj_config)
21+
22+
s3.upload_file(Filename=file_name, Bucket=BUCKET_NAME, Key=file_name)
23+
24+
print(f"Successfully uploaded {file_name} to Linode Object Storage.")
25+
26+
except NoCredentialsError:
27+
print(
28+
"Credentials not available. Ensure you have set your AWS credentials."
29+
)
30+
31+
32+
if __name__ == "__main__":
33+
if len(sys.argv) != 2:
34+
print("Usage: python upload_to_linode.py <file_name>")
35+
sys.exit(1)
36+
37+
file_name = sys.argv[1]
38+
39+
if not file_name:
40+
print("Error: The provided file name is empty or invalid.")
41+
sys.exit(1)
42+
43+
upload_to_linode_object_storage(file_name)

test/unit/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_json(url):
3636
return FIXTURES.get_fixture(formatted_url)
3737

3838

39-
def mock_get(url, headers=None, data=None):
39+
def mock_get(url, headers=None, data=None, **kwargs):
4040
"""
4141
Loads the response from a JSON file
4242
"""

test/unit/linode_client_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,28 @@ def test_tag_create_with_entities(self):
258258
},
259259
)
260260

261+
def test_override_ca(self):
262+
"""
263+
Tests that the CA file used for API requests can be overridden.
264+
"""
265+
self.client.ca_path = "foobar"
266+
267+
called = False
268+
269+
old_get = self.client.session.get
270+
271+
def get_mock(*params, verify=True, **kwargs):
272+
nonlocal called
273+
called = True
274+
assert verify == "foobar"
275+
return old_get(*params, **kwargs)
276+
277+
self.client.session.get = get_mock
278+
279+
self.client.linode.instances()
280+
281+
assert called
282+
261283

262284
class AccountGroupTest(ClientBaseCase):
263285
"""

0 commit comments

Comments
 (0)