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
30 changes: 28 additions & 2 deletions .github/workflows/e2e-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,37 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

- name: Set release version env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Add additional information to XML report
run: |
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
python test/script/add_to_xml_test_report.py \
--branch_name "${{ env.RELEASE_VERSION }}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"

- name: Upload test results
run: |
report_filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
python3 test/script/test_report_upload_script.py "${report_filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

- uses: actions/github-script@v6
id: update-check-run
if: ${{ inputs.pull_request_number != '' && fromJson(steps.commit-hash.outputs.data).repository.pullRequest.headRef.target.oid == inputs.sha }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ release: build
twine upload dist/*

@PHONEY: install
install: clean
install: clean requirements
python3 -m pip install .

@PHONEY: requirements
Expand Down
1 change: 1 addition & 0 deletions linode_api4/objects/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class Type(Base):
"label": Property(),
"network_out": Property(),
"price": Property(),
"region_prices": Property(),
"addons": Property(),
"memory": Property(),
"transfer": Property(),
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/account_transfer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"quota": 471,
"used": 737373,
"billable": 0,

"region_transfers": [
{
"id": "ap-west",
"used": 1,
"quota": 5010,
"billable": 0
}
]
}
114 changes: 105 additions & 9 deletions test/fixtures/linode_types.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"results": 4,
"pages": 1,
"page": 1,
"data": [
"results": 4,
"pages": 1,
"page": 1,
"data": [
{
"disk": 20480,
"memory": 1024,
Expand All @@ -12,7 +12,19 @@
"price": {
"hourly": 0.003,
"monthly": 2
}
},
"region_prices": [
{
"id": "ap-west",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
]
}
},
"class": "nanode",
Expand All @@ -25,6 +37,18 @@
"hourly": 0.0075,
"monthly": 5
},
"region_prices": [
{
"id": "us-east",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
],
"successor": null
},
{
Expand All @@ -36,7 +60,19 @@
"price": {
"hourly": 0.008,
"monthly": 5
}
},
"region_prices": [
{
"id": "ap-west",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
]
}
},
"class": "highmem",
Expand All @@ -49,6 +85,18 @@
"hourly": 0.09,
"monthly": 60
},
"region_prices": [
{
"id": "us-east",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
],
"successor": null
},
{
Expand All @@ -60,7 +108,19 @@
"price": {
"hourly": 0.004,
"monthly": 2.5
}
},
"region_prices": [
{
"id": "ap-west",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
]
}
},
"class": "standard",
Expand All @@ -73,6 +133,18 @@
"hourly": 0.015,
"monthly": 10
},
"region_prices": [
{
"id": "us-east",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
],
"successor": null
},
{
Expand All @@ -84,7 +156,19 @@
"price": {
"hourly": 0.008,
"monthly": 5
}
},
"region_prices": [
{
"id": "ap-west",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
]
}
},
"class": "gpu",
Expand All @@ -97,7 +181,19 @@
"hourly": 0.03,
"monthly": 20
},
"region_prices": [
{
"id": "us-east",
"hourly": 0.02,
"monthly": 20
},
{
"id": "ap-northeast",
"hourly": 0.02,
"monthly": 20
}
],
"successor": null
}
]
}
}
21 changes: 19 additions & 2 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@

import pytest

from linode_api4.linode_client import LinodeClient, LongviewSubscription
from linode_api4.linode_client import LinodeClient

ENV_TOKEN_NAME = "LINODE_TOKEN"
ENV_API_URL_NAME = "LINODE_API_URL"
ENV_API_CA_NAME = "LINODE_API_CA"
RUN_LONG_TESTS = "RUN_LONG_TESTS"


def get_token():
return os.environ.get(ENV_TOKEN_NAME, None)


def get_api_url():
return os.environ.get(ENV_API_URL_NAME, "https://api.linode.com/v4beta")


def get_api_ca_file():
result = os.environ.get(ENV_API_CA_NAME, None)
return result if result != "" else None


def run_long_tests():
return os.environ.get(RUN_LONG_TESTS, None)

Expand Down Expand Up @@ -71,7 +82,13 @@ def ssh_key_gen():
@pytest.fixture(scope="session")
def get_client():
token = get_token()
client = LinodeClient(token)
api_url = get_api_url()
api_ca_file = get_api_ca_file()
client = LinodeClient(
token,
base_url=api_url,
ca_path=api_ca_file,
)
return client


Expand Down
16 changes: 16 additions & 0 deletions test/integration/models/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,22 @@ def test_get_linode_types(get_client):
assert "g6-nanode-1" in ids


def test_get_linode_types_overrides(get_client):
types = get_client.linode.types()

target_types = [
v
for v in types
if len(v.region_prices) > 0 and v.region_prices[0].hourly > 0
]

assert len(target_types) > 0

for linode_type in target_types:
assert linode_type.region_prices[0].hourly >= 0
assert linode_type.region_prices[0].monthly >= 0


def test_get_linode_type_by_id(get_client):
pytest.skip(
"Might need Type to match how other object models are behaving e.g. client.load(Type, 123)"
Expand Down
41 changes: 41 additions & 0 deletions test/script/add_to_xml_test_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import argparse
import xml.etree.ElementTree as ET

# Parse command-line arguments
parser = argparse.ArgumentParser(
description="Modify XML with workflow information"
)
parser.add_argument("--branch_name", required=True)
parser.add_argument("--gha_run_id", required=True)
parser.add_argument("--gha_run_number", required=True)
parser.add_argument(
"--xmlfile", required=True
) # Added argument for XML file path

args = parser.parse_args()

# Open and parse the XML file
xml_file_path = args.xmlfile
tree = ET.parse(xml_file_path)
root = tree.getroot()

# Create new elements for the information
branch_name_element = ET.Element("branch_name")
branch_name_element.text = args.branch_name

gha_run_id_element = ET.Element("gha_run_id")
gha_run_id_element.text = args.gha_run_id

gha_run_number_element = ET.Element("gha_run_number")
gha_run_number_element.text = args.gha_run_number

# Add the new elements to the root of the XML
root.append(branch_name_element)
root.append(gha_run_id_element)
root.append(gha_run_number_element)

# Save the modified XML
modified_xml_file_path = xml_file_path # Overwrite it
tree.write(modified_xml_file_path)

print(f"Modified XML saved to {modified_xml_file_path}")
Loading