Skip to content
Open
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
44 changes: 43 additions & 1 deletion test/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ipaddress
import logging
import os
import random
import time
Expand Down Expand Up @@ -26,6 +27,7 @@
PlacementGroupType,
PostgreSQLDatabase,
)
from linode_api4.errors import ApiError
from linode_api4.linode_client import LinodeClient, MonitorClient
from linode_api4.objects import Region

Expand All @@ -36,6 +38,15 @@
RUN_LONG_TESTS = "RUN_LONG_TESTS"
SKIP_E2E_FIREWALL = "SKIP_E2E_FIREWALL"

ALL_ACCOUNT_AVAILABILITIES = {
"Linodes",
"NodeBalancers",
"Block Storage",
"Kubernetes",
}

logger = logging.getLogger(__name__)


def get_token():
return os.environ.get(ENV_TOKEN_NAME, None)
Expand All @@ -58,9 +69,40 @@ def get_regions(

regions = client.regions()

account_regional_availabilities = {}
try:
account_availabilities = client.account.availabilities()
for availability in account_availabilities:
account_regional_availabilities[availability.region] = (
availability.available
)
except ApiError:
logger.warning(
"Failed to retrieve account availabilities for regions. "
"Assuming required capabilities are available in all regions for this account. "
"Tests may fail if the account lacks access to necessary capabilities in the selected region."
Comment on lines +79 to +83
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message could be more actionable. Consider including information about the specific ApiError that occurred or suggesting concrete steps for troubleshooting (e.g., checking API token permissions).

Suggested change
except ApiError:
logger.warning(
"Failed to retrieve account availabilities for regions. "
"Assuming required capabilities are available in all regions for this account. "
"Tests may fail if the account lacks access to necessary capabilities in the selected region."
except ApiError as err:
logger.warning(
"Failed to retrieve account availabilities for regions due to ApiError: %s. "
"Assuming required capabilities are available in all regions for this account. "
"Tests may fail if the account lacks access to necessary capabilities in the selected region. "
"Verify that the LINODE_TOKEN environment variable is set with sufficient permissions and that "
"the Linode API at '%s' is reachable.",
err,
get_api_url(),

Copilot uses AI. Check for mistakes.
)

if capabilities is not None:
required_capabilities = set(capabilities)
required_account_capabilities = required_capabilities.intersection(
ALL_ACCOUNT_AVAILABILITIES
)

regions = [
v for v in regions if set(capabilities).issubset(v.capabilities)
v
for v in regions
if required_capabilities.issubset(v.capabilities)
and required_account_capabilities.issubset(
account_regional_availabilities.get(
v.id,
(
[]
if account_regional_availabilities
else ALL_ACCOUNT_AVAILABILITIES
),
)
Comment on lines +97 to +104
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional logic for the default value is complex and could be confusing. Consider extracting this into a named variable or helper function to clarify the intent: when account availability data is present but a region is missing, default to empty list (no availability); when no account data was retrieved at all, assume all capabilities are available.

Copilot uses AI. Check for mistakes.
)
]

if site_type is not None:
Expand Down