Skip to content

v5.16.0 #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 5, 2024
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
24 changes: 5 additions & 19 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,21 @@ jobs:
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} --disable-warnings --junitxml="${report_filename}"; then
echo "EXIT_STATUS=1" >> $GITHUB_ENV
fi
make testint TEST_ARGS="--junitxml=${report_filename}"
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Add additional information to XML report
- name: Upload test results
if: always()
run: |
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
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 tod_scripts/test_report_upload_script.py "${report_filename}"
sync
python3 tod_scripts/test_report_upload_script.py "${filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

- 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 .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.10
linode_api4-python
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
PYTHON ?= python3

INTEGRATION_TEST_PATH :=
TEST_CASE_COMMAND :=
MODEL_COMMAND :=
TEST_SUITE :=
TEST_ARGS :=

LINODE_SDK_VERSION ?= "0.0.0.dev"
VERSION_MODULE_DOCSTRING ?= \"\"\"\nThe version of this linode_api4 package.\n\"\"\"\n\n
VERSION_FILE := ./linode_api4/version.py

ifdef TEST_CASE
TEST_CASE_COMMAND = -k $(TEST_CASE)
TEST_CASE_COMMAND = -k $(TEST_CASE)
endif

ifdef TEST_MODEL
MODEL_COMMAND = models/$(TEST_MODEL)
ifdef TEST_SUITE
ifneq ($(TEST_SUITE),linode_client)
ifneq ($(TEST_SUITE),login_client)
TEST_COMMAND = models/$(TEST_SUITE)
else
TEST_COMMAND = login_client
endif
else
TEST_COMMAND = linode_client
endif
endif

.PHONY: clean
Expand Down Expand Up @@ -67,7 +75,7 @@ lint: build

.PHONY: testint
testint:
$(PYTHON) -m pytest test/integration/${INTEGRATION_TEST_PATH}${MODEL_COMMAND} ${TEST_CASE_COMMAND}
$(PYTHON) -m pytest test/integration/${TEST_COMMAND} ${TEST_CASE_COMMAND} ${TEST_ARGS}

.PHONY: testunit
testunit:
Expand Down
9 changes: 3 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,10 @@ Run the tests locally using the make command. Run the entire test suite using co

make testint

To run a specific package, use environment variable `INTEGRATION_TEST_PATH` with `testint` command::
To run a specific package/suite, use the environment variable `TEST_SUITE` using directory names in `integration/...` folder ::

make INTEGRATION_TEST_PATH="linode_client" testint

To run a specific model test suite, set the environment variable `TEST_MODEL` using file name in `integration/models`::

make TEST_MODEL="test_account.py" testint
make TEST_SUITE="account" testint // Runs tests in `integration/models/account` directory
make TEST_SUITE="linode_client" testint // Runs tests in `integration/linode_client` directory

Lastly to run a specific test case use environment variable `TEST_CASE` with `testint` command::

Expand Down
13 changes: 13 additions & 0 deletions linode_api4/groups/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
AccountBetaProgram,
AccountSettings,
BetaProgram,
ChildAccount,
Event,
Invoice,
Login,
Expand All @@ -18,6 +19,7 @@
ServiceTransfer,
User,
)
from linode_api4.objects.profile import PersonalAccessToken


class AccountGroup(Group):
Expand Down Expand Up @@ -496,3 +498,14 @@ def availabilities(self, *filters):
:rtype: PaginatedList of AccountAvailability
"""
return self.client._get_and_filter(AccountAvailability, *filters)

def child_accounts(self, *filters):
"""
Returns a list of all child accounts under the this parent account.

API doc: TBD

:returns: a list of all child accounts.
:rtype: PaginatedList of ChildAccount
"""
return self.client._get_and_filter(ChildAccount, *filters)
32 changes: 29 additions & 3 deletions linode_api4/groups/lke.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from typing import Any, Dict, Union

from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import Base, KubeVersion, LKECluster
from linode_api4.objects import (
Base,
JSONObject,
KubeVersion,
LKECluster,
LKEClusterControlPlaneOptions,
drop_null_keys,
)


class LKEGroup(Group):
Expand Down Expand Up @@ -47,7 +56,17 @@ def clusters(self, *filters):
"""
return self.client._get_and_filter(LKECluster, *filters)

def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
def cluster_create(
self,
region,
label,
node_pools,
kube_version,
control_plane: Union[
LKEClusterControlPlaneOptions, Dict[str, Any]
] = None,
**kwargs,
):
"""
Creates an :any:`LKECluster` on this account in the given region, with
the given label, and with node pools as described. For example::
Expand Down Expand Up @@ -80,6 +99,8 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
formatted dicts.
:param kube_version: The version of Kubernetes to use
:type kube_version: KubeVersion or str
:param control_plane: Dict[str, Any] or LKEClusterControlPlaneRequest
:type control_plane: The control plane configuration of this LKE cluster.
:param kwargs: Any other arguments to pass along to the API. See the API
docs for possible values.

Expand Down Expand Up @@ -112,10 +133,15 @@ def cluster_create(self, region, label, node_pools, kube_version, **kwargs):
if issubclass(type(kube_version), Base)
else kube_version
),
"control_plane": (
control_plane.dict
if issubclass(type(control_plane), JSONObject)
else control_plane
),
}
params.update(kwargs)

result = self.client.post("/lke/clusters", data=params)
result = self.client.post("/lke/clusters", data=drop_null_keys(params))

if "id" not in result:
raise UnexpectedResponseError(
Expand Down
35 changes: 35 additions & 0 deletions linode_api4/objects/account.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import datetime

import requests
Expand All @@ -16,6 +18,7 @@
)
from linode_api4.objects.longview import LongviewClient, LongviewSubscription
from linode_api4.objects.nodebalancer import NodeBalancer
from linode_api4.objects.profile import PersonalAccessToken
from linode_api4.objects.support import SupportTicket


Expand Down Expand Up @@ -53,6 +56,37 @@ class Account(Base):
}


class ChildAccount(Account):
"""
A child account under a parent account.

API Documentation: TBD
"""

api_endpoint = "/account/child-accounts/{euuid}"
id_attribute = "euuid"

def create_token(self, **kwargs):
"""
Create a ephemeral token for accessing the child account.

API Documentation: TBD
"""
resp = self._client.post(
"{}/token".format(self.api_endpoint),
model=self,
data=kwargs,
)

if "errors" in resp:
raise UnexpectedResponseError(
"Unexpected response when creating a token for the child account!",
json=resp,
)

return PersonalAccessToken(self._client, resp["id"], resp)


class ServiceTransfer(Base):
"""
A transfer request for transferring a service between Linode accounts.
Expand Down Expand Up @@ -476,6 +510,7 @@ class User(Base):
properties = {
"email": Property(),
"username": Property(identifier=True, mutable=True),
"user_type": Property(),
"restricted": Property(mutable=True),
"ssh_keys": Property(),
"tfa_enabled": Property(),
Expand Down
Loading
Loading