Skip to content

Commit 1517717

Browse files
Adds integration tests for private image sharing (#833)
1 parent 76f1a7a commit 1517717

File tree

3 files changed

+568
-1
lines changed

3 files changed

+568
-1
lines changed

tests/integration/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"domains",
2929
"events",
3030
"image",
31+
"images",
32+
"image-sharegroups",
3133
"image-upload",
3234
"firewalls",
3335
"kernels",
@@ -208,6 +210,6 @@ def get_random_region_with_caps(
208210

209211

210212
def assert_help_actions_list(expected_actions, help_output):
211-
output_actions = re.findall("\│\s(\S+)\s*\│", help_output)
213+
output_actions = re.findall(r"│\s(\S+(?:,\s)?\S+)\s*│", help_output)
212214
for expected_action in expected_actions:
213215
assert expected_action in output_actions
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import pytest
2+
3+
from tests.integration.helpers import (
4+
BASE_CMDS,
5+
exec_test_command,
6+
get_random_text,
7+
)
8+
9+
10+
@pytest.fixture
11+
def get_region():
12+
regions = exec_test_command(
13+
BASE_CMDS["regions"]
14+
+ [
15+
"list",
16+
"--text",
17+
"--no-headers",
18+
"--delimiter",
19+
",",
20+
"--format",
21+
"id",
22+
]
23+
).splitlines()
24+
first_id = regions[0]
25+
yield first_id
26+
27+
28+
def wait_for_image_status(id, expected_status, timeout=180, interval=5):
29+
import time
30+
31+
current_status = exec_test_command(
32+
BASE_CMDS["images"]
33+
+ [
34+
"view",
35+
id,
36+
"--text",
37+
"--no-headers",
38+
"--delimiter",
39+
",",
40+
"--format",
41+
"status",
42+
]
43+
).splitlines()
44+
timer = 0
45+
while current_status[0] != expected_status and timer < timeout:
46+
time.sleep(interval)
47+
timer += interval
48+
current_status = exec_test_command(
49+
BASE_CMDS["images"]
50+
+ [
51+
"view",
52+
id,
53+
"--text",
54+
"--no-headers",
55+
"--delimiter",
56+
",",
57+
"--format",
58+
"status",
59+
]
60+
).splitlines()
61+
if timer >= timeout:
62+
raise TimeoutError(
63+
f"Created image did not reach status '{expected_status}' within {timeout} seconds."
64+
)
65+
66+
67+
@pytest.fixture(scope="function")
68+
def create_image_id(get_region):
69+
linode_id = exec_test_command(
70+
BASE_CMDS["linodes"]
71+
+ [
72+
"create",
73+
"--image",
74+
"linode/alpine3.22",
75+
"--region",
76+
get_region,
77+
"--type",
78+
"g6-nanode-1",
79+
"--root_pass",
80+
"aComplex@Password",
81+
"--text",
82+
"--no-headers",
83+
"--delimiter",
84+
",",
85+
"--format",
86+
"id",
87+
]
88+
)
89+
disks = exec_test_command(
90+
BASE_CMDS["linodes"]
91+
+ [
92+
"disks-list",
93+
linode_id,
94+
"--text",
95+
"--no-headers",
96+
"--delimiter",
97+
",",
98+
"--format",
99+
"id",
100+
]
101+
).splitlines()
102+
image_id = exec_test_command(
103+
BASE_CMDS["images"]
104+
+ [
105+
"create",
106+
"--label",
107+
"linode-cli-test-image-sharing-image",
108+
"--disk_id",
109+
disks[0],
110+
"--text",
111+
"--no-headers",
112+
"--delimiter",
113+
",",
114+
"--format",
115+
"id",
116+
]
117+
)
118+
wait_for_image_status(image_id, "available")
119+
yield linode_id, image_id
120+
121+
122+
@pytest.fixture(scope="function")
123+
def create_share_group():
124+
label = get_random_text(8) + "_sharegroup_cli_test"
125+
share_group = exec_test_command(
126+
BASE_CMDS["image-sharegroups"]
127+
+ [
128+
"create",
129+
"--label",
130+
label,
131+
"--text",
132+
"--no-headers",
133+
"--delimiter",
134+
",",
135+
"--format",
136+
"id,uuid",
137+
]
138+
).split(",")
139+
yield share_group[0], share_group[1]

0 commit comments

Comments
 (0)