Skip to content

Commit b783d4f

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
[Integ-test] Avoid setting up integration tests networking in local zone
Before this commit, integration tests failed if the account has local zones enabled for the region. Because local zones do not support NAT Gateway Signed-off-by: Hanwen <[email protected]>
1 parent bbcba9e commit b783d4f

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

tests/integration-tests/conftest_networking.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,26 +195,27 @@ def subnet_name(visibility="Public", az_id=None, flavor=None):
195195
return f"{az_id_pascal_case}{visibility}{flavor_string}"
196196

197197

198-
def get_availability_zones(region, credential):
198+
def describe_availability_zones(region, credential):
199199
"""
200-
Return a list of availability zones for the given region.
200+
Return the response of boto3 describe_availability_zones.
201201
202202
Note that this function is called by the vpc_stacks fixture. Because vcp_stacks is session-scoped,
203203
it cannot utilize setup_sts_credentials, which is required in opt-in regions in order to call
204204
describe_availability_zones.
205205
"""
206-
az_list = []
207206
with aws_credential_provider(region, credential):
208207
client = boto3.client("ec2", region_name=region)
209-
response_az = client.describe_availability_zones(
208+
return client.describe_availability_zones(
210209
Filters=[
211210
{"Name": "region-name", "Values": [str(region)]},
212211
{"Name": "zone-type", "Values": ["availability-zone"]},
213212
]
214-
)
215-
for az in response_az.get("AvailabilityZones"):
216-
az_list.append(az.get("ZoneName"))
217-
return az_list
213+
).get("AvailabilityZones")
214+
215+
216+
def get_availability_zones(region, credential):
217+
"""Return a list of availability zones for the given region."""
218+
return [az.get("ZoneName") for az in describe_availability_zones(region, credential)]
218219

219220

220221
def get_az_setup_for_region(region: str, credential: list):
@@ -229,14 +230,7 @@ def get_az_setup_for_region(region: str, credential: list):
229230

230231
def get_az_id_to_az_name_map(region, credential):
231232
"""Return a dict mapping AZ IDs (e.g, 'use1-az2') to AZ names (e.g., 'us-east-1c')."""
232-
# credentials are managed manually rather than via setup_sts_credentials because this function
233-
# is called by a session-scoped fixture, which cannot make use of a class-scoped fixture.
234-
with aws_credential_provider(region, credential):
235-
ec2_client = boto3.client("ec2", region_name=region)
236-
return {
237-
entry.get("ZoneId"): entry.get("ZoneName")
238-
for entry in ec2_client.describe_availability_zones().get("AvailabilityZones")
239-
}
233+
return {entry.get("ZoneId"): entry.get("ZoneName") for entry in describe_availability_zones(region, credential)}
240234

241235

242236
# If stack creation fails it'll retry once more. This is done to mitigate failures due to resources

0 commit comments

Comments
 (0)