Skip to content

Commit

Permalink
Merge branch 'dev' into zhiwei/pep621
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai authored Jan 24, 2024
2 parents 47ecfff + d09d2ea commit 63bae8c
Show file tree
Hide file tree
Showing 76 changed files with 3,468 additions and 663 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/e2e-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
runs-on: ubuntu-latest
if:
github.event_name == 'workflow_dispatch' && inputs.sha != ''
env:
EXIT_STATUS: 0

steps:
- uses: actions-ecosystem/action-regex-match@v2
Expand All @@ -33,6 +35,8 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ inputs.sha }}
fetch-depth: 0
submodules: 'recursive'

- name: Get the hash value of the latest commit from the PR branch
uses: octokit/[email protected]
Expand Down Expand Up @@ -83,28 +87,25 @@ jobs:
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"
if ! python3 -m pytest test/integration/${INTEGRATION_TEST_PATH} --disable-warnings --junitxml="${report_filename}"; then
echo "EXIT_STATUS=1" >> $GITHUB_ENV
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 }}" \
python tod_scripts/add_to_xml_test_report.py \
--branch_name "${GITHUB_REF#refs/*/}" \
--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}"
python3 tod_scripts/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 }}
Expand Down Expand Up @@ -135,4 +136,13 @@ jobs:
status: 'completed',
conclusion: process.env.conclusion
});
return result;
return result;
- name: Test Execution Status Handler
run: |
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Test execution contains failure(s)"
exit $EXIT_STATUS
else
echo "Tests passed!"
fi
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7','3.8','3.9','3.10','3.11']
python-version: ['3.8','3.9','3.10','3.11']
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tod_scripts"]
path = tod_scripts
url = https://github.com/linode/TOD-test-report-uploader.git
28 changes: 14 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,47 @@ build: clean

@PHONEY: release
release: build
twine upload dist/*
$(PYTHON) -m twine upload dist/*

@PHONEY: install
install: clean requirements
python3 -m pip install .
$(PYTHON) -m pip install .

@PHONEY: requirements
requirements:
pip install -r requirements.txt -r requirements-dev.txt
$(PYTHON) -m pip install -r requirements.txt -r requirements-dev.txt

@PHONEY: black
black:
black linode_api4 test
$(PYTHON) -m black linode_api4 test

@PHONEY: isort
isort:
isort linode_api4 test
$(PYTHON) -m isort linode_api4 test

@PHONEY: autoflake
autoflake:
autoflake linode_api4 test
$(PYTHON) -m autoflake linode_api4 test

@PHONEY: format
format: black isort autoflake

@PHONEY: lint
lint: build
isort --check-only linode_api4 test
autoflake --check linode_api4 test
black --check --verbose linode_api4 test
pylint linode_api4
twine check dist/*
$(PYTHON) -m isort --check-only linode_api4 test
$(PYTHON) -m autoflake --check linode_api4 test
$(PYTHON) -m black --check --verbose linode_api4 test
$(PYTHON) -m pylint linode_api4
$(PYTHON) -m twine check dist/*

@PHONEY: testint
testint:
python3 -m pytest test/integration/${INTEGRATION_TEST_PATH}${MODEL_COMMAND} ${TEST_CASE_COMMAND}
$(PYTHON) -m pytest test/integration/${INTEGRATION_TEST_PATH}${MODEL_COMMAND} ${TEST_CASE_COMMAND}

@PHONEY: testunit
testunit:
python3 -m python test/unit
$(PYTHON) -m pytest test/unit

@PHONEY: smoketest
smoketest:
pytest -m smoke test/integration --disable-warnings
$(PYTHON) -m pytest -m smoke test/integration --disable-warnings
1 change: 1 addition & 0 deletions linode_api4/groups/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from .support import *
from .tag import *
from .volume import *
from .vpc import *
17 changes: 15 additions & 2 deletions linode_api4/groups/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from linode_api4.groups import Group
from linode_api4.objects import (
Account,
AccountAvailability,
AccountBetaProgram,
AccountSettings,
BetaProgram,
Expand Down Expand Up @@ -457,7 +458,7 @@ def enrolled_betas(self, *filters):
"""
Returns a list of all Beta Programs an account is enrolled in.
API doc: TBD
API doc: https://www.linode.com/docs/api/beta-programs/#enrolled-beta-programs-list
:returns: a list of Beta Programs.
:rtype: PaginatedList of AccountBetaProgram
Expand All @@ -468,7 +469,7 @@ def join_beta_program(self, beta: Union[str, BetaProgram]):
"""
Enrolls an account into a beta program.
API doc: TBD
API doc: https://www.linode.com/docs/api/beta-programs/#beta-program-enroll
:param beta: The object or id of a beta program to join.
:type beta: BetaProgram or str
Expand All @@ -483,3 +484,15 @@ def join_beta_program(self, beta: Union[str, BetaProgram]):
)

return True

def availabilities(self, *filters):
"""
Returns a list of all available regions and the resources which are NOT available
to the account.
API doc: TBD
:returns: a list of region availability information.
:rtype: PaginatedList of AccountAvailability
"""
return self.client._get_and_filter(AccountAvailability, *filters)
2 changes: 1 addition & 1 deletion linode_api4/groups/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def betas(self, *filters):
"""
Returns a list of available active Beta Programs.
API Documentation: TBD
API Documentation: https://www.linode.com/docs/api/beta-programs/#beta-programs-list
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
Expand Down
9 changes: 9 additions & 0 deletions linode_api4/groups/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from linode_api4.objects import (
AuthorizedApp,
Base,
ConfigInterface,
Firewall,
Image,
Instance,
Kernel,
Expand Down Expand Up @@ -250,6 +252,8 @@ def instance_create(
The contents of this field can be built using the
:any:`build_instance_metadata` method.
:type metadata: dict
:param firewall: The firewall to attach this Linode to.
:type firewall: int or Firewall
:returns: A new Instance object, or a tuple containing the new Instance and
the generated password.
Expand Down Expand Up @@ -284,6 +288,10 @@ def instance_create(
)
del kwargs["backup"]

if "firewall" in kwargs:
fw = kwargs.pop("firewall")
kwargs["firewall_id"] = fw.id if isinstance(fw, Firewall) else fw

params = {
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
"region": region.id if issubclass(type(region), Base) else region,
Expand All @@ -292,6 +300,7 @@ def instance_create(
else None,
"authorized_keys": authorized_keys,
}

params.update(kwargs)

result = self.client.post("/linode/instances", data=params)
Expand Down
20 changes: 20 additions & 0 deletions linode_api4/groups/region.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from linode_api4.groups import Group
from linode_api4.objects import Region
from linode_api4.objects.region import RegionAvailabilityEntry


class RegionGroup(Group):
Expand All @@ -23,3 +24,22 @@ def __call__(self, *filters):
"""

return self.client._get_and_filter(Region, *filters)

def availability(self, *filters):
"""
Returns the availability of Linode plans within a Region.
API Documentation: https://www.linode.com/docs/api/regions/#regions-availability-list
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A list of entries describing the availability of a plan in a region.
:rtype: PaginatedList of RegionAvailabilityEntry
"""

return self.client._get_and_filter(
RegionAvailabilityEntry, *filters, endpoint="/regions/availability"
)
83 changes: 83 additions & 0 deletions linode_api4/groups/vpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Any, Dict, List, Optional, Union

from linode_api4 import VPCSubnet
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import VPC, Base, Region
from linode_api4.paginated_list import PaginatedList


class VPCGroup(Group):
def __call__(self, *filters) -> PaginatedList:
"""
Retrieves all of the VPCs the acting user has access to.
This is intended to be called off of the :any:`LinodeClient`
class, like this::
vpcs = client.vpcs()
API Documentation: TODO
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A list of VPC the acting user can access.
:rtype: PaginatedList of VPC
"""
return self.client._get_and_filter(VPC, *filters)

def create(
self,
label: str,
region: Union[Region, str],
description: Optional[str] = None,
subnets: Optional[List[Dict[str, Any]]] = None,
**kwargs,
) -> VPC:
"""
Creates a new VPC under your Linode account.
API Documentation: TODO
:param label: The label of the newly created VPC.
:type label: str
:param region: The region of the newly created VPC.
:type region: Union[Region, str]
:param description: The user-defined description of this VPC.
:type description: Optional[str]
:param subnets: A list of subnets to create under this VPC.
:type subnets: List[Dict[str, Any]]
:returns: The new VPC object.
:rtype: VPC
"""
params = {
"label": label,
"region": region.id if isinstance(region, Region) else region,
}

if description is not None:
params["description"] = description

if subnets is not None and len(subnets) > 0:
for subnet in subnets:
if not isinstance(subnet, dict):
raise ValueError(
f"Unsupported type for subnet: {type(subnet)}"
)

params["subnets"] = subnets

params.update(kwargs)

result = self.client.post("/vpcs", data=params)

if not "id" in result:
raise UnexpectedResponseError(
"Unexpected response when creating VPC", json=result
)

d = VPC(self.client, result["id"], result)
return d
Loading

0 comments on commit 63bae8c

Please sign in to comment.