Skip to content

Commit ef5aa45

Browse files
committed
Test improvements
1 parent 59a0942 commit ef5aa45

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

test/e2e/tests/helper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616

1717
from typing import Union, Dict
18+
import time
1819

1920

2021
class EC2Validator:
@@ -214,6 +215,23 @@ def assert_transit_gateway(self, tgw_id: str, exists=True):
214215
pass
215216
assert res_found is exists
216217

218+
def wait_transit_gateway_state(self, tgw_id: str, state: str):
219+
is_state = False
220+
max_tries = 5
221+
try:
222+
for tries in range(max_tries):
223+
transit_gateway = self.ec2_client.describe_transit_gateways(TransitGatewayIds=[tgw_id])
224+
if transit_gateway['TransitGateways'][0]['State'] == state:
225+
is_state=True
226+
break
227+
else:
228+
print(f'try: {tries}')
229+
print(transit_gateway['TransitGateways'][0]['State'])
230+
time.sleep(30)
231+
except:
232+
pass
233+
return is_state
234+
217235
def get_transit_gateway_vpc_attachment(self, attachment_id: str) -> Union[None, Dict]:
218236
try:
219237
aws_res = self.ec2_client.describe_transit_gateway_vpc_attachments(TransitGatewayAttachmentIds=[attachment_id])

test/e2e/tests/test_transitgateway_vpc_attachment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@
3636
MODIFY_WAIT_AFTER_SECONDS = 30
3737

3838
@pytest.fixture(scope="module")
39-
def simple_tgw_attachment(request):
39+
def simple_tgw_attachment(request, ec2_client):
4040
test_resource_values = REPLACEMENT_VALUES.copy()
4141
resource_name = random_suffix_name("tgw-attachment-test", 24)
4242

4343
test_vpc = get_bootstrap_resources().SharedTestVPC
4444
test_tgw = get_bootstrap_resources().TestTransitGateway
45+
46+
tgw_id = test_tgw.transit_gateway_id
47+
48+
ec2_validator = EC2Validator(ec2_client)
49+
is_available = ec2_validator.wait_transit_gateway_state(tgw_id=tgw_id, state='available')
50+
assert is_available
4551

4652
test_resource_values["TGWVA_NAME"] = resource_name
4753
test_resource_values["VPC_ID"] = test_vpc.vpc_id

0 commit comments

Comments
 (0)