Skip to content

Commit 3eae0f6

Browse files
committed
Create test for backend_vpcs
1 parent 04c2c30 commit 3eae0f6

3 files changed

Lines changed: 92 additions & 3 deletions

File tree

tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def create_vpc_w_subnet():
214214
See: https://github.com/pytest-dev/pytest/issues/1216
215215
"""
216216

217-
region = get_random_region_with_caps(required_capabilities=["VPCs"])
217+
region = get_random_region_with_caps(required_capabilities=["VPCs", "NodeBalancers"])
218218
vpc_label = get_random_text(5) + "label"
219219
subnet_label = get_random_text(5) + "label"
220220

tests/integration/nodebalancers/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
from tests.integration.conftest import create_vpc_w_subnet
34
from tests.integration.helpers import (
45
BASE_CMDS,
56
check_attribute_value,
@@ -336,3 +337,12 @@ def simple_nodebalancer_with_config(linode_cloud_firewall):
336337
yield nodebalancer_id, config_id
337338

338339
delete_target_id(target="nodebalancers", id=nodebalancer_id)
340+
341+
342+
@pytest.fixture
343+
def get_vpc_with_subnet():
344+
vpc_json = create_vpc_w_subnet()
345+
346+
yield vpc_json
347+
348+
delete_target_id(target="vpcs", id=str(vpc_json["id"]))

tests/integration/nodebalancers/test_node_balancers.py

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
import ipaddress
2+
import json
13
import re
24

35
import pytest
46

57
from linodecli.exit_codes import ExitCodes
68
from tests.integration.helpers import (
79
BASE_CMDS,
10+
delete_target_id,
811
exec_failing_test_command,
912
exec_test_command,
1013
)
1114

1215

16+
def nodebalancer_created():
17+
return "[0-9]+,balancer[0-9]+,us-ord,[0-9]+-[0-9]+-[0-9]+-[0-9]+.ip.linodeusercontent.com,0"
18+
19+
1320
def test_fail_to_create_nodebalancer_without_region():
1421
result = exec_failing_test_command(
1522
BASE_CMDS["nodebalancers"]
@@ -537,5 +544,77 @@ def test_view_node_for_node_balancer_udp_configuration(
537544
)
538545

539546

540-
def nodebalancer_created():
541-
return "[0-9]+,balancer[0-9]+,us-ord,[0-9]+-[0-9]+-[0-9]+-[0-9]+.ip.linodeusercontent.com,0"
547+
def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
548+
vpc = get_vpc_with_subnet
549+
550+
nb_attrs = exec_test_command(
551+
BASE_CMDS["nodebalancers"]
552+
+ [
553+
"create",
554+
"--region",
555+
vpc["region"],
556+
"--backend_vpcs.subnet_id",
557+
str(vpc["subnets"][0]["id"]),
558+
"--text",
559+
"--delimiter",
560+
",",
561+
"--no-headers",
562+
]
563+
).split(",")
564+
565+
assert isinstance(ipaddress.ip_address(nb_attrs[5]), ipaddress.IPv4Address)
566+
assert isinstance(ipaddress.ip_address(nb_attrs[6]), ipaddress.IPv6Address)
567+
assert nb_attrs[-2] == "public"
568+
assert nb_attrs[-1] == ""
569+
570+
nb_vpcs = exec_test_command(
571+
BASE_CMDS["nodebalancers"]
572+
+ [
573+
"vpcs-list",
574+
nb_attrs[0],
575+
"--json",
576+
]
577+
)
578+
nb_vpcs = json.loads(nb_vpcs)
579+
580+
assert len(nb_vpcs) == 1
581+
assert nb_vpcs[0]["purpose"] == "backend"
582+
583+
nb_vpc = exec_test_command(
584+
BASE_CMDS["nodebalancers"]
585+
+ [
586+
"vpc-view",
587+
nb_attrs[0],
588+
str(nb_vpcs[0]["id"]),
589+
"--json",
590+
]
591+
)
592+
nb_vpc = json.loads(nb_vpc)
593+
594+
assert nb_vpc[0]["purpose"] == "backend"
595+
596+
# TODO: Uncomment when API implementation of /backend_vpcs and /frontend_vpcs endpoints is finished
597+
# nb_backend_vpcs = exec_test_command(
598+
# BASE_CMDS["nodebalancers"]
599+
# + [
600+
# "backend_vpcs-list",
601+
# nb_attrs[0],
602+
# "--json",
603+
# ]
604+
# )
605+
# nb_backend_vpcs = json.loads(nb_backend_vpcs)
606+
# assert len(nb_backend_vpcs) == 1
607+
# assert nb_backend_vpcs[0]["purpose"] == "backend"
608+
#
609+
# nb_frontend_vpcs = exec_test_command(
610+
# BASE_CMDS["nodebalancers"]
611+
# + [
612+
# "frontend_vpcs-list",
613+
# nb_attrs[0],
614+
# "--json",
615+
# ]
616+
# )
617+
# nb_frontend_vpcs = json.loads(nb_frontend_vpcs)
618+
# assert len(nb_frontend_vpcs) == 0
619+
620+
delete_target_id(target="nodebalancers", id=nb_attrs[0])

0 commit comments

Comments
 (0)