Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from linodecli import ENV_TOKEN_NAME
from tests.integration.helpers import (
DEFAULT_REGION,
check_attribute_value,
delete_target_id,
exec_test_command,
Expand Down Expand Up @@ -248,3 +249,25 @@ def pytest_configure(config):
config.addinivalue_line(
"markers", "smoke: mark test as part of smoke test suite"
)


@pytest.fixture
def create_reserved_ip(request):
tags = getattr(request, "param", None)
command = [
"linode-cli",
"networking",
"reserved-ip-add",
"--region",
DEFAULT_REGION,
"--json",
]

if tags:
command += ["--tags", tags]

result = json.loads(exec_test_command(command))[0]

yield result

delete_target_id("networking", result["address"], "reserved-ip-delete")
2 changes: 1 addition & 1 deletion tests/integration/database/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def mysql_cluster():
"--label",
mysql_database_label,
"--engine",
"mysql/8",
"mysql/8.4",
"--text",
"--delimiter",
",",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def mysql_db_engine_config(linode_cloud_firewall):
+ [
"mysql-create",
"--engine",
"mysql/8",
"mysql/8.4",
"--label",
label,
"--region",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import random
import re
import subprocess
Expand All @@ -14,6 +15,12 @@
FAILED_STATUS_CODE = 256
COMMAND_JSON_OUTPUT = ["--suppress-warnings", "--no-defaults", "--json"]

DEFAULT_REGION = (
"pl-labkrk-2"
if "devcloud" in os.getenv("LINODE_CLI_API_HOST", "")
else "us-ord"
)

# TypeVars for generic type hints below
T = TypeVar("T")

Expand Down
34 changes: 31 additions & 3 deletions tests/integration/linodes/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from tests.integration.helpers import (
BASE_CMDS,
DEFAULT_REGION,
delete_target_id,
exec_test_command,
get_random_region_with_caps,
Expand All @@ -16,7 +17,6 @@
DEFAULT_LABEL,
DEFAULT_LINODE_TYPE,
DEFAULT_RANDOM_PASS,
DEFAULT_REGION,
DEFAULT_TEST_IMAGE,
create_linode,
create_linode_and_wait,
Expand Down Expand Up @@ -487,8 +487,6 @@ def test_linode_instance(linode_cloud_firewall):
"--delimiter",
",",
"--no-headers",
"--format",
"id",
"--no-defaults",
"--format",
"id",
Expand Down Expand Up @@ -700,3 +698,33 @@ def linode_with_authorization_key(linode_cloud_firewall):

yield result
delete_target_id(target="linodes", id=result[0])


@pytest.fixture
def linode_with_reserved_ip(linode_cloud_firewall, create_reserved_ip):
res_ip = create_reserved_ip["address"]

linode_id = exec_test_command(
BASE_CMDS["linodes"]
+ [
"create",
"--type",
"g6-nanode-1",
"--region",
DEFAULT_REGION,
"--firewall_id",
linode_cloud_firewall,
"--ipv4",
res_ip,
"--text",
"--no-headers",
"--format",
"id",
]
)

wait_until(linode_id=linode_id, timeout=180, status="offline")

yield res_ip, linode_id

delete_target_id(target="linodes", id=linode_id)
7 changes: 1 addition & 6 deletions tests/integration/linodes/helpers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import json
import os
import time

from tests.integration.helpers import (
BASE_CMDS,
DEFAULT_REGION,
exec_test_command,
)

DEFAULT_RANDOM_PASS = exec_test_command(["openssl", "rand", "-base64", "32"])
DEFAULT_REGION = (
"pl-labkrk-2"
if "devcloud" in os.getenv("LINODE_CLI_API_HOST", "")
else "us-ord"
)

DEFAULT_TEST_IMAGE = exec_test_command(
[
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/linodes/test_linode_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ def test_interface_settings_update(
interface_id,
"--default_route.ipv6_interface_id",
interface_id,
"--default_route.ipv4_eligible_interface_ids",
interface_id,
"--default_route.ipv6_eligible_interface_ids",
interface_id,
"--json",
]
)
Expand All @@ -161,8 +157,6 @@ def test_interface_settings_update(
default_route = settings["default_route"]
assert default_route["ipv4_interface_id"] == int(interface_id)
assert default_route["ipv6_interface_id"] == int(interface_id)
assert default_route["ipv4_eligible_interface_ids"] == [int(interface_id)]
assert default_route["ipv6_eligible_interface_ids"] == [int(interface_id)]


def test_interface_update(linode_interface_public, monkeypatch: MonkeyPatch):
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/linodes/test_linodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
linode_min_req,
linode_with_authorization_key,
linode_with_label,
linode_with_reserved_ip,
linode_wo_image,
test_linode_instance,
)
Expand Down Expand Up @@ -319,3 +320,40 @@ def test_create_linode_disk_encryption_disabled(linode_cloud_firewall):
assert linode_id in res and "disabled" in res

delete_target_id(target="linodes", id=linode_id)


def test_display_linode_with_res_ipv4(linode_with_reserved_ip):
res_ip, linode_id = linode_with_reserved_ip
result = exec_test_command(
BASE_CMDS["linodes"]
+ ["view", linode_id, "--text", "--no-headers", "--no-defaults"]
)

assert linode_id in result
assert res_ip in result


def test_linode_allocate_res_ipv4(test_linode_instance, create_reserved_ip):
linode_id = test_linode_instance
res_ip = create_reserved_ip["address"]
new_headers = ["reserved", "tags"]

result = exec_test_command(
BASE_CMDS["linodes"]
+ [
"ip-add",
linode_id,
"--address",
res_ip,
"--type",
"ipv4",
"--public",
"true",
"--text",
"--delimiter",
",",
]
).splitlines()

assert_headers_in_lines(new_headers, [result[0].split(",")])
assert res_ip in result[1]
8 changes: 7 additions & 1 deletion tests/integration/monitor/test_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ def test_channels_list():
)
lines = res.splitlines()
headers = [
"alerts.alert_count",
"alerts.type",
"alerts.url",
"channel_type",
"content.email.email_addresses",
"created",
"created_by",
"details",
"id",
"label",
"type",
"updated",
"updated_by",
]
assert_headers_in_lines(headers, lines)

Expand Down
37 changes: 1 addition & 36 deletions tests/integration/networking/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,12 @@
import json

import pytest

from tests.integration.helpers import (
BASE_CMDS,
delete_target_id,
exec_test_command,
)
from tests.integration.helpers import delete_target_id
from tests.integration.linodes.helpers import (
DEFAULT_REGION,
create_linode,
create_linode_and_wait,
)


@pytest.fixture
def create_reserved_ip(request):
tags = getattr(request, "param", None)
command = BASE_CMDS["networking"] + [
"reserved-ip-add",
"--region",
DEFAULT_REGION,
"--json",
]

if tags:
command += ["--tags", tags]

result = json.loads(exec_test_command(command))[0]

yield result

delete_target_id("networking", result["address"], "reserved-ip-delete")


@pytest.fixture(scope="package")
def get_linode_id(linode_cloud_firewall):
linode_id = create_linode_and_wait(firewall_id=linode_cloud_firewall)
Expand All @@ -60,11 +33,3 @@ def get_linode_ids_shared_ipv4(linode_cloud_firewall):

for id_num in linode_ids:
delete_target_id(target="linodes", id=id_num)


def get_command_heads_and_vals(command):
result = exec_test_command(command).splitlines()
headers = [item for item in result[0].split(",")]
values = [item for item in result[1].split(",")]

return headers, values
4 changes: 1 addition & 3 deletions tests/integration/networking/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

from tests.integration.helpers import (
BASE_CMDS,
DEFAULT_REGION,
assert_headers_in_lines,
exec_test_command,
)
from tests.integration.linodes.helpers import DEFAULT_REGION
from tests.integration.networking.fixtures import ( # noqa: F401
create_reserved_ip,
get_command_heads_and_vals,
get_linode_id,
get_linode_ids_shared_ipv4,
)
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/nodebalancers/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,29 @@ def simple_nodebalancer_with_config(linode_cloud_firewall):
yield nodebalancer_id, config_id

delete_target_id(target="nodebalancers", id=nodebalancer_id)


@pytest.fixture
def nodebalancer_with_reserved_ipv4(create_reserved_ip):
res_ip = create_reserved_ip["address"]
region = create_reserved_ip["region"]
nodebalancer_id = exec_test_command(
BASE_CMDS["nodebalancers"]
+ [
"create",
"--region",
region,
"--ipv4",
res_ip,
"--text",
"--delimiter",
",",
"--no-headers",
"--format",
"id",
]
)

yield res_ip, nodebalancer_id

delete_target_id(target="nodebalancers", id=nodebalancer_id)
18 changes: 18 additions & 0 deletions tests/integration/nodebalancers/test_node_balancers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
linode_to_add,
nodebalancer_w_config_and_node,
nodebalancer_with_default_conf,
nodebalancer_with_reserved_ipv4,
nodebalancer_with_udp_config_and_node,
simple_nodebalancer_with_config,
)
Expand Down Expand Up @@ -68,6 +69,23 @@ def test_display_public_ipv4_for_nodebalancer(nodebalancer_w_config_and_node):
assert re.search(r"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", result)


def test_display_nodebalancer_with_res_ipv4(nodebalancer_with_reserved_ipv4):
res_ip, nb_id = nodebalancer_with_reserved_ipv4
result = exec_test_command(
BASE_CMDS["nodebalancers"]
+ [
"view",
nb_id,
"--format",
"ipv4",
"--text",
"--no-headers",
]
)

assert res_ip in result


def test_fail_to_view_nodebalancer_with_invalid_id():
result = exec_failing_test_command(
BASE_CMDS["nodebalancers"] + ["view", "535", "--text", "--no-headers"],
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/tags/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
exec_test_command,
get_random_text,
)
from tests.integration.networking.fixtures import ( # noqa: F401
create_reserved_ip,
)


@pytest.fixture(scope="session")
Expand Down
Loading
Loading