Skip to content

Commit 7886c08

Browse files
authored
Add lke tests (#641)
1 parent 04c1e92 commit 7886c08

File tree

2 files changed

+197
-8
lines changed

2 files changed

+197
-8
lines changed

linodecli/api_request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ def _attempt_warn_old_version(ctx, result):
374374
"with --suppress-warnings",
375375
file=sys.stderr,
376376
)
377-
suppress_version_warning = ctx.config.get_bool("suppress-version-warning") or os.getenv(
378-
"LINODE_CLI_SUPPRESS_VERSION_WARNING"
379-
)
377+
suppress_version_warning = ctx.config.get_bool(
378+
"suppress-version-warning"
379+
) or os.getenv("LINODE_CLI_SUPPRESS_VERSION_WARNING")
380380
if new_version_exists and not suppress_version_warning:
381381
print(
382382
f"The API responded with version {spec_version}, which is newer than "

tests/integration/lke/test_clusters.py

Lines changed: 194 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,30 @@ def test_deploy_an_lke_cluster():
5555
"--no-defaults",
5656
]
5757
).stdout.decode()
58-
5958
assert label + ",us-ord," + lke_version in result
6059

61-
# Sleep needed here for proper deletion of linodes that are related to lke cluster
62-
time.sleep(15)
6360

64-
remove_lke_clusters()
61+
@pytest.fixture
62+
def get_cluster_id():
63+
cluster_id = (
64+
exec_test_command(
65+
BASE_CMD
66+
+ [
67+
"clusters-list",
68+
"--text",
69+
"--no-headers",
70+
"--delimiter",
71+
",",
72+
"--format",
73+
"id",
74+
]
75+
)
76+
.stdout.decode()
77+
.rstrip()
78+
.splitlines()
79+
)
80+
first_id = cluster_id[0]
81+
yield first_id
6582

6683

6784
def test_lke_cluster_list():
@@ -78,6 +95,175 @@ def test_lke_cluster_list():
7895
assert_headers_in_lines(headers, lines)
7996

8097

98+
def test_view_lke_cluster(get_cluster_id):
99+
cluster_id = get_cluster_id
100+
101+
res = (
102+
exec_test_command(
103+
BASE_CMD + ["cluster-view", cluster_id, "--text", "--delimiter=,"]
104+
)
105+
.stdout.decode()
106+
.rstrip()
107+
)
108+
lines = res.splitlines()
109+
headers = ["label", "k8s_version"]
110+
assert_headers_in_lines(headers, lines)
111+
112+
113+
def test_update_kubernetes_cluster(get_cluster_id):
114+
cluster_id = get_cluster_id
115+
new_label = "cluster_test" + str(time.time_ns())
116+
updated_label = (
117+
exec_test_command(
118+
BASE_CMD
119+
+ [
120+
"cluster-update",
121+
cluster_id,
122+
"--label",
123+
new_label,
124+
"--text",
125+
"--no-headers",
126+
"--format=label",
127+
]
128+
)
129+
.stdout.decode()
130+
.rstrip()
131+
)
132+
assert new_label == updated_label
133+
134+
135+
def test_list_kubernetes_endpoint(get_cluster_id):
136+
cluster_id = get_cluster_id
137+
res = (
138+
exec_test_command(
139+
BASE_CMD
140+
+ ["api-endpoints-list", cluster_id, "--text", "--delimiter=,"]
141+
)
142+
.stdout.decode()
143+
.rstrip()
144+
)
145+
lines = res.splitlines()
146+
147+
headers = ["endpoint"]
148+
assert_headers_in_lines(headers, lines)
149+
150+
151+
def test_cluster_dashboard_url(get_cluster_id):
152+
cluster_id = get_cluster_id
153+
res = (
154+
exec_test_command(
155+
BASE_CMD
156+
+ ["cluster-dashboard-url", cluster_id, "--text", "--delimiter=,"]
157+
)
158+
.stdout.decode()
159+
.rstrip()
160+
)
161+
lines = res.splitlines()
162+
163+
headers = ["url"]
164+
assert_headers_in_lines(headers, lines)
165+
166+
167+
@pytest.fixture
168+
def get_node_pool_id(get_cluster_id):
169+
cluster_id = get_cluster_id
170+
nodepool_id = (
171+
exec_test_command(
172+
BASE_CMD
173+
+ [
174+
"pools-list",
175+
cluster_id,
176+
"--text",
177+
"--no-headers",
178+
"--delimiter",
179+
",",
180+
"--format",
181+
"id",
182+
]
183+
)
184+
.stdout.decode()
185+
.rstrip()
186+
.splitlines()
187+
)
188+
first_id = nodepool_id[0]
189+
yield first_id
190+
191+
192+
def test_node_pool_list(get_cluster_id):
193+
cluster_id = get_cluster_id
194+
res = (
195+
exec_test_command(
196+
BASE_CMD + ["pools-list", cluster_id, "--text", "--delimiter=,"]
197+
)
198+
.stdout.decode()
199+
.rstrip()
200+
)
201+
lines = res.splitlines()
202+
203+
headers = ["nodes.id", "nodes.instance_id"]
204+
assert_headers_in_lines(headers, lines)
205+
206+
207+
def test_view_pool(get_cluster_id, get_node_pool_id):
208+
cluster_id = get_cluster_id
209+
node_pool_id = get_node_pool_id
210+
res = (
211+
exec_test_command(
212+
BASE_CMD
213+
+ ["pool-view", cluster_id, node_pool_id, "--text", "--delimiter=,"]
214+
)
215+
.stdout.decode()
216+
.rstrip()
217+
)
218+
lines = res.splitlines()
219+
headers = ["type", "labels.value"]
220+
assert_headers_in_lines(headers, lines)
221+
222+
223+
@pytest.mark.skip(reason="BUG TPT-TPT-3145")
224+
def test_update_node_pool(get_cluster_id, get_node_pool_id):
225+
cluster_id = get_cluster_id
226+
node_pool_id = get_node_pool_id
227+
new_label = "cluster_test" + str(time.time_ns())
228+
updated_count = (
229+
exec_test_command(
230+
BASE_CMD
231+
+ [
232+
"pool-update",
233+
cluster_id,
234+
node_pool_id,
235+
"--count",
236+
"5",
237+
"--label.value",
238+
new_label,
239+
"--text",
240+
"--no-headers",
241+
"--format=label",
242+
]
243+
)
244+
.stdout.decode()
245+
.rstrip()
246+
)
247+
assert new_label == updated_count
248+
249+
250+
@pytest.mark.skip(reason="BUG TPT-TPT-3145")
251+
def test_view_node(get_cluster_id, get_node_pool_id):
252+
cluster_id = get_cluster_id
253+
node_pool_id = get_node_pool_id
254+
res = (
255+
exec_test_command(
256+
BASE_CMD
257+
+ ["node-view", cluster_id, node_pool_id, "--text", "--delimiter=,"]
258+
)
259+
.stdout.decode()
260+
.rstrip()
261+
)
262+
lines = res.splitlines()
263+
headers = ["type", "labels.value"]
264+
assert_headers_in_lines(headers, lines)
265+
266+
81267
@pytest.fixture
82268
def test_version_id():
83269
version_id = (
@@ -101,7 +287,7 @@ def test_version_id():
101287
yield first_id
102288

103289

104-
def test_beta_view(test_version_id):
290+
def test_version_view(test_version_id):
105291
version_id = test_version_id
106292
res = (
107293
exec_test_command(
@@ -114,3 +300,6 @@ def test_beta_view(test_version_id):
114300

115301
headers = ["id"]
116302
assert_headers_in_lines(headers, lines)
303+
# Sleep needed here for proper deletion of linodes that are related to lke cluster
304+
time.sleep(5)
305+
remove_lke_clusters()

0 commit comments

Comments
 (0)