Skip to content

Commit e4ca7aa

Browse files
committed
Create tests for Linodes Creation Options and Password-less
1 parent d57c7bf commit e4ca7aa

3 files changed

Lines changed: 170 additions & 20 deletions

File tree

tests/integration/linodes/fixtures.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,41 @@ def linode_with_label(linode_cloud_firewall):
662662
res_arr = result.split(",")
663663
linode_id = res_arr[4]
664664
delete_target_id(target="linodes", id=linode_id)
665+
666+
667+
@pytest.fixture(scope="module")
668+
def linode_with_authorization_key(linode_cloud_firewall):
669+
label = "cli" + get_random_text(5)
670+
test_region = get_random_region_with_caps(
671+
required_capabilities=["Linodes", "Disk Encryption"]
672+
)
673+
result = exec_test_command(
674+
BASE_CMDS["linodes"]
675+
+ [
676+
"create",
677+
"--type",
678+
"g6-nanode-1",
679+
"--region",
680+
test_region,
681+
"--image",
682+
DEFAULT_TEST_IMAGE,
683+
"--label",
684+
label,
685+
"--authorized_keys",
686+
"ssh-rsa",
687+
"--kernel",
688+
"linode/latest-64bit",
689+
"--boot_size",
690+
"9000",
691+
"--text",
692+
"--delimiter",
693+
",",
694+
"--no-headers",
695+
"--no-defaults",
696+
"--format",
697+
"id,type",
698+
]
699+
).split(",")
700+
701+
yield result
702+
delete_target_id(target="linodes", id=result[0])

tests/integration/linodes/helpers.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,27 @@ def get_disk_id(test_linode_instance):
304304
).splitlines()
305305
first_id = disk_id[0].split(",")[0]
306306
return first_id
307+
308+
309+
def wait_for_disk_status(
310+
linode_id: "str", disk_id: "str", timeout, status: "str", period=10
311+
):
312+
must_end = time.time() + timeout
313+
while time.time() < must_end:
314+
time.sleep(period)
315+
result = exec_test_command(
316+
[
317+
"linode-cli",
318+
"linodes",
319+
"disk-view",
320+
linode_id,
321+
disk_id,
322+
"--format",
323+
"status",
324+
"--text",
325+
"--no-headers",
326+
]
327+
)
328+
if status == result:
329+
return True
330+
return False

tests/integration/linodes/test_linodes.py

Lines changed: 108 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
exec_failing_test_command,
1212
exec_test_command,
1313
get_random_region_with_caps,
14+
get_random_text,
15+
retry_exec_test_command_with_delay,
1416
)
1517
from tests.integration.linodes.fixtures import ( # noqa: F401
1618
linode_min_req,
19+
linode_with_authorization_key,
1720
linode_with_label,
1821
linode_wo_image,
1922
test_linode_instance,
@@ -23,6 +26,7 @@
2326
DEFAULT_TEST_IMAGE,
2427
create_linode,
2528
get_disk_id,
29+
wait_for_disk_status,
2630
wait_until,
2731
)
2832

@@ -42,6 +46,110 @@ def test_create_linodes_with_a_label(linode_with_label):
4246
)
4347

4448

49+
def test_expected_error_if_fields_authorized_users_authorized_keys_root_pass_are_not_set():
50+
test_region = get_random_region_with_caps(
51+
required_capabilities=["Linodes", "Disk Encryption"]
52+
)
53+
result = exec_failing_test_command(
54+
BASE_CMDS["linodes"]
55+
+ [
56+
"create",
57+
"--type",
58+
"g6-nanode-1",
59+
"--region",
60+
test_region,
61+
"--image",
62+
DEFAULT_TEST_IMAGE,
63+
"--label",
64+
"cli-negative-test-case",
65+
"--kernel",
66+
"linode/latest-64bit",
67+
"--boot_size",
68+
"9000",
69+
"--text",
70+
"--delimiter",
71+
",",
72+
"--no-headers",
73+
"--format",
74+
"label,region,type,image,id",
75+
"--no-defaults",
76+
],
77+
expected_code=ExitCodes.REQUEST_FAILED,
78+
)
79+
assert "Request failed: 400" in result
80+
assert (
81+
"Must provide valid root_pass, authorized_keys, or authorized_users"
82+
in result
83+
)
84+
85+
86+
def test_create_linode_with_kernel_and_boot_size_then_add_disk_and_rebuild(
87+
linode_with_authorization_key,
88+
):
89+
result_create = linode_with_authorization_key
90+
assert result_create[1] == "g6-nanode-1"
91+
assert wait_until(
92+
linode_id=result_create[0], timeout=180, status="running"
93+
), "linode failed to change status to running from creating.."
94+
95+
response_create_disk = (
96+
retry_exec_test_command_with_delay(
97+
BASE_CMDS["linodes"]
98+
+ [
99+
"disk-create",
100+
result_create[0],
101+
"--size",
102+
"2000",
103+
"--label",
104+
"cli" + get_random_text(5),
105+
"--image",
106+
"linode/debian12",
107+
"--root_pass",
108+
"aComplex@Password123",
109+
"--text",
110+
"--no-headers",
111+
"--delimiter",
112+
",",
113+
],
114+
retries=3,
115+
delay=10,
116+
)
117+
.splitlines()[0]
118+
.split(",")
119+
)
120+
assert "not ready" in response_create_disk
121+
assert wait_for_disk_status(
122+
linode_id=result_create[0],
123+
disk_id=response_create_disk[0],
124+
timeout=180,
125+
status="ready",
126+
), "linode failed to change disk status to ready after disk creation.."
127+
128+
result_rebuild = (
129+
exec_test_command(
130+
BASE_CMDS["linodes"]
131+
+ [
132+
"rebuild",
133+
"--image",
134+
DEFAULT_TEST_IMAGE,
135+
"--authorized_keys",
136+
"ssh-rsa-sha2-512",
137+
"--text",
138+
"--no-headers",
139+
"--delimiter",
140+
",",
141+
result_create[0],
142+
]
143+
)
144+
.splitlines()[0]
145+
.split(",")
146+
)
147+
assert DEFAULT_TEST_IMAGE in result_rebuild
148+
assert wait_until(
149+
linode_id=result_create[0], timeout=180, status="running"
150+
), "linode failed to change status to running from rebuilding.."
151+
152+
45153
@pytest.mark.smoke
46154
def test_view_linode_configuration(test_linode_instance):
47155
linode_id = test_linode_instance
@@ -75,26 +183,6 @@ def test_create_linode_with_min_required_props(linode_min_req):
75183
assert re.search("[0-9]+,us-ord,g6-nanode-1", result)
76184

77185

78-
def test_create_linodes_fails_without_a_root_pass():
79-
result = exec_failing_test_command(
80-
BASE_CMDS["linodes"]
81-
+ [
82-
"create",
83-
"--type",
84-
"g6-nanode-1",
85-
"--region",
86-
"us-ord",
87-
"--image",
88-
DEFAULT_TEST_IMAGE,
89-
"--text",
90-
"--no-headers",
91-
],
92-
ExitCodes.REQUEST_FAILED,
93-
)
94-
assert "Request failed: 400" in result
95-
assert "root_pass root_pass is required" in result
96-
97-
98186
def test_create_linode_without_image_and_not_boot(linode_wo_image):
99187
linode_id = linode_wo_image
100188

0 commit comments

Comments
 (0)