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
299 changes: 299 additions & 0 deletions tests/integration/lke/test_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,302 @@ def test_cluster_nodes_recycle(lke_cluster):
cluster_id = lke_cluster

exec_test_command(BASE_CMDS["lke"] + ["cluster-nodes-recycle", cluster_id])


def test_create_cluster_with_apl_enabled(monkeypatch):
"""
Test creating an LKE cluster with apl_enabled=true using v4beta API.
"""
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")

label = get_random_text(8) + "_apl_enabled_cluster"

test_region = get_random_region_with_caps(
required_capabilities=["Linodes", "Kubernetes"]
)
lke_version = exec_test_command(
BASE_CMDS["lke"]
+ [
"versions-list",
"--text",
"--no-headers",
]
).splitlines()[0]

# Create cluster with apl_enabled=true
cluster_label = exec_test_command(
BASE_CMDS["lke"]
+ [
"cluster-create",
"--region",
test_region,
"--label",
label,
"--node_pools.type",
"g6-dedicated-8", # APL requires higher specs
"--node_pools.count",
"3", # APL requires minimum 3 nodes
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment states "APL requires minimum 3 nodes" but there's no clear indication whether this is a hard requirement enforced by the API or just a testing convention. If APL actually works with any number of nodes, this comment could be misleading. Consider clarifying whether this is an API requirement or just a testing choice, or remove the comment if it's not a hard requirement.

Suggested change
"3", # APL requires minimum 3 nodes
"3", # Use 3 nodes for this APL-enabled cluster test

Copilot uses AI. Check for mistakes.
"--node_pools.disks",
'[{"type":"ext4","size":1024}]',
"--k8s_version",
lke_version,
"--tier",
"standard",
"--apl_enabled",
"true",
"--text",
"--delimiter",
",",
"--no-headers",
"--format=label",
]
)

assert label == cluster_label

cluster_id = get_cluster_id(label=cluster_label)

# Verify apl_enabled is set to true
res = exec_test_command(
BASE_CMDS["lke"] + ["cluster-view", cluster_id, "--json"]
)
cluster_data = json.loads(res)
assert cluster_data[0]["apl_enabled"] is True

delete_target_id(
target="lke", id=cluster_id, delete_command="cluster-delete"
)


def test_create_cluster_with_apl_disabled(monkeypatch):
"""
Test creating an LKE cluster with apl_enabled=false.
"""
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")

label = get_random_text(8) + "_apl_disabled_cluster"

test_region = get_random_region_with_caps(
required_capabilities=["Linodes", "Kubernetes"]
)
lke_version = exec_test_command(
BASE_CMDS["lke"]
+ [
"versions-list",
"--text",
"--no-headers",
]
).splitlines()[0]

# Create cluster with apl_enabled=false
cluster_label = exec_test_command(
BASE_CMDS["lke"]
+ [
"cluster-create",
"--region",
test_region,
"--label",
label,
"--node_pools.type",
"g6-standard-1",
"--node_pools.count",
"1",
"--node_pools.disks",
'[{"type":"ext4","size":1024}]',
"--k8s_version",
lke_version,
"--tier",
"standard",
"--apl_enabled",
"false",
"--text",
"--delimiter",
",",
"--no-headers",
"--format=label",
]
)

assert label == cluster_label

cluster_id = get_cluster_id(label=cluster_label)

# Verify apl_enabled is set to false
res = exec_test_command(
BASE_CMDS["lke"] + ["cluster-view", cluster_id, "--json"]
)
cluster_data = json.loads(res)
assert cluster_data[0]["apl_enabled"] is False

delete_target_id(
target="lke", id=cluster_id, delete_command="cluster-delete"
)


def test_create_cluster_apl_default(monkeypatch):
"""
Test creating an LKE cluster without specifying apl_enabled (should default to false).
"""
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")

label = get_random_text(8) + "_apl_default_cluster"

test_region = get_random_region_with_caps(
required_capabilities=["Linodes", "Kubernetes"]
)
lke_version = exec_test_command(
BASE_CMDS["lke"]
+ [
"versions-list",
"--text",
"--no-headers",
]
).splitlines()[0]

# Create cluster without apl_enabled parameter
cluster_label = exec_test_command(
BASE_CMDS["lke"]
+ [
"cluster-create",
"--region",
test_region,
"--label",
label,
"--node_pools.type",
"g6-standard-1",
"--node_pools.count",
"1",
"--node_pools.disks",
'[{"type":"ext4","size":1024}]',
"--k8s_version",
lke_version,
"--tier",
"standard",
"--text",
"--delimiter",
",",
"--no-headers",
"--format=label",
]
)

assert label == cluster_label

cluster_id = get_cluster_id(label=cluster_label)

# Verify apl_enabled defaults to false
res = exec_test_command(
BASE_CMDS["lke"] + ["cluster-view", cluster_id, "--json"]
)
cluster_data = json.loads(res)
assert cluster_data[0]["apl_enabled"] is False

delete_target_id(
target="lke", id=cluster_id, delete_command="cluster-delete"
)


def test_list_clusters_includes_apl_enabled(monkeypatch):
"""
Test that clusters-list includes apl_enabled field for all clusters.
"""
monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta")

# Create two clusters - one with APL enabled, one without
label_apl_on = get_random_text(8) + "_apl_on"
label_apl_off = get_random_text(8) + "_apl_off"

test_region = get_random_region_with_caps(
required_capabilities=["Linodes", "Kubernetes"]
)
lke_version = exec_test_command(
BASE_CMDS["lke"]
+ [
"versions-list",
"--text",
"--no-headers",
]
).splitlines()[0]

# Create cluster with APL enabled
exec_test_command(
BASE_CMDS["lke"]
+ [
"cluster-create",
"--region",
test_region,
"--label",
label_apl_on,
"--node_pools.type",
"g6-dedicated-8",
"--node_pools.count",
"3",
"--node_pools.disks",
'[{"type":"ext4","size":1024}]',
"--k8s_version",
lke_version,
"--tier",
"standard",
"--apl_enabled",
"true",
"--text",
"--no-headers",
"--format=label",
]
)

# Create cluster with APL disabled
exec_test_command(
BASE_CMDS["lke"]
+ [
"cluster-create",
"--region",
test_region,
"--label",
label_apl_off,
"--node_pools.type",
"g6-standard-1",
"--node_pools.count",
"1",
"--node_pools.disks",
'[{"type":"ext4","size":1024}]',
"--k8s_version",
lke_version,
"--tier",
"standard",
"--apl_enabled",
"false",
"--text",
"--no-headers",
"--format=label",
]
)

cluster_id_apl_on = get_cluster_id(label=label_apl_on)
cluster_id_apl_off = get_cluster_id(label=label_apl_off)

# List all clusters and verify apl_enabled is present
res = exec_test_command(BASE_CMDS["lke"] + ["clusters-list", "--json"])
clusters = json.loads(res)

# Find our test clusters
apl_on_cluster = next(
(c for c in clusters if c["id"] == int(cluster_id_apl_on)), None
)
apl_off_cluster = next(
(c for c in clusters if c["id"] == int(cluster_id_apl_off)), None
)

assert apl_on_cluster is not None
assert apl_off_cluster is not None

assert apl_on_cluster["apl_enabled"] is True
assert apl_off_cluster["apl_enabled"] is False

# Cleanup
delete_target_id(
target="lke", id=cluster_id_apl_on, delete_command="cluster-delete"
)
delete_target_id(
target="lke", id=cluster_id_apl_off, delete_command="cluster-delete"
)
7 changes: 6 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
LOADED_FILES = {}


FIXTURES_PATH = "tests/fixtures"
# Use an absolute path for fixtures so tests work regardless of the current
# working directory (VSCode test runner may change cwd when running a single
# test file).
FIXTURES_PATH = os.path.normpath(
os.path.join(os.path.dirname(__file__), "..", "fixtures")
)


@contextlib.contextmanager
Expand Down
Loading