Skip to content

Commit be6e62f

Browse files
authored
Integration tests (#814)
1 parent 2230585 commit be6e62f

File tree

7 files changed

+391
-7
lines changed

7 files changed

+391
-7
lines changed

tests/integration/account/test_account.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def test_account_setting_view():
196196
"longview_subscription",
197197
"network_helper",
198198
"interfaces_for_new_linodes",
199+
"maintenance_policy",
199200
]
200201

201202
settings_text = exec_test_command(
@@ -343,7 +344,15 @@ def test_maintenance_list():
343344
)
344345
lines = res.splitlines()
345346

346-
headers = ["entity.type", "entity.label"]
347+
headers = [
348+
"complete_time",
349+
"entity.type",
350+
"entity.label",
351+
"maintenance_policy_set",
352+
"not_before",
353+
"source",
354+
"start_time",
355+
]
347356
assert_headers_in_lines(headers, lines)
348357

349358

tests/integration/helpers.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
# TypeVars for generic type hints below
1717
T = TypeVar("T")
1818

19-
2019
MODULES = [
2120
"account",
21+
"alerts",
2222
"domains",
2323
"linodes",
2424
"nodebalancers",
@@ -33,7 +33,9 @@
3333
"linodes",
3434
"lke",
3535
"longview",
36+
"maintenance",
3637
"managed",
38+
"monitor",
3739
"networking",
3840
"obj",
3941
"object-storage",
@@ -100,8 +102,41 @@ def exec_failing_test_command(
100102

101103

102104
# Delete/Remove helper functions (mainly used in clean-ups after tests)
103-
def delete_target_id(target: str, id: str, delete_command: str = "delete"):
104-
command = ["linode-cli", target, delete_command, id]
105+
def delete_target_id(
106+
target: str,
107+
id: str,
108+
delete_command: str = "delete",
109+
service_type: str = None,
110+
use_retry: bool = False,
111+
retries: int = 3,
112+
delay: int = 80,
113+
):
114+
if service_type:
115+
command = ["linode-cli", target, delete_command, service_type, id]
116+
else:
117+
command = ["linode-cli", target, delete_command, id]
118+
119+
if use_retry:
120+
last_exc = None
121+
for attempt in range(retries):
122+
try:
123+
subprocess.run(
124+
command,
125+
check=True,
126+
stdout=subprocess.PIPE,
127+
stderr=subprocess.PIPE,
128+
text=True,
129+
)
130+
return # success
131+
except Exception as e:
132+
last_exc = e
133+
if attempt < retries - 1:
134+
time.sleep(delay)
135+
# If all retries fail, raise
136+
raise RuntimeError(
137+
f"Error executing command '{' '.join(command)}' after {retries} retries: {last_exc}"
138+
)
139+
105140
try:
106141
subprocess.run(
107142
command,

tests/integration/lke/test_clusters.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_deploy_an_lke_cluster():
5252
'[{"type":"ext4","size":1024}]',
5353
"--k8s_version",
5454
lke_version,
55+
"--tier",
56+
"standard",
5557
"--text",
5658
"--delimiter",
5759
",",
@@ -75,7 +77,15 @@ def test_lke_cluster_list():
7577
)
7678
lines = res.splitlines()
7779

78-
headers = ["label", "k8s_version"]
80+
headers = [
81+
"label",
82+
"k8s_version",
83+
"tier",
84+
"apl_enabled",
85+
"vpc_id",
86+
"subnet_id",
87+
"stack_type",
88+
]
7989
assert_headers_in_lines(headers, lines)
8090

8191

@@ -87,7 +97,15 @@ def test_view_lke_cluster(lke_cluster):
8797
+ ["cluster-view", cluster_id, "--text", "--delimiter=,"]
8898
)
8999
lines = res.splitlines()
90-
headers = ["label", "k8s_version"]
100+
headers = [
101+
"label",
102+
"k8s_version",
103+
"tier",
104+
"apl_enabled",
105+
"vpc_id",
106+
"subnet_id",
107+
"stack_type",
108+
]
91109
assert_headers_in_lines(headers, lines)
92110

93111

@@ -160,7 +178,7 @@ def test_view_pool(lke_cluster):
160178
)
161179

162180
lines = res.splitlines()
163-
headers = ["type", "labels"]
181+
headers = ["type", "labels", "k8s_version", "label"]
164182
assert_headers_in_lines(headers, lines)
165183

166184

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from tests.integration.helpers import (
2+
BASE_CMDS,
3+
assert_headers_in_lines,
4+
exec_test_command,
5+
)
6+
7+
8+
def test_maintenance_policies_list():
9+
res = exec_test_command(
10+
BASE_CMDS["maintenance"] + ["policies-list", "--text", "--delimiter=,"]
11+
)
12+
lines = res.splitlines()
13+
headers = [
14+
"description",
15+
"is_default",
16+
"label",
17+
"is_default",
18+
"slug",
19+
"type",
20+
]
21+
assert_headers_in_lines(headers, lines)
22+
rows = [line.split(",") for line in lines[1:] if line.strip()]
23+
24+
type_index = headers.index("type")
25+
types = [row[type_index].strip() for row in rows]
26+
27+
assert set(types) == {"migrate", "power_off_on"}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
from tests.integration.helpers import (
4+
BASE_CMDS,
5+
exec_test_command,
6+
)
7+
8+
9+
@pytest.fixture
10+
def get_service_type():
11+
service_ids = exec_test_command(
12+
BASE_CMDS["monitor"]
13+
+ [
14+
"service-list",
15+
"--text",
16+
"--no-headers",
17+
"--delimiter",
18+
",",
19+
"--format",
20+
"service_type",
21+
]
22+
).splitlines()
23+
first_id = service_ids[0].split(",")[0]
24+
yield first_id
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import pytest
2+
3+
from tests.integration.helpers import (
4+
BASE_CMDS,
5+
assert_headers_in_lines,
6+
delete_target_id,
7+
exec_test_command,
8+
get_random_text,
9+
retry_exec_test_command_with_delay,
10+
)
11+
12+
13+
def test_channels_list():
14+
res = exec_test_command(
15+
BASE_CMDS["alerts"] + ["channels-list", "--text", "--delimiter=,"]
16+
)
17+
lines = res.splitlines()
18+
headers = [
19+
"channel_type",
20+
"content.email.email_addresses",
21+
"id",
22+
"label",
23+
"type",
24+
"updated",
25+
]
26+
assert_headers_in_lines(headers, lines)
27+
28+
29+
@pytest.fixture
30+
def get_channel_id():
31+
channel_ids = exec_test_command(
32+
BASE_CMDS["alerts"]
33+
+ [
34+
"channels-list",
35+
"--text",
36+
"--no-headers",
37+
"--delimiter",
38+
",",
39+
"--format",
40+
"id",
41+
]
42+
).splitlines()
43+
first_id = channel_ids[0].split(",")[0]
44+
yield first_id
45+
46+
47+
def test_alerts_definition_create(get_channel_id, get_service_type):
48+
label = get_random_text(8) + "_alert"
49+
exec_test_command(
50+
BASE_CMDS["alerts"]
51+
+ [
52+
"definition-create",
53+
"--channel_ids",
54+
get_channel_id,
55+
"--label",
56+
label,
57+
"--rule_criteria.rules.metric",
58+
"cpu_usage",
59+
"--rule_criteria.rules.operator",
60+
"eq",
61+
"--rule_criteria.rules.threshold",
62+
"80",
63+
"--rule_criteria.rules.aggregate_function",
64+
"avg",
65+
"--severity",
66+
"1",
67+
"--trigger_conditions.criteria_condition",
68+
"ALL",
69+
"--trigger_conditions.evaluation_period_seconds",
70+
"300",
71+
"--trigger_conditions.polling_interval_seconds",
72+
"300",
73+
"--trigger_conditions.trigger_occurrences",
74+
"3",
75+
get_service_type,
76+
]
77+
)
78+
79+
80+
def test_alerts_list():
81+
res = exec_test_command(
82+
BASE_CMDS["alerts"]
83+
+ ["definitions-list-all", "--text", "--delimiter=,"]
84+
)
85+
lines = res.splitlines()
86+
headers = ["class", "created", "label", "severity", "service_type"]
87+
assert_headers_in_lines(headers, lines)
88+
89+
90+
@pytest.fixture
91+
def get_alert_id():
92+
alert_id = exec_test_command(
93+
BASE_CMDS["alerts"]
94+
+ [
95+
"definitions-list-all",
96+
"--text",
97+
"--no-headers",
98+
"--delimiter",
99+
",",
100+
"--format",
101+
"id",
102+
]
103+
).splitlines()
104+
first_id = alert_id[-1]
105+
yield first_id
106+
107+
108+
def test_alert_view(get_alert_id, get_service_type):
109+
alert_id = get_alert_id
110+
service_type = get_service_type
111+
res = exec_test_command(
112+
BASE_CMDS["alerts"]
113+
+ [
114+
"definition-view",
115+
service_type,
116+
alert_id,
117+
"--text",
118+
"--delimiter=,",
119+
]
120+
)
121+
lines = res.splitlines()
122+
123+
headers = ["class", "created", "label", "severity", "service_type"]
124+
assert_headers_in_lines(headers, lines)
125+
126+
127+
def test_alert_update(get_alert_id, get_service_type):
128+
alert_id = get_alert_id
129+
service_type = get_service_type
130+
new_label = get_random_text(8) + "_updated"
131+
updated_label = retry_exec_test_command_with_delay(
132+
BASE_CMDS["alerts"]
133+
+ [
134+
"definition-update",
135+
service_type,
136+
alert_id,
137+
"--label",
138+
new_label,
139+
"--text",
140+
"--no-headers",
141+
"--format=label",
142+
],
143+
delay=50,
144+
)
145+
assert updated_label == new_label
146+
delete_target_id(
147+
target="alerts",
148+
delete_command="definition-delete",
149+
service_type=service_type,
150+
id=alert_id,
151+
use_retry=True,
152+
)

0 commit comments

Comments
 (0)