Skip to content
Merged
21 changes: 11 additions & 10 deletions .github/workflows/e2e-suite-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ on:
pull_request:
workflow_dispatch:
inputs:
test_path:
description: "The path from 'test/integration' to the target to be tested, e.g. 'cli'"
module:
description: "The module from 'test/integration' to the target to be tested, e.g. 'cli, domains, events, etc'"
required: false
run_long_tests:
description: "Select True to run long tests, e.g. database, rebuild, etc"
required: false
type: choice
options:
- "True"
- "False"
default: "False"
sha:
description: 'The hash value of the commit.'
required: true
Expand All @@ -21,13 +29,6 @@ jobs:
github.event_name == 'workflow_dispatch' && inputs.sha != ''

steps:
- uses: actions-ecosystem/action-regex-match@v2
id: validate-tests
with:
text: ${{ inputs.test_path }}
regex: '[^a-z0-9-:.\/_]' # Tests validation
flags: gi

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v4
Expand Down Expand Up @@ -72,7 +73,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
- run: make MODULE="${{ inputs.module }}" RUN_LONG_TESTS="${{ inputs.run_long_tests }}" testint
env:
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN_2 }}

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/e2e-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ on:
module:
description: "The module from 'test/integration' to the target to be tested, e.g. 'cli, domains, events, etc'"
required: false
run_long_tests:
description: "Select True to run long tests, e.g. database, rebuild, etc"
required: false
type: choice
options:
- "True"
- "False"
default: "False"
sha:
description: 'The hash value of the commit.'
required: true
Expand Down Expand Up @@ -111,7 +119,7 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_cli_test_report.xml"
make testint TEST_ARGS="--junitxml=${report_filename}" MODULE="${{ inputs.module }}"
make testint TEST_ARGS="--junitxml=${report_filename}" MODULE="${{ inputs.module }}" RUN_LONG_TESTS="${{ inputs.run_long_tests }}"
env:
LINODE_CLI_TOKEN: ${{ env.LINODE_CLI_TOKEN }}

Expand Down
31 changes: 2 additions & 29 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tests.integration.helpers import (
delete_target_id,
exec_test_command,
get_random_region_with_caps,
get_random_text,
)
from tests.integration.linodes.helpers_linodes import (
Expand Down Expand Up @@ -465,34 +466,6 @@ def nodebalancer_with_default_conf(linode_cloud_firewall):
delete_target_id(target="nodebalancers", id=nodebalancer_id)


def get_regions_with_capabilities(capabilities):
Copy link
Contributor Author

@ykim-akamai ykim-akamai Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored and moved to helpers.py

regions = (
exec_test_command(
[
"linode-cli",
"regions",
"ls",
"--text",
"--no-headers",
"--format=id,capabilities",
]
)
.stdout.decode()
.rstrip()
)

regions = regions.split("\n")

regions_with_all_caps = []

for region in regions:
region_name = region.split()[0]
if all(capability in region for capability in capabilities):
regions_with_all_caps.append(region_name)

return regions_with_all_caps


def create_vpc_w_subnet():
"""
Creates and returns a VPC and a corresponding subnet.
Expand All @@ -504,7 +477,7 @@ def create_vpc_w_subnet():
See: https://github.com/pytest-dev/pytest/issues/1216
"""

region = get_regions_with_capabilities(["VPCs"])[0]
region = get_random_region_with_caps(required_capabilities=["VPCs"])
vpc_label = str(time.time_ns()) + "label"
subnet_label = str(time.time_ns()) + "label"

Expand Down
30 changes: 28 additions & 2 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import random
import subprocess
import time
Expand Down Expand Up @@ -71,8 +72,8 @@ def delete_tag(arg: str):
assert result.returncode == SUCCESS_STATUS_CODE


def delete_target_id(target: str, id: str, subcommand: str = "delete"):
command = ["linode-cli", target, subcommand, id]
def delete_target_id(target: str, id: str, delete_command: str = "delete"):
command = ["linode-cli", target, delete_command, id]
result = exec_test_command(command)
assert result.returncode == SUCCESS_STATUS_CODE

Expand Down Expand Up @@ -168,3 +169,28 @@ def retry_exec_test_command_with_delay(

assert process.returncode == 0, f"Command failed after {retries} retries"
return process


def get_random_region_with_caps(
required_capabilities: List[str], site_type="core"
):
json_regions_data = (
exec_test_command(["linode-cli", "regions", "ls", "--json"])
.stdout.decode()
.strip()
)

# Parse regions JSON data
regions = json.loads(json_regions_data)

matching_regions = [
region
for region in regions
if all(cap in region["capabilities"] for cap in required_capabilities)
and region["site_type"] == site_type
]

# Extract the region ids
matching_region_ids = [region["id"] for region in matching_regions]

return random.choice(matching_region_ids) if matching_region_ids else None
118 changes: 55 additions & 63 deletions tests/integration/linodes/helpers_linodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def wait_until(linode_id: "str", timeout, status: "str", period=5):
return False


def create_linode(firewall_id: "str", test_region=DEFAULT_REGION):
def create_linode(
firewall_id: "str", test_region=DEFAULT_REGION, disk_encryption=False
):
# create linode
linode_id = (
exec_test_command(
Expand All @@ -89,6 +91,8 @@ def create_linode(firewall_id: "str", test_region=DEFAULT_REGION):
DEFAULT_RANDOM_PASS,
"--firewall_id",
firewall_id,
"--disk_encryption",
"enabled" if disk_encryption else "disabled",
"--format=id",
"--text",
"--no-headers",
Expand Down Expand Up @@ -183,73 +187,40 @@ def create_linode_and_wait(
test_plan=DEFAULT_LINODE_TYPE,
test_image=DEFAULT_TEST_IMAGE,
test_region=DEFAULT_REGION,
disk_encryption=False,
):
linode_type = test_plan

# key_pair = generate_random_ssh_key()
# Base command
command = [
"linode-cli",
"linodes",
"create",
"--type",
test_plan,
"--region",
test_region,
"--image",
test_image,
"--root_pass",
DEFAULT_RANDOM_PASS,
"--firewall_id",
firewall_id,
"--format=id",
"--backups_enabled",
"true",
"--disk_encryption",
"enabled" if disk_encryption else "disabled",
"--text",
"--no-headers",
]

output = ""
# if ssh key is successfully generated
# Add SSH key if provided
if ssh_key:
output = (
exec_test_command(
[
"linode-cli",
"linodes",
"create",
"--type",
linode_type,
"--region",
test_region,
"--image",
test_image,
"--root_pass",
DEFAULT_RANDOM_PASS,
"--authorized_keys",
ssh_key,
"--firewall_id",
firewall_id,
"--format=id",
"--backups_enabled",
"true",
"--text",
"--no-headers",
]
)
.stdout.decode()
.rstrip()
)
else:
output = (
exec_test_command(
[
"linode-cli",
"linodes",
"create",
"--type",
linode_type,
"--region",
"us-ord",
"--image",
test_image,
"--root_pass",
DEFAULT_RANDOM_PASS,
"--firewall_id",
firewall_id,
"--format=id",
"--backups_enabled",
"true",
"--text",
"--no-headers",
]
)
.stdout.decode()
.rstrip()
)
linode_id = output
command.extend(["--authorized_keys", ssh_key])

linode_id = exec_test_command(command).stdout.decode().strip()

# wait until linode is running, wait_until returns True when it is in running state
result = (wait_until(linode_id=linode_id, timeout=240, status="running"),)
result = wait_until(linode_id=linode_id, timeout=240, status="running")

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

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

return result


def get_disk_ids(linode_id):
disk_ids = (
exec_test_command(
BASE_CMD
+ [
"disks-list",
linode_id,
"--text",
"--no-headers",
"--format",
"id",
]
)
.stdout.decode()
.rstrip()
.splitlines()
)

return disk_ids
12 changes: 6 additions & 6 deletions tests/integration/linodes/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def test_create_backup_with_backup_enabled(linode_backup_enabled):


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


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


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