Skip to content

Commit 602fa57

Browse files
committed
Test improvements
1 parent 59a0942 commit 602fa57

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

test/e2e/tests/helper.py

Lines changed: 18 additions & 2 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,11 +215,26 @@ 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+
time.sleep(30)
229+
except:
230+
pass
231+
return is_state
232+
217233
def get_transit_gateway_vpc_attachment(self, attachment_id: str) -> Union[None, Dict]:
218234
try:
219235
aws_res = self.ec2_client.describe_transit_gateway_vpc_attachments(TransitGatewayAttachmentIds=[attachment_id])
220-
if len(aws_res["TransitGateways"]) > 0:
221-
return aws_res["TransitGateways"][0]
236+
if len(aws_res["TransitGatewayVpcAttachments"]) > 0:
237+
return aws_res["TransitGatewayVpcAttachments"][0]
222238
return None
223239
except self.ec2_client.exceptions.ClientError:
224240
return None

test/e2e/tests/test_transitgateway_vpc_attachment.py

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@
3434
DELETE_WAIT_AFTER_SECONDS = 180
3535
MAX_WAIT_FOR_SYNCED_SECONDS = 180
3636
MODIFY_WAIT_AFTER_SECONDS = 30
37+
WAIT_PERIOD = 30
3738

3839
@pytest.fixture(scope="module")
39-
def simple_tgw_attachment(request):
40+
def simple_tgw_attachment(request, ec2_client):
4041
test_resource_values = REPLACEMENT_VALUES.copy()
4142
resource_name = random_suffix_name("tgw-attachment-test", 24)
4243

4344
test_vpc = get_bootstrap_resources().SharedTestVPC
4445
test_tgw = get_bootstrap_resources().TestTransitGateway
46+
47+
tgw_id = test_tgw.transit_gateway_id
48+
49+
ec2_validator = EC2Validator(ec2_client)
50+
is_available = ec2_validator.wait_transit_gateway_state(tgw_id=tgw_id, state='available')
51+
assert is_available
4552

4653
test_resource_values["TGWVA_NAME"] = resource_name
4754
test_resource_values["VPC_ID"] = test_vpc.vpc_id
@@ -96,7 +103,7 @@ def test_crud_tags(self, ec2_client, simple_tgw_attachment):
96103
ref,
97104
"ACK.ResourceSynced",
98105
"True",
99-
wait_periods=MAX_WAIT_FOR_SYNCED_SECONDS,
106+
wait_periods=WAIT_PERIOD,
100107
)
101108

102109
time.sleep(CREATE_WAIT_AFTER_SECONDS)
@@ -143,20 +150,6 @@ def test_crud_tags(self, ec2_client, simple_tgw_attachment):
143150
actual=attachment["Tags"],
144151
)
145152

146-
@pytest.mark.resource_data({'tag_key': 'initialtagkey', 'tag_value': 'initialtagvalue'})
147-
def test_update_options(self, ec2_client, simple_tgw_attachment):
148-
(ref, cr) = simple_tgw_attachment
149-
150-
151-
assert k8s.wait_on_condition(
152-
ref,
153-
"ACK.ResourceSynced",
154-
"True",
155-
wait_periods=MAX_WAIT_FOR_SYNCED_SECONDS,
156-
)
157-
158-
attachment_id = cr["status"]["id"]
159-
160153
# Update options
161154
updates = {
162155
"spec": {
@@ -171,7 +164,7 @@ def test_update_options(self, ec2_client, simple_tgw_attachment):
171164
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
172165

173166
# Check resource synced successfully
174-
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=5)
167+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=WAIT_PERIOD)
175168

176169
# Verify the update in AWS
177170
ec2_validator = EC2Validator(ec2_client)
@@ -180,20 +173,6 @@ def test_update_options(self, ec2_client, simple_tgw_attachment):
180173
assert attachment["Options"]["DnsSupport"] == "disable"
181174
assert attachment["Options"]["Ipv6Support"] == "enable"
182175

183-
@pytest.mark.resource_data({'tag_key': 'initialtagkey', 'tag_value': 'initialtagvalue'})
184-
def test_update_subnet_ids(self, ec2_client, simple_tgw_attachment):
185-
(ref, cr) = simple_tgw_attachment
186-
187-
188-
assert k8s.wait_on_condition(
189-
ref,
190-
"ACK.ResourceSynced",
191-
"True",
192-
wait_periods=MAX_WAIT_FOR_SYNCED_SECONDS,
193-
)
194-
195-
attachment_id = cr["status"]["id"]
196-
197176
# Update subnet ids
198177
test_vpc = get_bootstrap_resources().SharedTestVPC
199178
updates = {
@@ -206,10 +185,10 @@ def test_update_subnet_ids(self, ec2_client, simple_tgw_attachment):
206185
time.sleep(MODIFY_WAIT_AFTER_SECONDS)
207186

208187
# Check resource synced successfully
209-
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=5)
188+
assert k8s.wait_on_condition(ref, "ACK.ResourceSynced", "True", wait_periods=WAIT_PERIOD)
210189

211190
# Verify the update in AWS
212191
ec2_validator = EC2Validator(ec2_client)
213192
attachment = ec2_validator.get_transit_gateway_vpc_attachment(attachment_id)
214193

215-
assert attachment["SubnetIds"] == test_vpc.public_subnets.subnet_ids
194+
assert set(attachment["SubnetIds"]) == set(test_vpc.public_subnets.subnet_ids)

0 commit comments

Comments
 (0)