Skip to content

Commit 43d8ec3

Browse files
Filter regions based on account availabilities in get_regions function (#625)
* Filter regions based on account availabilities in get_regions function * Bypass account's region availabilities check when the token has no account access * Make ALL_ACCOUNT_AVAILABILITIES a global constant * Optimization
1 parent 6ed9f7d commit 43d8ec3

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

test/integration/conftest.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ipaddress
2+
import logging
23
import os
34
import random
45
import time
@@ -26,6 +27,7 @@
2627
PlacementGroupType,
2728
PostgreSQLDatabase,
2829
)
30+
from linode_api4.errors import ApiError
2931
from linode_api4.linode_client import LinodeClient, MonitorClient
3032
from linode_api4.objects import Region
3133

@@ -36,6 +38,15 @@
3638
RUN_LONG_TESTS = "RUN_LONG_TESTS"
3739
SKIP_E2E_FIREWALL = "SKIP_E2E_FIREWALL"
3840

41+
ALL_ACCOUNT_AVAILABILITIES = {
42+
"Linodes",
43+
"NodeBalancers",
44+
"Block Storage",
45+
"Kubernetes",
46+
}
47+
48+
logger = logging.getLogger(__name__)
49+
3950

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

5970
regions = client.regions()
6071

72+
account_regional_availabilities = {}
73+
try:
74+
account_availabilities = client.account.availabilities()
75+
for availability in account_availabilities:
76+
account_regional_availabilities[availability.region] = (
77+
availability.available
78+
)
79+
except ApiError:
80+
logger.warning(
81+
"Failed to retrieve account availabilities for regions. "
82+
"Assuming required capabilities are available in all regions for this account. "
83+
"Tests may fail if the account lacks access to necessary capabilities in the selected region."
84+
)
85+
6186
if capabilities is not None:
87+
required_capabilities = set(capabilities)
88+
required_account_capabilities = required_capabilities.intersection(
89+
ALL_ACCOUNT_AVAILABILITIES
90+
)
91+
6292
regions = [
63-
v for v in regions if set(capabilities).issubset(v.capabilities)
93+
v
94+
for v in regions
95+
if required_capabilities.issubset(v.capabilities)
96+
and required_account_capabilities.issubset(
97+
account_regional_availabilities.get(
98+
v.id,
99+
(
100+
[]
101+
if account_regional_availabilities
102+
else ALL_ACCOUNT_AVAILABILITIES
103+
),
104+
)
105+
)
64106
]
65107

66108
if site_type is not None:

0 commit comments

Comments
 (0)