Skip to content

Commit fd7ade9

Browse files
authored
test: Add LKE ACL cases (#684)
1 parent eb210e9 commit fd7ade9

File tree

3 files changed

+269
-20
lines changed

3 files changed

+269
-20
lines changed

tests/integration/helpers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,24 @@ def get_random_region_with_caps(
194194
matching_region_ids = [region["id"] for region in matching_regions]
195195

196196
return random.choice(matching_region_ids) if matching_region_ids else None
197+
198+
199+
def get_cluster_id(label: str):
200+
cluster_id = (
201+
exec_test_command(
202+
[
203+
"linode-cli",
204+
"lke",
205+
"clusters-list",
206+
"--text",
207+
"--format=id",
208+
"--no-headers",
209+
"--label",
210+
label,
211+
]
212+
)
213+
.stdout.decode()
214+
.rstrip()
215+
)
216+
217+
return cluster_id

tests/integration/lke/test_clusters.py

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
assert_headers_in_lines,
55
delete_target_id,
66
exec_test_command,
7+
get_cluster_id,
78
get_random_region_with_caps,
89
get_random_text,
910
retry_exec_test_command_with_delay,
@@ -84,26 +85,6 @@ def get_pool_nodesid(cluster_id):
8485
return first_id
8586

8687

87-
def get_cluster_id(label: str):
88-
cluster_id = (
89-
exec_test_command(
90-
BASE_CMD
91-
+ [
92-
"clusters-list",
93-
"--text",
94-
"--format=id",
95-
"--no-headers",
96-
"--label",
97-
label,
98-
]
99-
)
100-
.stdout.decode()
101-
.rstrip()
102-
)
103-
104-
return cluster_id
105-
106-
10788
@pytest.fixture
10889
def test_lke_cluster():
10990
label = get_random_text(8) + "_cluster"
@@ -512,3 +493,78 @@ def test_pool_view(test_lke_cluster, test_node_pool):
512493
]
513494

514495
assert_headers_in_lines(headers, lines)
496+
497+
498+
def test_update_autoscaler(test_lke_cluster, test_node_pool):
499+
cluster_id = test_lke_cluster
500+
node_pool_id = test_node_pool
501+
502+
result = (
503+
exec_test_command(
504+
BASE_CMD
505+
+ [
506+
"pool-update",
507+
cluster_id,
508+
node_pool_id,
509+
"--autoscaler.enabled",
510+
"true",
511+
"--autoscaler.min",
512+
"1",
513+
"--autoscaler.max",
514+
"3",
515+
"--text",
516+
]
517+
)
518+
.stdout.decode()
519+
.rstrip()
520+
)
521+
522+
headers = [
523+
"autoscaler.enabled",
524+
"autoscaler.max",
525+
"autoscaler.min",
526+
"count",
527+
"disk_encryption",
528+
"id",
529+
"labels.key",
530+
"labels.value",
531+
"tags",
532+
"taints",
533+
"type",
534+
]
535+
536+
assert_headers_in_lines(headers, result.splitlines())
537+
538+
assert "3" in result
539+
assert "1" in result
540+
541+
542+
def test_kubeconfig_view(test_lke_cluster):
543+
cluster_id = test_lke_cluster
544+
545+
kubeconfig = (
546+
retry_exec_test_command_with_delay(
547+
BASE_CMD
548+
+ [
549+
"kubeconfig-view",
550+
cluster_id,
551+
"--text",
552+
],
553+
retries=5,
554+
delay=60,
555+
)
556+
.stdout.decode()
557+
.strip()
558+
)
559+
560+
header = ["kubeconfig"]
561+
562+
assert_headers_in_lines(header, kubeconfig.splitlines())
563+
564+
assert kubeconfig
565+
566+
567+
def test_cluster_nodes_recycle(test_lke_cluster):
568+
cluster_id = test_lke_cluster
569+
570+
exec_test_command(BASE_CMD + ["cluster-nodes-recycle", cluster_id])
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# │ cluster-acl-delete │ Delete the control plane access control list. │
2+
# │ cluster-acl-update │ Update the control plane access control list. │
3+
# │ cluster-acl-view │ Get the control plane access control list. │
4+
import pytest
5+
6+
from tests.integration.helpers import (
7+
assert_headers_in_lines,
8+
delete_target_id,
9+
exec_test_command,
10+
get_cluster_id,
11+
get_random_region_with_caps,
12+
get_random_text,
13+
retry_exec_test_command_with_delay,
14+
)
15+
16+
BASE_CMD = ["linode-cli", "lke"]
17+
18+
19+
@pytest.fixture
20+
def test_lke_cluster_acl():
21+
label = get_random_text(8) + "_cluster"
22+
23+
test_region = get_random_region_with_caps(
24+
required_capabilities=["Linodes", "Kubernetes"]
25+
)
26+
lke_version = (
27+
exec_test_command(
28+
BASE_CMD
29+
+ [
30+
"versions-list",
31+
"--text",
32+
"--no-headers",
33+
]
34+
)
35+
.stdout.decode()
36+
.rstrip()
37+
.splitlines()[0]
38+
)
39+
40+
cluster_label = (
41+
exec_test_command(
42+
BASE_CMD
43+
+ [
44+
"cluster-create",
45+
"--region",
46+
test_region,
47+
"--label",
48+
label,
49+
"--node_pools.type",
50+
"g6-standard-1",
51+
"--node_pools.count",
52+
"1",
53+
"--node_pools.disks",
54+
'[{"type":"ext4","size":1024}]',
55+
"--k8s_version",
56+
lke_version,
57+
"--control_plane.high_availability",
58+
"true",
59+
"--control_plane.acl.enabled",
60+
"true",
61+
"--text",
62+
"--delimiter",
63+
",",
64+
"--no-headers",
65+
"--format",
66+
"label",
67+
"--no-defaults",
68+
]
69+
)
70+
.stdout.decode()
71+
.rstrip()
72+
)
73+
74+
cluster_id = get_cluster_id(label=cluster_label)
75+
76+
yield cluster_id
77+
78+
delete_target_id(
79+
target="lke", id=cluster_id, delete_command="cluster-delete"
80+
)
81+
82+
83+
def test_cluster_acl_view(test_lke_cluster_acl):
84+
cluster_id = test_lke_cluster_acl
85+
86+
acl = (
87+
exec_test_command(
88+
BASE_CMD
89+
+ [
90+
"cluster-acl-view",
91+
cluster_id,
92+
"--text",
93+
]
94+
)
95+
.stdout.decode()
96+
.strip()
97+
)
98+
99+
headers = [
100+
"acl.enabled",
101+
"acl.addresses.ipv4",
102+
"acl.addresses.ipv6",
103+
"acl.revision-id",
104+
]
105+
106+
assert_headers_in_lines(headers, acl.splitlines())
107+
108+
assert "True" in acl
109+
110+
111+
def test_cluster_acl_update(test_lke_cluster_acl):
112+
cluster_id = test_lke_cluster_acl
113+
114+
print("RUNNING TEST")
115+
116+
# Verify the update
117+
acl = (
118+
exec_test_command(
119+
BASE_CMD
120+
+ [
121+
"cluster-acl-update",
122+
cluster_id,
123+
"--acl.addresses.ipv4",
124+
"203.0.113.1",
125+
"--acl.addresses.ipv6",
126+
"2001:db8:1234:abcd::/64",
127+
"--acl.enabled",
128+
"true",
129+
"--text",
130+
]
131+
)
132+
.stdout.decode()
133+
.strip()
134+
)
135+
136+
headers = [
137+
"acl.enabled",
138+
"acl.addresses.ipv4",
139+
"acl.addresses.ipv6",
140+
"acl.revision-id",
141+
]
142+
143+
assert_headers_in_lines(headers, acl.splitlines())
144+
145+
assert "203.0.113.1" in acl
146+
assert "2001:db8:1234:abcd::/64" in acl
147+
148+
149+
def test_cluster_acl_delete(test_lke_cluster_acl):
150+
cluster_id = test_lke_cluster_acl
151+
152+
retry_exec_test_command_with_delay(
153+
BASE_CMD + ["cluster-acl-delete", cluster_id]
154+
)
155+
156+
# Verify the deletion
157+
acl = (
158+
exec_test_command(
159+
BASE_CMD
160+
+ [
161+
"cluster-acl-view",
162+
cluster_id,
163+
"--text",
164+
"--format=acl.enabled",
165+
"--text",
166+
]
167+
)
168+
.stdout.decode()
169+
.strip()
170+
)
171+
172+
assert "False" in acl

0 commit comments

Comments
 (0)