Skip to content

Commit fd3b6a1

Browse files
committed
Create test for frontend VPC IPv4
1 parent 3eae0f6 commit fd3b6a1

1 file changed

Lines changed: 67 additions & 14 deletions

File tree

tests/integration/nodebalancers/test_node_balancers.py

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -555,23 +555,22 @@ def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
555555
vpc["region"],
556556
"--backend_vpcs.subnet_id",
557557
str(vpc["subnets"][0]["id"]),
558-
"--text",
559-
"--delimiter",
560-
",",
561-
"--no-headers",
558+
"--json",
562559
]
563-
).split(",")
560+
)
561+
nb_attrs = json.loads(nb_attrs)
562+
nb_id = str(nb_attrs[0]["id"])
564563

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] == ""
564+
assert isinstance(ipaddress.ip_address(nb_attrs[0]["ipv4"]), ipaddress.IPv4Address)
565+
assert isinstance(ipaddress.ip_address(nb_attrs[0]["ipv6"]), ipaddress.IPv6Address)
566+
assert nb_attrs[0]["frontend_address_type"] == "public"
567+
assert nb_attrs[0]["frontend_vpc_subnet_id"] is None
569568

570569
nb_vpcs = exec_test_command(
571570
BASE_CMDS["nodebalancers"]
572571
+ [
573572
"vpcs-list",
574-
nb_attrs[0],
573+
nb_id,
575574
"--json",
576575
]
577576
)
@@ -584,7 +583,7 @@ def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
584583
BASE_CMDS["nodebalancers"]
585584
+ [
586585
"vpc-view",
587-
nb_attrs[0],
586+
nb_id,
588587
str(nb_vpcs[0]["id"]),
589588
"--json",
590589
]
@@ -598,7 +597,7 @@ def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
598597
# BASE_CMDS["nodebalancers"]
599598
# + [
600599
# "backend_vpcs-list",
601-
# nb_attrs[0],
600+
# nb_id,
602601
# "--json",
603602
# ]
604603
# )
@@ -610,11 +609,65 @@ def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
610609
# BASE_CMDS["nodebalancers"]
611610
# + [
612611
# "frontend_vpcs-list",
613-
# nb_attrs[0],
612+
# nb_id,
614613
# "--json",
615614
# ]
616615
# )
617616
# nb_frontend_vpcs = json.loads(nb_frontend_vpcs)
618617
# assert len(nb_frontend_vpcs) == 0
619618

620-
delete_target_id(target="nodebalancers", id=nb_attrs[0])
619+
delete_target_id(target="nodebalancers", id=nb_id)
620+
621+
622+
def test_nb_with_frontend_ipv4_only(get_vpc_with_subnet):
623+
vpc = get_vpc_with_subnet
624+
ipv4_address = "10.0.0.2" # first available address
625+
626+
nb_attrs = exec_test_command(
627+
BASE_CMDS["nodebalancers"]
628+
+ [
629+
"create",
630+
"--region",
631+
vpc["region"],
632+
"--frontend_vpcs.subnet_id",
633+
str(vpc["subnets"][0]["id"]),
634+
"--frontend_vpcs.ipv4_range",
635+
"10.0.0.0/24",
636+
"--type",
637+
"premium",
638+
"--json",
639+
]
640+
)
641+
nb_attrs = json.loads(nb_attrs)
642+
nb_id = str(nb_attrs[0]["id"])
643+
644+
assert nb_attrs[0]["ipv4"] == ipv4_address
645+
assert nb_attrs[0]["ipv6"] is None
646+
assert nb_attrs[0]["frontend_address_type"] == "vpc"
647+
assert nb_attrs[0]["frontend_vpc_subnet_id"] == vpc["subnets"][0]["id"]
648+
649+
# TODO: Uncomment when API implementation of /backend_vpcs and /frontend_vpcs endpoints is finished
650+
# nb_frontend_vpcs = exec_test_command(
651+
# BASE_CMDS["nodebalancers"]
652+
# + [
653+
# "frontend_vpcs-list",
654+
# nb_id,
655+
# "--json",
656+
# ]
657+
# )
658+
# nb_frontend_vpcs = json.loads(nb_frontend_vpcs)
659+
# assert len(nb_frontend_vpcs) == 1
660+
# assert nb_frontend_vpcs[0]["purpose"] == "frontend"
661+
#
662+
# nb_backend_vpcs = exec_test_command(
663+
# BASE_CMDS["nodebalancers"]
664+
# + [
665+
# "backend_vpcs-list",
666+
# nb_id,
667+
# "--json",
668+
# ]
669+
# )
670+
# nb_backend_vpcs = json.loads(nb_backend_vpcs)
671+
# assert len(nb_backend_vpcs) == 0
672+
673+
delete_target_id(target="nodebalancers", id=nb_id)

0 commit comments

Comments
 (0)