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
41 changes: 40 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,37 @@ 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."
)

if capabilities is not None:
regions = [
v for v in regions if set(capabilities).issubset(v.capabilities)
v
for v in regions
if set(capabilities).issubset(v.capabilities)
and set(capabilities)
.intersection(ALL_ACCOUNT_AVAILABILITIES)
Comment on lines +91 to +92
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The set intersection set(capabilities).intersection(ALL_ACCOUNT_AVAILABILITIES) is computed for every region in the list comprehension. Consider calculating this once before the list comprehension and storing it in a variable to avoid redundant computation.

Copilot uses AI. Check for mistakes.
.issubset(
account_regional_availabilities.get(
v.id,
(
[]
if account_regional_availabilities
else ALL_ACCOUNT_AVAILABILITIES
),
)
)
Comment on lines +91 to +102
Copy link

Copilot AI Dec 27, 2025

Choose a reason for hiding this comment

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

The nested conditional logic with multi-line set operations is difficult to read and understand. Consider extracting this logic into a separate helper function (e.g., is_region_available_for_capabilities) that takes the region, capabilities, and account_regional_availabilities as parameters. This would improve readability and make the code easier to test and maintain.

Copilot uses AI. Check for mistakes.
]

if site_type is not None:
Expand Down