Skip to content

Commit d00bef5

Browse files
committed
Bypass account's region availabilities check when the token has no account access
1 parent ed9638e commit d00bef5

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

test/integration/conftest.py

Lines changed: 27 additions & 6 deletions
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

@@ -35,6 +37,8 @@
3537
ENV_API_CA_NAME = "LINODE_API_CA"
3638
RUN_LONG_TESTS = "RUN_LONG_TESTS"
3739

40+
logger = logging.getLogger(__name__)
41+
3842

3943
def get_token():
4044
return os.environ.get(ENV_TOKEN_NAME, None)
@@ -62,12 +66,20 @@ def get_regions(
6266
"Block Storage",
6367
"Kubernetes",
6468
}
65-
account_availabilities = client.account.availabilities()
66-
account_regional_availabilities = {
67-
a.region: a.available for a in account_availabilities
68-
}
6969

70-
print(account_regional_availabilities)
70+
account_regional_availabilities = {}
71+
try:
72+
account_availabilities = client.account.availabilities()
73+
for availability in account_availabilities:
74+
account_regional_availabilities[availability.region] = (
75+
availability.available
76+
)
77+
except ApiError:
78+
logger.warning(
79+
"Failed to retrieve account availabilities for regions. "
80+
"Assuming required capabilities are available in all regions for this account. "
81+
"Tests may fail if the account lacks access to necessary capabilities in the selected region."
82+
)
7183

7284
if capabilities is not None:
7385
regions = [
@@ -76,7 +88,16 @@ def get_regions(
7688
if set(capabilities).issubset(v.capabilities)
7789
and set(capabilities)
7890
.intersection(ALL_ACCOUNT_AVAILABILITIES)
79-
.issubset(account_regional_availabilities.get(v.id, []))
91+
.issubset(
92+
account_regional_availabilities.get(
93+
v.id,
94+
(
95+
[]
96+
if account_regional_availabilities
97+
else ALL_ACCOUNT_AVAILABILITIES
98+
),
99+
)
100+
)
80101
]
81102

82103
if site_type is not None:

0 commit comments

Comments
 (0)