Skip to content
Merged
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
6 changes: 3 additions & 3 deletions test/integration/models/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def test_get_types(test_linode_client):
client = test_linode_client
types = client.database.types()

assert (types[0].type_class, "nanode")
Comment thread
ykim-akamai marked this conversation as resolved.
assert (types[0].id, "g6-nanode-1")
assert (types[0].engines.mongodb[0].price.monthly, 15)
assert "nanode" in types[0].type_class
assert "g6-nanode-1" in types[0].id
assert types[0].engines.mongodb[0].price.monthly == 15


def test_get_engines(test_linode_client):
Expand Down
62 changes: 44 additions & 18 deletions test/integration/models/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
wait_for_condition,
)

import polling
import pytest

from linode_api4 import VPCIPAddress
from linode_api4 import LinodeClient, VPCIPAddress
from linode_api4.errors import ApiError
from linode_api4.objects import (
Config,
Expand Down Expand Up @@ -84,7 +85,7 @@ def linode_for_network_interface_tests(test_linode_client):
linode_instance.delete()


@pytest.fixture(scope="session", autouse=True)
@pytest.fixture
def linode_for_disk_tests(test_linode_client):
client = test_linode_client
available_regions = client.regions()
Expand All @@ -94,21 +95,24 @@ def linode_for_disk_tests(test_linode_client):
linode_instance, password = client.linode.instance_create(
"g6-nanode-1",
chosen_region,
image="linode/debian10",
image="linode/alpine3.19",
label=label + "_long_tests",
)

time.sleep(10)

# Provisioning time
wait_for_condition(10, 300, get_status, linode_instance, "running")

time.sleep(10)

linode_instance.shutdown()

wait_for_condition(10, 100, get_status, linode_instance, "offline")

# Now it allocates 100% disk space hence need to clear some space for tests
linode_instance.disks[1].delete()

test_linode_client.polling.event_poller_create(
"linode", "disk_delete", entity_id=linode_instance.id
)

yield linode_instance

linode_instance.delete()
Expand Down Expand Up @@ -138,6 +142,10 @@ def get_status(linode: Instance, status: str):
return linode.status == status


def instance_type_condition(linode: Instance, type: str):
return type in str(linode.type)


def test_get_linode(test_linode_client, linode_with_volume_firewall):
linode = test_linode_client.load(Instance, linode_with_volume_firewall.id)

Expand Down Expand Up @@ -303,6 +311,7 @@ def test_linode_resize_with_class(


def test_linode_resize_with_migration_type(
test_linode_client,
create_linode_for_long_running_tests,
):
linode = create_linode_for_long_running_tests
Expand All @@ -311,18 +320,32 @@ def test_linode_resize_with_migration_type(
wait_for_condition(10, 100, get_status, linode, "running")

time.sleep(5)
res = linode.resize(new_type="g6-standard-1", migration_type=m_type)

assert res
assert "g6-nanode-1" in str(linode.type)
assert linode.specs.disk == 25600

wait_for_condition(10, 300, get_status, linode, "resizing")
res = linode.resize(new_type="g6-standard-1", migration_type=m_type)

assert linode.status == "resizing"
if res:
# there is no resizing state in warm migration anymore hence wait for resizing and poll event
test_linode_client.polling.event_poller_create(
"linode", "linode_resize", entity_id=linode.id
).wait_for_next_event_finished(interval=5)

wait_for_condition(
10,
100,
get_status,
linode,
"running",
)
else:
raise ApiError

# Takes about 3-5 minute to resize, sometimes longer...
wait_for_condition(30, 600, get_status, linode, "running")
# reload resized linode
resized_linode = test_linode_client.load(Instance, linode.id)

assert linode.status == "running"
assert resized_linode.specs.disk == 51200


def test_linode_boot_with_config(create_linode):
Expand Down Expand Up @@ -376,10 +399,9 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):

disk = linode.disks[0]

disk.resize(5000)
send_request_when_resource_available(300, disk.resize, 5000)

# Using hard sleep instead of wait as the status shows ready when it is resizing
time.sleep(120)
time.sleep(100)

disk = test_linode_client.load(Disk, linode.disks[0].id, linode.id)

Expand All @@ -397,7 +419,11 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):
def test_linode_create_disk(test_linode_client, linode_for_disk_tests):
linode = test_linode_client.load(Instance, linode_for_disk_tests.id)

disk = linode.disk_create(size=500)
disk = send_request_when_resource_available(
300,
linode.disk_create,
size=500,
)

wait_for_disk_status(disk, 120)

Expand Down
28 changes: 23 additions & 5 deletions test/integration/models/test_lke.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_lke_node_delete(lke_cluster):

def test_lke_node_recycle(test_linode_client, lke_cluster):
cluster = test_linode_client.load(LKECluster, lke_cluster.id)
node = cluster.pools[0].nodes[0]

node_id = cluster.pools[0].nodes[0].id

send_request_when_resource_available(300, cluster.node_recycle, node_id)
Expand All @@ -106,9 +106,18 @@ def test_lke_node_recycle(test_linode_client, lke_cluster):
assert node.status == "not_ready"

# wait for provisioning
wait_for_condition(10, 300, get_node_status, cluster, "ready")
wait_for_condition(
10,
500,
get_node_status,
test_linode_client.load(LKECluster, lke_cluster.id),
"ready",
)

node = cluster.pools[0].nodes[0]
node_pool = test_linode_client.load(
LKENodePool, cluster.pools[0].id, cluster.id
)
node = node_pool.nodes[0]
assert node.status == "ready"


Expand All @@ -117,9 +126,18 @@ def test_lke_cluster_nodes_recycle(test_linode_client, lke_cluster):

send_request_when_resource_available(300, cluster.cluster_nodes_recycle)

wait_for_condition(5, 300, get_node_status, cluster, "not_ready")
wait_for_condition(
5,
300,
get_node_status,
test_linode_client.load(LKECluster, cluster.id),
"not_ready",
)

node = cluster.pools[0].nodes[0]
node_pool = test_linode_client.load(
LKENodePool, cluster.pools[0].id, cluster.id
)
node = node_pool.nodes[0]
assert node.status == "not_ready"


Expand Down