Skip to content

Commit 49cfdff

Browse files
committed
Create test for: premium_40gb & error msgs
1 parent 397bc44 commit 49cfdff

4 files changed

Lines changed: 110 additions & 6 deletions

File tree

tests/integration/conftest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from itertools import count
1212
from pathlib import Path
1313
from random import randint
14-
from typing import Callable, Optional
14+
from typing import Callable, List, Optional
1515

1616
import pytest
1717
import requests
@@ -203,7 +203,7 @@ def _generate_test_files(
203203
return _generate_test_files
204204

205205

206-
def create_vpc_w_subnet():
206+
def create_vpc_w_subnet(valid_regions: List[str] = None):
207207
"""
208208
Creates and returns a VPC and a corresponding subnet.
209209
@@ -214,7 +214,10 @@ 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", "NodeBalancers"])
217+
region = get_random_region_with_caps(
218+
required_capabilities=["VPCs", "NodeBalancers"],
219+
valid_regions=valid_regions,
220+
)
218221
vpc_label = get_random_text(5) + "label"
219222
subnet_label = get_random_text(5) + "label"
220223

tests/integration/helpers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ def retry_exec_test_command_with_delay(
189189

190190

191191
def get_random_region_with_caps(
192-
required_capabilities: List[str], site_type="core"
192+
required_capabilities: List[str],
193+
site_type: str = "core",
194+
valid_regions: List[str] = None,
193195
):
194196
json_regions_data = exec_test_command(
195197
["linode-cli", "regions", "ls", "--json"]
@@ -208,6 +210,10 @@ def get_random_region_with_caps(
208210
# Extract the region ids
209211
matching_region_ids = [region["id"] for region in matching_regions]
210212

213+
# To filter out regions that cannot be used for the Linode resource
214+
if valid_regions:
215+
matching_region_ids = [reg for reg in matching_region_ids if reg in valid_regions]
216+
211217
return random.choice(matching_region_ids) if matching_region_ids else None
212218

213219

tests/integration/nodebalancers/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
import pytest
24

35
from tests.integration.conftest import create_vpc_w_subnet
@@ -6,6 +8,8 @@
68
check_attribute_value,
79
delete_target_id,
810
exec_test_command,
11+
get_random_region_with_caps,
12+
get_random_text,
913
wait_for_condition,
1014
)
1115
from tests.integration.linodes.helpers import DEFAULT_TEST_IMAGE
@@ -340,8 +344,9 @@ def simple_nodebalancer_with_config(linode_cloud_firewall):
340344

341345

342346
@pytest.fixture
343-
def get_vpc_with_subnet():
344-
vpc_json = create_vpc_w_subnet()
347+
def get_vpc_with_subnet(request):
348+
premium_regions = getattr(request, "param", None)
349+
vpc_json = create_vpc_w_subnet(premium_regions)
345350

346351
yield vpc_json
347352

tests/integration/nodebalancers/test_node_balancers.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,30 @@
1313
)
1414

1515

16+
# Lists of valid regions where NodeBalancers of type "premium" or "premium_40gb" can be created
17+
PREMIUM_REGIONS = [
18+
"nl-ams",
19+
"jp-tyo-3",
20+
"sg-sin-2",
21+
"de-fra-2",
22+
"in-bom-2",
23+
"gb-lon",
24+
"us-lax",
25+
"id-cgk",
26+
"us-mia",
27+
"it-mil",
28+
"jp-osa",
29+
"in-maa",
30+
"se-sto",
31+
"br-gru",
32+
"us-sea",
33+
"fr-par",
34+
"us-iad",
35+
"pl-labkrk-2", # DevCloud
36+
]
37+
PREMIUM_40GB_REGIONS = ["us-iad"] # No DevCloud region for premium_40gb type
38+
39+
1640
def nodebalancer_created():
1741
return "[0-9]+,balancer[0-9]+,us-ord,[0-9]+-[0-9]+-[0-9]+-[0-9]+.ip.linodeusercontent.com,0"
1842

@@ -595,6 +619,7 @@ def test_nb_with_backend_vpc_only(get_vpc_with_subnet):
595619
delete_target_id(target="nodebalancers", id=nb_id)
596620

597621

622+
@pytest.mark.parametrize("get_vpc_with_subnet", [PREMIUM_REGIONS], indirect=True)
598623
def test_nb_with_frontend_ipv4_only(get_vpc_with_subnet):
599624
vpc = get_vpc_with_subnet
600625
ipv4_address = "10.0.0.2" # first available address
@@ -637,3 +662,68 @@ def test_nb_with_frontend_ipv4_only(get_vpc_with_subnet):
637662
# assert len(nb_backend_vpcs) == 0
638663

639664
delete_target_id(target="nodebalancers", id=nb_id)
665+
666+
667+
@pytest.mark.parametrize("get_vpc_with_subnet", [PREMIUM_REGIONS], indirect=True)
668+
def test_nb_with_frontend_ipv6_in_single_stack_vpc_fail(get_vpc_with_subnet):
669+
vpc = get_vpc_with_subnet
670+
671+
result = exec_failing_test_command(
672+
BASE_CMDS["nodebalancers"]
673+
+ [
674+
"create",
675+
"--region",
676+
vpc["region"],
677+
"--frontend_vpcs.subnet_id",
678+
str(vpc["subnets"][0]["id"]),
679+
"--frontend_vpcs.ipv6_range",
680+
"/62",
681+
"--type",
682+
"premium",
683+
],
684+
)
685+
assert "Request failed: 400" in result
686+
assert "No IPv6 subnets available in VPC" in result
687+
688+
689+
@pytest.mark.parametrize("get_vpc_with_subnet", [PREMIUM_REGIONS], indirect=True)
690+
def test_nb_with_frontend_and_default_type_fail(get_vpc_with_subnet):
691+
vpc = get_vpc_with_subnet
692+
693+
result = exec_failing_test_command(
694+
BASE_CMDS["nodebalancers"]
695+
+ [
696+
"create",
697+
"--region",
698+
vpc["region"],
699+
"--frontend_vpcs.subnet_id",
700+
str(vpc["subnets"][0]["id"]),
701+
],
702+
)
703+
assert "Request failed: 400" in result
704+
assert "NodeBalancer with frontend VPC IP must be premium" in result
705+
706+
707+
@pytest.mark.parametrize(
708+
"get_vpc_with_subnet",
709+
[PREMIUM_40GB_REGIONS],
710+
indirect=True,
711+
)
712+
def test_nb_with_premium40gb_type(get_vpc_with_subnet):
713+
vpc = get_vpc_with_subnet
714+
715+
nb_attrs = exec_test_command(
716+
BASE_CMDS["nodebalancers"]
717+
+ [
718+
"create",
719+
"--region",
720+
vpc["region"],
721+
"--type",
722+
"premium_40gb",
723+
"--json",
724+
],
725+
)
726+
nb_attrs = json.loads(nb_attrs)
727+
assert nb_attrs[0]["type"] == "premium_40gb"
728+
729+
delete_target_id(target="nodebalancers", id=str(nb_attrs[0]["id"]))

0 commit comments

Comments
 (0)