Skip to content

Commit 8c01958

Browse files
committed
Create integration tests for NodeBalancer Front-End IP & 40Gbps
Covered endpoints: /v4beta/nodebalancers /v4beta/nodebalancers/<nb_id>/vpcs /v4beta/nodebalancers/<nb_id>/vpcs/<nb_vpc_config_id> /v4beta/nodebalancers/<nb_id>/backend_vpcs /v4beta/nodebalancers/<nb_id>/frontend_vpcs
1 parent 31c34c5 commit 8c01958

File tree

2 files changed

+223
-1
lines changed

2 files changed

+223
-1
lines changed

test/integration/conftest.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def create_vpc(test_linode_client):
457457
vpc = client.vpcs.create(
458458
label=label,
459459
region=get_region(
460-
test_linode_client, {"VPCs", "VPC IPv6 Stack", "Linode Interfaces"}
460+
test_linode_client, {"VPCs", "VPC IPv6 Stack", "VPC Dual Stack", "Linode Interfaces", "NodeBalancers"}
461461
),
462462
description="test description",
463463
ipv6=[{"range": "auto"}],
@@ -467,6 +467,24 @@ def create_vpc(test_linode_client):
467467
vpc.delete()
468468

469469

470+
@pytest.fixture(scope="session")
471+
def create_vpc_ipv4(test_linode_client):
472+
client = test_linode_client
473+
474+
label = get_test_label(length=10) + "-ipv4"
475+
476+
vpc = client.vpcs.create(
477+
label=label,
478+
region=get_region(
479+
test_linode_client, {"VPCs", "Linode Interfaces", "NodeBalancers"}
480+
),
481+
description="test description"
482+
)
483+
yield vpc
484+
485+
vpc.delete()
486+
487+
470488
@pytest.fixture(scope="session")
471489
def create_vpc_with_subnet(test_linode_client, create_vpc):
472490
subnet = create_vpc.subnet_create(
@@ -480,6 +498,18 @@ def create_vpc_with_subnet(test_linode_client, create_vpc):
480498
subnet.delete()
481499

482500

501+
@pytest.fixture(scope="session")
502+
def create_vpc_with_subnet_ipv4(test_linode_client, create_vpc_ipv4):
503+
subnet = create_vpc_ipv4.subnet_create(
504+
label="test-subnet",
505+
ipv4="10.0.0.0/24"
506+
)
507+
508+
yield create_vpc_ipv4, subnet
509+
510+
subnet.delete()
511+
512+
483513
@pytest.fixture(scope="session")
484514
def create_vpc_with_subnet_and_linode(
485515
test_linode_client, create_vpc_with_subnet, e2e_test_firewall

test/integration/models/nodebalancer/test_nodebalancer.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ipaddress
12
import re
23
from test.integration.conftest import (
34
get_api_ca_file,
@@ -272,3 +273,194 @@ def test_nodebalancer_types(test_linode_client):
272273
isinstance(region_price.monthly, (float, int))
273274
and region_price.monthly >= 0
274275
)
276+
277+
278+
def test_nb_with_backend_only(test_linode_client, create_vpc_with_subnet):
279+
client = test_linode_client
280+
vpc = create_vpc_with_subnet[0].id
281+
vpc_region = create_vpc_with_subnet[0].region
282+
subnet = create_vpc_with_subnet[1].id
283+
label = get_test_label(8)
284+
285+
nb = client.nodebalancer_create(
286+
region=vpc_region, label=label, vpcs=[{"vpc_id": vpc,"subnet_id": subnet}]
287+
)
288+
289+
assert isinstance(ipaddress.ip_address(nb.ipv4.address), ipaddress.IPv4Address)
290+
assert isinstance(ipaddress.ip_address(nb.ipv6), ipaddress.IPv6Address)
291+
assert nb.frontend_address_type == 'public'
292+
assert nb.frontend_vpc_subnet_id is None
293+
294+
nb_get = NodeBalancer(client, nb.id)
295+
nb_vpcs = nb_get.vpcs()
296+
297+
assert len(nb_vpcs) == 1
298+
assert nb_vpcs[0].purpose == 'backend'
299+
300+
nb_vpc = nb_get.vpc(nb_vpcs[0].id)
301+
302+
assert nb_vpc.purpose == 'backend'
303+
304+
# TODO: There is no API implementation yet for /backend_vpcs and /frontend_vpcs
305+
# nb_backend_vpcs = nb_get.backend_vpcs()
306+
# assert len(nb_backend_vpcs) == 1
307+
# assert nb_backend_vpcs[0].purpose == 'backend'
308+
#
309+
# nb_frontend_vpcs = nb_get.frontend_vpcs()
310+
# assert len(nb_frontend_vpcs) == 0
311+
312+
nb.delete()
313+
314+
315+
def test_nb_with_frontend_ipv4_only_in_single_stack_vpc(test_linode_client, create_vpc_with_subnet_ipv4):
316+
client = test_linode_client
317+
vpc_region = create_vpc_with_subnet_ipv4[0].region
318+
subnet = create_vpc_with_subnet_ipv4[1].id
319+
label = get_test_label(8)
320+
ipv4_address = "10.0.0.2" # first available address
321+
322+
nb = client.nodebalancer_create(
323+
region=vpc_region,
324+
label=label,
325+
frontend_vpcs=[{"subnet_id": subnet, "ipv4_range": "10.0.0.0/24"}],
326+
type="premium"
327+
)
328+
assert nb.ipv4.address == ipv4_address
329+
assert nb.ipv6 is None
330+
assert nb.frontend_address_type == 'vpc'
331+
assert nb.frontend_vpc_subnet_id == subnet
332+
333+
# TODO: There is no API implementation yet for /backend_vpcs and /frontend_vpcs
334+
# nb_frontend_vpcs = nb_get.frontend_vpcs()
335+
# assert len(nb_frontend_vpcs) == 1
336+
# assert nb_frontend_vpcs[0].purpose == 'frontend'
337+
#
338+
# nb_backend_vpcs = nb_get.backend_vpcs()
339+
# assert len(nb_backend_vpcs) == 0
340+
341+
nb.delete()
342+
343+
344+
def test_nb_with_frontend_ipv6_only_in_single_stack_vpc(test_linode_client, create_vpc_with_subnet_ipv4):
345+
client = test_linode_client
346+
vpc_region = create_vpc_with_subnet_ipv4[0].region
347+
subnet = create_vpc_with_subnet_ipv4[1].id
348+
label = get_test_label(8)
349+
350+
with pytest.raises(ApiError) as err:
351+
client.nodebalancer_create(
352+
region=vpc_region,
353+
label=label,
354+
frontend_vpcs=[{"subnet_id": subnet, "ipv6_range": "/62"}],
355+
type="premium"
356+
)
357+
assert "No IPv6 subnets available in VPC" in str(err.json)
358+
359+
360+
def test_nb_with_frontend_and_default_type(test_linode_client, create_vpc_with_subnet):
361+
client = test_linode_client
362+
vpc_region = create_vpc_with_subnet[0].region
363+
subnet = create_vpc_with_subnet[1].id
364+
label = get_test_label(8)
365+
366+
with pytest.raises(ApiError) as err:
367+
client.nodebalancer_create(
368+
region=vpc_region,
369+
label=label,
370+
frontend_vpcs=[{"subnet_id": subnet}],
371+
)
372+
assert "Nodebalancer with frontend VPC IP must be premium" in str(err.json)
373+
374+
375+
def test_nb_with_frontend_and_premium40gb_type(test_linode_client):
376+
region = "us-iad" # premium_40gb type can be used in specific regions only
377+
client = test_linode_client
378+
379+
vpc = client.vpcs.create(
380+
label=get_test_label(length=10),
381+
region=region,
382+
description="test description",
383+
ipv6=[{"range": "auto"}],
384+
)
385+
386+
subnet = vpc.subnet_create(
387+
label="test-subnet",
388+
ipv4="10.0.0.0/24",
389+
ipv6=[{"range": "auto"}],
390+
)
391+
392+
nb = client.nodebalancer_create(
393+
region=region,
394+
label=get_test_label(length=8),
395+
frontend_vpcs=[{"subnet_id": subnet.id}],
396+
type="premium_40gb"
397+
)
398+
assert nb.type == 'premium_40gb'
399+
400+
nb_get = test_linode_client.load(
401+
NodeBalancer,
402+
nb.id,
403+
)
404+
assert nb_get.type == 'premium_40gb'
405+
406+
nb.delete()
407+
vpc.delete()
408+
409+
410+
def test_nb_with_frontend_and_backend_in_different_vpcs(test_linode_client, create_vpc_with_subnet):
411+
client = test_linode_client
412+
region = create_vpc_with_subnet[0].region
413+
vpc_backend = create_vpc_with_subnet[0].id
414+
subnet_backend = create_vpc_with_subnet[1].id
415+
label = get_test_label(8)
416+
ipv4_range = "10.0.0.0/24"
417+
ipv4_address = "10.0.0.2" # first available address
418+
419+
vpc_frontend = client.vpcs.create(
420+
label=get_test_label(length=10),
421+
region=region,
422+
description="test description",
423+
ipv6=[{"range": "auto"}],
424+
)
425+
426+
subnet_frontend = vpc_frontend.subnet_create(
427+
label="test-subnet",
428+
ipv4=ipv4_range,
429+
ipv6=[{"range": "auto"}],
430+
)
431+
ipv6_range = subnet_frontend.ipv6[0].range
432+
ipv6_address = ipv6_range.split("::")[0] + ":1::1"
433+
434+
nb = client.nodebalancer_create(
435+
region=region,
436+
label=label,
437+
vpcs=[{"vpc_id": vpc_backend,"subnet_id": subnet_backend}],
438+
frontend_vpcs=[{"subnet_id": subnet_frontend.id, "ipv4_range": ipv4_range, "ipv6_range": ipv6_range}],
439+
type="premium"
440+
)
441+
442+
assert nb.ipv4.address == ipv4_address
443+
assert nb.ipv6 == ipv6_address
444+
assert nb.frontend_address_type == 'vpc'
445+
assert nb.frontend_vpc_subnet_id == subnet_frontend.id
446+
447+
nb_get = NodeBalancer(client, nb.id)
448+
nb_vpcs = nb_get.vpcs()
449+
450+
assert len(nb_vpcs) == 2
451+
assert nb_vpcs[0].ipv4_range == f"{ipv4_address}/32"
452+
assert nb_vpcs[0].ipv6_range == f"{ipv6_address[:-1]}/64"
453+
assert nb_vpcs[0].purpose == 'frontend'
454+
assert nb_vpcs[1].purpose == 'backend'
455+
456+
# TODO: There is no API implementation yet for /backend_vpcs and /frontend_vpcs
457+
# nb_backend_vpcs = nb_get.backend_vpcs()
458+
# assert len(nb_backend_vpcs) == 1
459+
# assert nb_backend_vpcs[0].purpose == 'backend'
460+
#
461+
# nb_frontend_vpcs = nb_get.frontend_vpcs()
462+
# assert len(nb_frontend_vpcs) == 1
463+
# assert nb_frontend_vpcs[0].purpose == 'frontend'
464+
465+
nb.delete()
466+
vpc_frontend.delete()

0 commit comments

Comments
 (0)