Skip to content

Commit aa6f02a

Browse files
committed
Modify tests to filter out invalid regions for premium NBs
1 parent abf8c8f commit aa6f02a

File tree

2 files changed

+88
-25
lines changed

2 files changed

+88
-25
lines changed

test/integration/conftest.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
wait_for_condition,
1010
)
1111
from test.integration.models.database.helpers import get_db_engine_id
12-
from typing import Optional, Set
12+
from typing import List, Optional, Set
1313

1414
import pytest
1515
import requests
@@ -112,9 +112,18 @@ def get_regions(
112112

113113

114114
def get_region(
115-
client: LinodeClient, capabilities: Set[str] = None, site_type: str = "core"
115+
client: LinodeClient,
116+
capabilities: Set[str] = None,
117+
site_type: str = "core",
118+
valid_regions: List[str] = None,
116119
):
117-
return random.choice(get_regions(client, capabilities, site_type))
120+
regions = get_regions(client, capabilities, site_type)
121+
122+
# To filter out regions that cannot be used for the Linode resource
123+
if valid_regions:
124+
regions = [reg for reg in regions if reg.id in valid_regions]
125+
126+
return random.choice(regions)
118127

119128

120129
def get_api_ca_file():
@@ -516,6 +525,41 @@ def create_vpc_with_subnet_ipv4(test_linode_client, create_vpc_ipv4):
516525
subnet.delete()
517526

518527

528+
@pytest.fixture(scope="function")
529+
def create_vpc_with_subnet_in_premium_region(request, test_linode_client):
530+
premium_regions = getattr(request, "param", None)
531+
client = test_linode_client
532+
label = get_test_label(length=10)
533+
534+
vpc = client.vpcs.create(
535+
label=label,
536+
region=get_region(
537+
client,
538+
{
539+
"VPCs",
540+
"VPC IPv6 Stack",
541+
"VPC Dual Stack",
542+
"Linode Interfaces",
543+
"NodeBalancers",
544+
},
545+
valid_regions=premium_regions,
546+
),
547+
description="test description",
548+
ipv6=[{"range": "auto"}],
549+
)
550+
551+
subnet = vpc.subnet_create(
552+
label="test-subnet",
553+
ipv4="10.0.0.0/24",
554+
ipv6=[{"range": "auto"}],
555+
)
556+
557+
yield vpc, subnet
558+
559+
subnet.delete()
560+
vpc.delete()
561+
562+
519563
@pytest.fixture(scope="session")
520564
def create_vpc_with_subnet_and_linode(
521565
test_linode_client, create_vpc_with_subnet, e2e_test_firewall

test/integration/models/nodebalancer/test_nodebalancer.py

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@
1818
RegionPrice,
1919
)
2020

21+
# Lists of valid regions where NodeBalancers of type "premium" or "premium_40gb" can be created
22+
PREMIUM_REGIONS = [
23+
"nl-ams",
24+
"jp-tyo-3",
25+
"sg-sin-2",
26+
"de-fra-2",
27+
"in-bom-2",
28+
"gb-lon",
29+
"us-lax",
30+
"id-cgk",
31+
"us-mia",
32+
"it-mil",
33+
"jp-osa",
34+
"in-maa",
35+
"se-sto",
36+
"br-gru",
37+
"us-sea",
38+
"fr-par",
39+
"us-iad",
40+
]
41+
PREMIUM_40GB_REGIONS = ["us-iad"]
42+
2143
TEST_REGION = get_region(
2244
LinodeClient(
2345
token=get_token(),
@@ -390,27 +412,22 @@ def test_nb_with_frontend_and_default_type(
390412
assert "NodeBalancer with frontend VPC IP must be premium" in error_msg
391413

392414

393-
def test_nb_with_frontend_and_premium40gb_type(test_linode_client):
394-
region = "us-iad" # premium_40gb type can be used in specific regions only
415+
@pytest.mark.parametrize(
416+
"create_vpc_with_subnet_in_premium_region",
417+
[PREMIUM_40GB_REGIONS],
418+
indirect=True,
419+
)
420+
def test_nb_with_frontend_and_premium40gb_type(
421+
test_linode_client, create_vpc_with_subnet_in_premium_region
422+
):
395423
client = test_linode_client
396424

397-
vpc = client.vpcs.create(
398-
label=get_test_label(length=10),
399-
region=region,
400-
description="test description",
401-
ipv6=[{"range": "auto"}],
402-
)
403-
404-
subnet = vpc.subnet_create(
405-
label="test-subnet",
406-
ipv4="10.0.0.0/24",
407-
ipv6=[{"range": "auto"}],
408-
)
409-
410425
nb = client.nodebalancer_create(
411-
region=region,
426+
region=create_vpc_with_subnet_in_premium_region[0].region,
412427
label=get_test_label(length=8),
413-
frontend_vpcs=[{"subnet_id": subnet.id}],
428+
frontend_vpcs=[
429+
{"subnet_id": create_vpc_with_subnet_in_premium_region[1].id}
430+
],
414431
type="premium_40gb",
415432
)
416433
assert nb.type == "premium_40gb"
@@ -422,16 +439,18 @@ def test_nb_with_frontend_and_premium40gb_type(test_linode_client):
422439
assert nb_get.type == "premium_40gb"
423440

424441
nb.delete()
425-
vpc.delete()
426442

427443

444+
@pytest.mark.parametrize(
445+
"create_vpc_with_subnet_in_premium_region", [PREMIUM_REGIONS], indirect=True
446+
)
428447
def test_nb_with_frontend_and_backend_in_different_vpcs(
429-
test_linode_client, create_vpc_with_subnet
448+
test_linode_client, create_vpc_with_subnet_in_premium_region
430449
):
431450
client = test_linode_client
432-
region = create_vpc_with_subnet[0].region
433-
vpc_backend = create_vpc_with_subnet[0].id
434-
subnet_backend = create_vpc_with_subnet[1].id
451+
region = create_vpc_with_subnet_in_premium_region[0].region
452+
vpc_backend = create_vpc_with_subnet_in_premium_region[0].id
453+
subnet_backend = create_vpc_with_subnet_in_premium_region[1].id
435454
label = get_test_label(8)
436455
ipv4_range = "10.0.0.0/24"
437456
ipv4_address = "10.0.0.2" # first available address

0 commit comments

Comments
 (0)