Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ def test_domain(test_linode_client):
domain=domain_addr, soa_email=soa_email, tags=["test-tag"]
)

def get_domain_status():
domain.invalidate()
return domain.status == "active"

wait_for_condition(3, 30, get_domain_status)

# Create a SRV record
domain.record_create(
"SRV",
Expand All @@ -333,6 +339,12 @@ def test_volume(test_linode_client):

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

def get_volume_status():
volume.invalidate()
return volume.status == "active"

wait_for_condition(5, 45, get_volume_status)

yield volume

send_request_when_resource_available(timeout=100, func=volume.delete)
Expand Down
70 changes: 34 additions & 36 deletions test/integration/linode_client/test_linode_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import re
import time
from test.integration.conftest import get_region
from test.integration.helpers import get_test_label
from test.integration.helpers import get_test_label, wait_for_condition

import pytest

from linode_api4 import ApiError
from linode_api4.objects import ConfigInterface, ObjectStorageKeys, Region


def is_tag_created(client, tag_label):
tags = client.tags()
tag_label_list = [i.label for i in tags]

return tag_label in tag_label_list


@pytest.fixture(scope="session")
def setup_client_and_linode(test_linode_client, e2e_test_firewall):
client = test_linode_client
Expand Down Expand Up @@ -55,10 +62,11 @@ def test_fails_to_create_domain_without_soa_email(setup_client_and_linode):

timestamp = str(time.time_ns())
domain_addr = timestamp + "example.com"
try:
domain = client.domain_create(domain=domain_addr)
except ApiError as e:
assert e.status == 400

with pytest.raises(ApiError) as exc_info:
client.domain_create(domain=domain_addr)

assert exc_info.value.status == 400


@pytest.mark.smoke
Expand Down Expand Up @@ -90,11 +98,16 @@ def test_get_regions(test_linode_client):
def test_image_create(setup_client_and_linode):
client = setup_client_and_linode[0]
linode = setup_client_and_linode[1]

label = get_test_label()
description = "Test description"
tags = ["test"]
usable_disk = [v for v in linode.disks if v.filesystem != "swap"]

def linode_disks_are_ready(linode_instance):
linode_instance.invalidate()
disks = [d for d in linode_instance.disks if d.filesystem != "swap"]
return disks if disks else None

usable_disk = wait_for_condition(5, 120, linode_disks_are_ready, linode)

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

try:
with pytest.raises(ApiError) as exc_info:
client.image_create(disk=disk_id, label=label, description=description)
except ApiError as e:
assert 400 <= e.status < 500

# TODO: Specific status code may be used when defect is solved: ARB-7797
assert 400 <= exc_info.value.status < 500


def test_fails_to_delete_predefined_images(setup_client_and_linode):
client = setup_client_and_linode[0]

images = client.images()

try:
with pytest.raises(ApiError, match="Unauthorized") as exc_info:
# new images go on top of the list thus choose last image
images.last().delete()
except ApiError as e:
assert "Unauthorized" in str(e.json)
assert e.status == 403

assert exc_info.value.status == 403


def test_get_volume(test_linode_client, test_volume):
Expand All @@ -150,11 +163,7 @@ def test_get_tag(test_linode_client, test_tag):
client = test_linode_client
label = test_tag.label

tags = client.tags()

tag_label_list = [i.label for i in tags]

assert label in tag_label_list
assert wait_for_condition(3, 30, is_tag_created, client, label)


def test_create_tag_with_id(
Expand All @@ -176,15 +185,10 @@ def test_create_tag_with_id(
volumes=[volume.id, volume],
)

# Get tags after creation
tags = client.tags()

tag_label_list = [i.label for i in tags]
assert wait_for_condition(3, 30, is_tag_created, client, label)

tag.delete()

assert label in tag_label_list


@pytest.mark.smoke
def test_create_tag_with_entities(
Expand All @@ -202,15 +206,10 @@ def test_create_tag_with_entities(
label, entities=[linode, domain, nodebalancer, volume]
)

# Get tags after creation
tags = client.tags()

tag_label_list = [i.label for i in tags]
assert wait_for_condition(3, 30, is_tag_created, client, label)

tag.delete()

assert label in tag_label_list


# AccountGroupTests
def test_get_account_settings(test_linode_client):
Expand Down Expand Up @@ -345,16 +344,15 @@ def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
client = test_linode_client
region = get_region(client, {"Kubernetes"}).id

try:
cluster = client.lke.cluster_create(
with pytest.raises(ApiError, match="not valid") as exc_info:
client.lke.cluster_create(
region,
"example-cluster",
invalid_version,
{"type": "g6-standard-1", "count": 3},
)
except ApiError as e:
assert "not valid" in str(e.json)
assert e.status == 400

assert exc_info.value.status == 400


# ObjectStorageGroupTests
Expand Down
3 changes: 2 additions & 1 deletion test/integration/models/account/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ def test_latest_get_event(test_linode_client, e2e_test_firewall):
)

def get_linode_status():
linode.invalidate()
return linode.status == "running"

# To ensure the Linode is running and the 'event' key has been populated
wait_for_condition(3, 100, get_linode_status)
wait_for_condition(5, 150, get_linode_status)

events = client.load(Event, "")
latest_events = events._raw_json.get("data")[:15]
Expand Down
3 changes: 1 addition & 2 deletions test/integration/models/domain/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ def test_clone(test_linode_client, test_domain):
dom = "example.clone-" + timestamp + "-inttestsdk.org"
domain.clone(dom)

time.sleep(1)
time.sleep(3)

ds = test_linode_client.domains()

domains = [i.domain for i in ds]
Comment thread
mawilk90 marked this conversation as resolved.

assert dom in domains
Expand Down
2 changes: 1 addition & 1 deletion test/integration/models/linode/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def test_linode_rebuild(test_linode_client):
root_pass="aComplex@Password123",
)

wait_for_condition(10, 100, get_status, linode, "running")
wait_for_condition(10, 150, get_status, linode, "running")

retry_sending_request(
3,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/models/placement/test_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_pg_migration(

# Says it could take up to ~6 hrs for migration to fully complete
send_request_when_resource_available(
300,
400,
linode.initiate_migration,
placement_group=pg_inbound.id,
migration_type=MigrationType.COLD,
Expand Down