Skip to content

Commit 03045d4

Browse files
authored
test: Add test coverage for Disk Encryption, Config, and Disk (#677)
1 parent 7a77276 commit 03045d4

19 files changed

+1360
-330
lines changed

.github/workflows/e2e-suite-windows.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ on:
22
pull_request:
33
workflow_dispatch:
44
inputs:
5-
test_path:
6-
description: "The path from 'test/integration' to the target to be tested, e.g. 'cli'"
5+
module:
6+
description: "The module from 'test/integration' to the target to be tested, e.g. 'cli, domains, events, etc'"
77
required: false
8+
run_long_tests:
9+
description: "Select True to run long tests, e.g. database, rebuild, etc"
10+
required: false
11+
type: choice
12+
options:
13+
- "True"
14+
- "False"
15+
default: "False"
816
sha:
917
description: 'The hash value of the commit.'
1018
required: true
@@ -21,13 +29,6 @@ jobs:
2129
github.event_name == 'workflow_dispatch' && inputs.sha != ''
2230

2331
steps:
24-
- uses: actions-ecosystem/action-regex-match@v2
25-
id: validate-tests
26-
with:
27-
text: ${{ inputs.test_path }}
28-
regex: '[^a-z0-9-:.\/_]' # Tests validation
29-
flags: gi
30-
3132
# Check out merge commit
3233
- name: Checkout PR
3334
uses: actions/checkout@v4
@@ -72,7 +73,7 @@ jobs:
7273
env:
7374
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7475

75-
- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
76+
- run: make MODULE="${{ inputs.module }}" RUN_LONG_TESTS="${{ inputs.run_long_tests }}" testint
7677
env:
7778
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN_2 }}
7879

.github/workflows/e2e-suite.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ on:
1010
module:
1111
description: "The module from 'test/integration' to the target to be tested, e.g. 'cli, domains, events, etc'"
1212
required: false
13+
run_long_tests:
14+
description: "Select True to run long tests, e.g. database, rebuild, etc"
15+
required: false
16+
type: choice
17+
options:
18+
- "True"
19+
- "False"
20+
default: "False"
1321
sha:
1422
description: 'The hash value of the commit.'
1523
required: true
@@ -111,7 +119,7 @@ jobs:
111119
run: |
112120
timestamp=$(date +'%Y%m%d%H%M')
113121
report_filename="${timestamp}_cli_test_report.xml"
114-
make testint TEST_ARGS="--junitxml=${report_filename}" MODULE="${{ inputs.module }}"
122+
make testint TEST_ARGS="--junitxml=${report_filename}" MODULE="${{ inputs.module }}" RUN_LONG_TESTS="${{ inputs.run_long_tests }}"
115123
env:
116124
LINODE_CLI_TOKEN: ${{ env.LINODE_CLI_TOKEN }}
117125

tests/integration/conftest.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from tests.integration.helpers import (
2121
delete_target_id,
2222
exec_test_command,
23+
get_random_region_with_caps,
2324
get_random_text,
2425
)
2526
from tests.integration.linodes.helpers_linodes import (
@@ -465,34 +466,6 @@ def nodebalancer_with_default_conf(linode_cloud_firewall):
465466
delete_target_id(target="nodebalancers", id=nodebalancer_id)
466467

467468

468-
def get_regions_with_capabilities(capabilities):
469-
regions = (
470-
exec_test_command(
471-
[
472-
"linode-cli",
473-
"regions",
474-
"ls",
475-
"--text",
476-
"--no-headers",
477-
"--format=id,capabilities",
478-
]
479-
)
480-
.stdout.decode()
481-
.rstrip()
482-
)
483-
484-
regions = regions.split("\n")
485-
486-
regions_with_all_caps = []
487-
488-
for region in regions:
489-
region_name = region.split()[0]
490-
if all(capability in region for capability in capabilities):
491-
regions_with_all_caps.append(region_name)
492-
493-
return regions_with_all_caps
494-
495-
496469
def create_vpc_w_subnet():
497470
"""
498471
Creates and returns a VPC and a corresponding subnet.
@@ -504,7 +477,7 @@ def create_vpc_w_subnet():
504477
See: https://github.com/pytest-dev/pytest/issues/1216
505478
"""
506479

507-
region = get_regions_with_capabilities(["VPCs"])[0]
480+
region = get_random_region_with_caps(required_capabilities=["VPCs"])
508481
vpc_label = str(time.time_ns()) + "label"
509482
subnet_label = str(time.time_ns()) + "label"
510483

tests/integration/helpers.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import random
23
import subprocess
34
import time
@@ -71,8 +72,8 @@ def delete_tag(arg: str):
7172
assert result.returncode == SUCCESS_STATUS_CODE
7273

7374

74-
def delete_target_id(target: str, id: str, subcommand: str = "delete"):
75-
command = ["linode-cli", target, subcommand, id]
75+
def delete_target_id(target: str, id: str, delete_command: str = "delete"):
76+
command = ["linode-cli", target, delete_command, id]
7677
result = exec_test_command(command)
7778
assert result.returncode == SUCCESS_STATUS_CODE
7879

@@ -168,3 +169,28 @@ def retry_exec_test_command_with_delay(
168169

169170
assert process.returncode == 0, f"Command failed after {retries} retries"
170171
return process
172+
173+
174+
def get_random_region_with_caps(
175+
required_capabilities: List[str], site_type="core"
176+
):
177+
json_regions_data = (
178+
exec_test_command(["linode-cli", "regions", "ls", "--json"])
179+
.stdout.decode()
180+
.strip()
181+
)
182+
183+
# Parse regions JSON data
184+
regions = json.loads(json_regions_data)
185+
186+
matching_regions = [
187+
region
188+
for region in regions
189+
if all(cap in region["capabilities"] for cap in required_capabilities)
190+
and region["site_type"] == site_type
191+
]
192+
193+
# Extract the region ids
194+
matching_region_ids = [region["id"] for region in matching_regions]
195+
196+
return random.choice(matching_region_ids) if matching_region_ids else None

tests/integration/linodes/helpers_linodes.py

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def wait_until(linode_id: "str", timeout, status: "str", period=5):
7171
return False
7272

7373

74-
def create_linode(firewall_id: "str", test_region=DEFAULT_REGION):
74+
def create_linode(
75+
firewall_id: "str", test_region=DEFAULT_REGION, disk_encryption=False
76+
):
7577
# create linode
7678
linode_id = (
7779
exec_test_command(
@@ -89,6 +91,8 @@ def create_linode(firewall_id: "str", test_region=DEFAULT_REGION):
8991
DEFAULT_RANDOM_PASS,
9092
"--firewall_id",
9193
firewall_id,
94+
"--disk_encryption",
95+
"enabled" if disk_encryption else "disabled",
9296
"--format=id",
9397
"--text",
9498
"--no-headers",
@@ -183,73 +187,40 @@ def create_linode_and_wait(
183187
test_plan=DEFAULT_LINODE_TYPE,
184188
test_image=DEFAULT_TEST_IMAGE,
185189
test_region=DEFAULT_REGION,
190+
disk_encryption=False,
186191
):
187-
linode_type = test_plan
188-
189-
# key_pair = generate_random_ssh_key()
192+
# Base command
193+
command = [
194+
"linode-cli",
195+
"linodes",
196+
"create",
197+
"--type",
198+
test_plan,
199+
"--region",
200+
test_region,
201+
"--image",
202+
test_image,
203+
"--root_pass",
204+
DEFAULT_RANDOM_PASS,
205+
"--firewall_id",
206+
firewall_id,
207+
"--format=id",
208+
"--backups_enabled",
209+
"true",
210+
"--disk_encryption",
211+
"enabled" if disk_encryption else "disabled",
212+
"--text",
213+
"--no-headers",
214+
]
190215

191-
output = ""
192-
# if ssh key is successfully generated
216+
# Add SSH key if provided
193217
if ssh_key:
194-
output = (
195-
exec_test_command(
196-
[
197-
"linode-cli",
198-
"linodes",
199-
"create",
200-
"--type",
201-
linode_type,
202-
"--region",
203-
test_region,
204-
"--image",
205-
test_image,
206-
"--root_pass",
207-
DEFAULT_RANDOM_PASS,
208-
"--authorized_keys",
209-
ssh_key,
210-
"--firewall_id",
211-
firewall_id,
212-
"--format=id",
213-
"--backups_enabled",
214-
"true",
215-
"--text",
216-
"--no-headers",
217-
]
218-
)
219-
.stdout.decode()
220-
.rstrip()
221-
)
222-
else:
223-
output = (
224-
exec_test_command(
225-
[
226-
"linode-cli",
227-
"linodes",
228-
"create",
229-
"--type",
230-
linode_type,
231-
"--region",
232-
"us-ord",
233-
"--image",
234-
test_image,
235-
"--root_pass",
236-
DEFAULT_RANDOM_PASS,
237-
"--firewall_id",
238-
firewall_id,
239-
"--format=id",
240-
"--backups_enabled",
241-
"true",
242-
"--text",
243-
"--no-headers",
244-
]
245-
)
246-
.stdout.decode()
247-
.rstrip()
248-
)
249-
linode_id = output
218+
command.extend(["--authorized_keys", ssh_key])
219+
220+
linode_id = exec_test_command(command).stdout.decode().strip()
250221

251222
# wait until linode is running, wait_until returns True when it is in running state
252-
result = (wait_until(linode_id=linode_id, timeout=240, status="running"),)
223+
result = wait_until(linode_id=linode_id, timeout=240, status="running")
253224

254225
assert result, "linode failed to change status to running"
255226

@@ -275,3 +246,24 @@ def set_backups_enabled_in_account_settings(toggle: bool):
275246
result = exec_test_command(command).stdout.decode().rstrip()
276247

277248
return result
249+
250+
251+
def get_disk_ids(linode_id):
252+
disk_ids = (
253+
exec_test_command(
254+
BASE_CMD
255+
+ [
256+
"disks-list",
257+
linode_id,
258+
"--text",
259+
"--no-headers",
260+
"--format",
261+
"id",
262+
]
263+
)
264+
.stdout.decode()
265+
.rstrip()
266+
.splitlines()
267+
)
268+
269+
return disk_ids

tests/integration/linodes/test_backups.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def test_create_backup_with_backup_enabled(linode_backup_enabled):
131131

132132

133133
@pytest.mark.skipif(
134-
os.environ.get("RUN_LONG_TESTS", None) != "TRUE",
135-
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=TRUE",
134+
os.environ.get("RUN_LONG_TESTS", None) != "True",
135+
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=True",
136136
)
137137
def test_take_snapshot_of_linode():
138138
# get linode id after creation and wait for "running" status
@@ -159,8 +159,8 @@ def test_take_snapshot_of_linode():
159159

160160

161161
@pytest.mark.skipif(
162-
os.environ.get("RUN_LONG_TESTS", None) != "TRUE",
163-
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=TRUE",
162+
os.environ.get("RUN_LONG_TESTS", None) != "True",
163+
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=True",
164164
)
165165
def test_view_the_snapshot(snapshot_of_linode):
166166
# get linode id after creation and wait for "running" status
@@ -187,8 +187,8 @@ def test_view_the_snapshot(snapshot_of_linode):
187187

188188

189189
@pytest.mark.skipif(
190-
os.environ.get("RUN_LONG_TESTS", None) != "TRUE",
191-
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=TRUE",
190+
os.environ.get("RUN_LONG_TESTS", None) != "True",
191+
reason="Skipping long-running Test, to run set RUN_LONG_TESTS=True",
192192
)
193193
def test_cancel_backups(snapshot_of_linode):
194194
# get linode id after creation and wait for "running" status

0 commit comments

Comments
 (0)