Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai committed Jan 16, 2024
1 parent 07f68e4 commit 6ea0384
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 29 deletions.
41 changes: 41 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Use random integer as the start point here to avoid
# id conflicts when multiple testings are running.
import json
import logging
import os
import subprocess
Expand Down Expand Up @@ -402,3 +403,43 @@ def get_regions_with_capabilities(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.
This is not directly implemented as a fixture because the teardown
order cannot be guaranteed, causing issues when attempting to
assign Linodes to a VPC in a separate fixture.
See: https://github.com/pytest-dev/pytest/issues/1216
"""

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

vpc_json = json.loads(
exec_test_command(
[
"linode-cli",
"vpcs",
"create",
"--label",
vpc_label,
"--region",
region,
"--subnets.ipv4",
"10.0.0.0/24",
"--subnets.label",
subnet_label,
"--json",
"--suppress-warnings",
]
)
.stdout.decode()
.rstrip()
)[0]

return vpc_json
96 changes: 96 additions & 0 deletions tests/integration/linodes/test_interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import json
import time

import pytest

from tests.integration.conftest import (
create_vpc_w_subnet,
)
from tests.integration.helpers import delete_target_id, exec_test_command
from tests.integration.linodes.helpers_linodes import (
BASE_CMD,
DEFAULT_LABEL,
DEFAULT_RANDOM_PASS,
DEFAULT_TEST_IMAGE,
)

timestamp = str(time.time_ns())
linode_label = DEFAULT_LABEL + timestamp


@pytest.fixture
def linode_with_vpc_interface():
vpc_json = create_vpc_w_subnet()

vpc_region = vpc_json["region"]
vpc_id = str(vpc_json["id"])
subnet_id = str(vpc_json["subnets"][0]["id"])

linode_json = json.loads(
exec_test_command(
BASE_CMD
+ [
"create",
"--type",
"g6-nanode-1",
"--region",
vpc_region,
"--image",
DEFAULT_TEST_IMAGE,
"--root_pass",
DEFAULT_RANDOM_PASS,
"--interfaces.purpose",
"vpc",
"--interfaces.primary",
"true",
"--interfaces.subnet_id",
subnet_id,
"--interfaces.ipv4.nat_1_1",
"any",
"--interfaces.ipv4.vpc",
"10.0.0.5",
"--interfaces.purpose",
"public",
"--json",
"--suppress-warnings",
]
)
.stdout.decode()
.rstrip()
)[0]

yield linode_json, vpc_json

delete_target_id(target="linodes", id=str(linode_json["id"]))
delete_target_id(target="vpcs", id=vpc_id)


def test_with_vpc_interface(linode_with_vpc_interface):
linode_json, vpc_json = linode_with_vpc_interface

config_json = json.loads(
exec_test_command(
BASE_CMD
+ [
"configs-list",
str(linode_json["id"]),
"--json",
"--suppress-warnings",
]
)
.stdout.decode()
.rstrip()
)[0]

vpc_interface = config_json["interfaces"][0]
public_interface = config_json["interfaces"][1]

assert vpc_interface["primary"]
assert vpc_interface["purpose"] == "vpc"
assert vpc_interface["subnet_id"] == vpc_json["subnets"][0]["id"]
assert vpc_interface["vpc_id"] == vpc_json["id"]
assert vpc_interface["ipv4"]["vpc"] == "10.0.0.5"
assert vpc_interface["ipv4"]["nat_1_1"] == linode_json["ipv4"][0]

assert not public_interface["primary"]
assert public_interface["purpose"] == "public"
35 changes: 6 additions & 29 deletions tests/integration/vpc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,17 @@

import pytest

from tests.integration.conftest import get_regions_with_capabilities
from tests.integration.conftest import (
create_vpc_w_subnet,
get_regions_with_capabilities,
)
from tests.integration.helpers import delete_target_id, exec_test_command


@pytest.fixture
def test_vpc_w_subnet():
region = get_regions_with_capabilities(["VPCs"])[0]

vpc_label = str(time.time_ns()) + "label"

subnet_label = str(time.time_ns()) + "label"

vpc_id = (
exec_test_command(
[
"linode-cli",
"vpcs",
"create",
"--label",
vpc_label,
"--region",
region,
"--subnets.ipv4",
"10.0.0.0/24",
"--subnets.label",
subnet_label,
"--no-headers",
"--text",
"--format=id",
]
)
.stdout.decode()
.rstrip()
)
vpc_json = create_vpc_w_subnet()
vpc_id = str(vpc_json["id"])

yield vpc_id

Expand Down

0 comments on commit 6ea0384

Please sign in to comment.