Skip to content

Commit e12230d

Browse files
authored
TPT-4443: Fix flaky tests (#698)
* Fix flaky integration tests * Update test_domain and test_volume with waits * Update test_linode_client and test_account with waits * Add linode.invalidate() into get_linode_status * Add two more Capabilities to be aligned with the latest apinext object * Add missing API doc links for Object Storage global quotas
1 parent cff502a commit e12230d

9 files changed

Lines changed: 55 additions & 43 deletions

File tree

linode_api4/groups/object_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def global_quotas(self, *filters):
539539
"""
540540
Lists the active account-level Object Storage quotas applied to your account.
541541
542-
API Documentation: TBD
542+
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quotas
543543
544544
:param filters: Any number of filters to apply to this query.
545545
See :doc:`Filtering Collections</linode_api4/objects/filtering>`

linode_api4/objects/object_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class ObjectStorageGlobalQuota(Base):
622622
"""
623623
An account-level Object Storage quota.
624624
625-
API documentation: TBD
625+
API documentation: https://techdocs.akamai.com/linode-api/reference/get-object-storage-global-quota
626626
"""
627627

628628
api_endpoint = "/object-storage/global-quotas/{quota_id}"

linode_api4/objects/region.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Capability(StrEnum):
3939
lke_control_plane_acl = "LKE Network Access Control List (IP ACL)"
4040
aclb = "Akamai Cloud Load Balancer"
4141
support_ticket_severity = "Support Ticket Severity"
42+
support_live_chat = "Support Live Chat"
4243
backups = "Backups"
4344
placement_group = "Placement Group"
4445
disk_encryption = "Disk Encryption"
@@ -58,6 +59,7 @@ class Capability(StrEnum):
5859
maintenance_policy = "Maintenance Policy"
5960
vpc_dual_stack = "VPC Dual Stack"
6061
vpc_ipv6_stack = "VPC IPv6 Stack"
62+
vpc_custom_ipv4_ranges = "Custom VPC IPv4 Ranges"
6163
nlb = "Network LoadBalancer"
6264
natgateway = "NAT Gateway"
6365
lke_e_byovpc = "Kubernetes Enterprise BYO VPC"

test/integration/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ def test_domain(test_linode_client):
310310
domain=domain_addr, soa_email=soa_email, tags=["test-tag"]
311311
)
312312

313+
def get_domain_status():
314+
domain.invalidate()
315+
return domain.status == "active"
316+
317+
wait_for_condition(3, 30, get_domain_status)
318+
313319
# Create a SRV record
314320
domain.record_create(
315321
"SRV",
@@ -333,6 +339,12 @@ def test_volume(test_linode_client):
333339

334340
volume = client.volume_create(label=label, region=region)
335341

342+
def get_volume_status():
343+
volume.invalidate()
344+
return volume.status == "active"
345+
346+
wait_for_condition(5, 45, get_volume_status)
347+
336348
yield volume
337349

338350
send_request_when_resource_available(timeout=100, func=volume.delete)

test/integration/linode_client/test_linode_client.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import re
22
import time
33
from test.integration.conftest import get_region
4-
from test.integration.helpers import get_test_label
4+
from test.integration.helpers import get_test_label, wait_for_condition
55

66
import pytest
77

88
from linode_api4 import ApiError
99
from linode_api4.objects import ConfigInterface, ObjectStorageKeys, Region
1010

1111

12+
def is_tag_created(client, tag_label):
13+
tags = client.tags()
14+
tag_label_list = [i.label for i in tags]
15+
16+
return tag_label in tag_label_list
17+
18+
1219
@pytest.fixture(scope="session")
1320
def setup_client_and_linode(test_linode_client, e2e_test_firewall):
1421
client = test_linode_client
@@ -55,10 +62,11 @@ def test_fails_to_create_domain_without_soa_email(setup_client_and_linode):
5562

5663
timestamp = str(time.time_ns())
5764
domain_addr = timestamp + "example.com"
58-
try:
59-
domain = client.domain_create(domain=domain_addr)
60-
except ApiError as e:
61-
assert e.status == 400
65+
66+
with pytest.raises(ApiError) as exc_info:
67+
client.domain_create(domain=domain_addr)
68+
69+
assert exc_info.value.status == 400
6270

6371

6472
@pytest.mark.smoke
@@ -90,11 +98,16 @@ def test_get_regions(test_linode_client):
9098
def test_image_create(setup_client_and_linode):
9199
client = setup_client_and_linode[0]
92100
linode = setup_client_and_linode[1]
93-
94101
label = get_test_label()
95102
description = "Test description"
96103
tags = ["test"]
97-
usable_disk = [v for v in linode.disks if v.filesystem != "swap"]
104+
105+
def linode_disks_are_ready(linode_instance):
106+
linode_instance.invalidate()
107+
disks = [d for d in linode_instance.disks if d.filesystem != "swap"]
108+
return disks if disks else None
109+
110+
usable_disk = wait_for_condition(5, 120, linode_disks_are_ready, linode)
98111

99112
image = client.image_create(
100113
disk=usable_disk[0].id, label=label, description=description, tags=tags
@@ -116,23 +129,23 @@ def test_fails_to_create_image_with_non_existing_disk_id(
116129
description = "Test description"
117130
disk_id = 111111
118131

119-
try:
132+
with pytest.raises(ApiError) as exc_info:
120133
client.image_create(disk=disk_id, label=label, description=description)
121-
except ApiError as e:
122-
assert 400 <= e.status < 500
134+
135+
# TODO: Specific status code may be used when defect is solved: ARB-7797
136+
assert 400 <= exc_info.value.status < 500
123137

124138

125139
def test_fails_to_delete_predefined_images(setup_client_and_linode):
126140
client = setup_client_and_linode[0]
127141

128142
images = client.images()
129143

130-
try:
144+
with pytest.raises(ApiError, match="Unauthorized") as exc_info:
131145
# new images go on top of the list thus choose last image
132146
images.last().delete()
133-
except ApiError as e:
134-
assert "Unauthorized" in str(e.json)
135-
assert e.status == 403
147+
148+
assert exc_info.value.status == 403
136149

137150

138151
def test_get_volume(test_linode_client, test_volume):
@@ -150,11 +163,7 @@ def test_get_tag(test_linode_client, test_tag):
150163
client = test_linode_client
151164
label = test_tag.label
152165

153-
tags = client.tags()
154-
155-
tag_label_list = [i.label for i in tags]
156-
157-
assert label in tag_label_list
166+
assert wait_for_condition(3, 30, is_tag_created, client, label)
158167

159168

160169
def test_create_tag_with_id(
@@ -176,15 +185,10 @@ def test_create_tag_with_id(
176185
volumes=[volume.id, volume],
177186
)
178187

179-
# Get tags after creation
180-
tags = client.tags()
181-
182-
tag_label_list = [i.label for i in tags]
188+
assert wait_for_condition(3, 30, is_tag_created, client, label)
183189

184190
tag.delete()
185191

186-
assert label in tag_label_list
187-
188192

189193
@pytest.mark.smoke
190194
def test_create_tag_with_entities(
@@ -202,15 +206,10 @@ def test_create_tag_with_entities(
202206
label, entities=[linode, domain, nodebalancer, volume]
203207
)
204208

205-
# Get tags after creation
206-
tags = client.tags()
207-
208-
tag_label_list = [i.label for i in tags]
209+
assert wait_for_condition(3, 30, is_tag_created, client, label)
209210

210211
tag.delete()
211212

212-
assert label in tag_label_list
213-
214213

215214
# AccountGroupTests
216215
def test_get_account_settings(test_linode_client):
@@ -345,16 +344,15 @@ def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
345344
client = test_linode_client
346345
region = get_region(client, {"Kubernetes"}).id
347346

348-
try:
349-
cluster = client.lke.cluster_create(
347+
with pytest.raises(ApiError, match="not valid") as exc_info:
348+
client.lke.cluster_create(
350349
region,
351350
"example-cluster",
352351
invalid_version,
353352
{"type": "g6-standard-1", "count": 3},
354353
)
355-
except ApiError as e:
356-
assert "not valid" in str(e.json)
357-
assert e.status == 400
354+
355+
assert exc_info.value.status == 400
358356

359357

360358
# ObjectStorageGroupTests

test/integration/models/account/test_account.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ def test_latest_get_event(test_linode_client, e2e_test_firewall):
108108
)
109109

110110
def get_linode_status():
111+
linode.invalidate()
111112
return linode.status == "running"
112113

113114
# To ensure the Linode is running and the 'event' key has been populated
114-
wait_for_condition(3, 100, get_linode_status)
115+
wait_for_condition(5, 150, get_linode_status)
115116

116117
events = client.load(Event, "")
117118
latest_events = events._raw_json.get("data")[:15]

test/integration/models/domain/test_domain.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def test_clone(test_linode_client, test_domain):
4343
dom = "example.clone-" + timestamp + "-inttestsdk.org"
4444
domain.clone(dom)
4545

46-
time.sleep(1)
46+
time.sleep(3)
4747

4848
ds = test_linode_client.domains()
49-
5049
domains = [i.domain for i in ds]
5150

5251
assert dom in domains

test/integration/models/linode/test_linode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_linode_rebuild(test_linode_client):
304304
root_pass="aComplex@Password123",
305305
)
306306

307-
wait_for_condition(10, 100, get_status, linode, "running")
307+
wait_for_condition(10, 150, get_status, linode, "running")
308308

309309
retry_sending_request(
310310
3,

test/integration/models/placement/test_placement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_pg_migration(
9292

9393
# Says it could take up to ~6 hrs for migration to fully complete
9494
send_request_when_resource_available(
95-
300,
95+
400,
9696
linode.initiate_migration,
9797
placement_group=pg_inbound.id,
9898
migration_type=MigrationType.COLD,

0 commit comments

Comments
 (0)