Skip to content

Commit 7934893

Browse files
various changes
1 parent 2cff9cc commit 7934893

File tree

3 files changed

+137
-98
lines changed

3 files changed

+137
-98
lines changed

test/integration/conftest.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
import requests
1313
from requests.exceptions import ConnectionError, RequestException
1414

15-
from linode_api4 import PlacementGroupPolicy, PlacementGroupType
15+
from linode_api4 import (
16+
InterfaceGeneration,
17+
LinodeInterfaceDefaultRouteOptions,
18+
LinodeInterfaceOptions,
19+
LinodeInterfacePublicOptions,
20+
LinodeInterfaceVLANOptions,
21+
LinodeInterfaceVPCOptions,
22+
PlacementGroupPolicy,
23+
PlacementGroupType,
24+
)
1625
from linode_api4.linode_client import LinodeClient
1726
from linode_api4.objects import Region
1827

@@ -521,3 +530,73 @@ def linode_for_vlan_tests(test_linode_client, e2e_test_firewall):
521530
yield linode_instance
522531

523532
linode_instance.delete()
533+
534+
535+
@pytest.fixture(scope="session")
536+
def linode_with_interface_generation_linode(
537+
test_linode_client,
538+
e2e_test_firewall,
539+
# We won't be using this all the time, but it's
540+
# necessary for certain consumers of this fixture
541+
create_vpc_with_subnet,
542+
):
543+
client = test_linode_client
544+
545+
label = get_test_label()
546+
547+
instance = client.linode.instance_create(
548+
"g6-nanode-1",
549+
create_vpc_with_subnet[0].region,
550+
label=label,
551+
interface_generation=InterfaceGeneration.LINODE,
552+
booted=False,
553+
)
554+
555+
yield instance
556+
557+
instance.delete()
558+
559+
560+
@pytest.fixture(scope="session")
561+
def linode_with_linode_interfaces(
562+
test_linode_client, e2e_test_firewall, create_vpc_with_subnet
563+
):
564+
client = test_linode_client
565+
vpc, subnet = create_vpc_with_subnet
566+
567+
# Are there regions where VPCs are supported but Linode Interfaces aren't?
568+
region = vpc.region
569+
label = get_test_label()
570+
571+
instance, _ = client.linode.instance_create(
572+
"g6-nanode-1",
573+
region,
574+
image="linode/debian12",
575+
label=label,
576+
booted=False,
577+
interface_generation=InterfaceGeneration.LINODE,
578+
interfaces=[
579+
LinodeInterfaceOptions(
580+
firewall_id=e2e_test_firewall.id,
581+
default_route=LinodeInterfaceDefaultRouteOptions(
582+
ipv4=True,
583+
ipv6=True,
584+
),
585+
public=LinodeInterfacePublicOptions(),
586+
),
587+
LinodeInterfaceOptions(
588+
vpc=LinodeInterfaceVPCOptions(
589+
subnet_id=subnet.id,
590+
),
591+
),
592+
LinodeInterfaceOptions(
593+
vlan=LinodeInterfaceVLANOptions(
594+
vlan_label="test-vlan", ipam_address="10.0.0.5/32"
595+
),
596+
),
597+
],
598+
)
599+
600+
yield instance
601+
602+
instance.delete()

test/integration/models/linode/interfaces/test_interfaces.py

Lines changed: 8 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import copy
22
import ipaddress
3-
from test.integration.helpers import get_test_label
43

54
import pytest
65

76
from linode_api4 import (
87
ApiError,
98
Instance,
10-
InterfaceGeneration,
119
LinodeInterface,
1210
LinodeInterfaceDefaultRouteOptions,
13-
LinodeInterfaceOptions,
1411
LinodeInterfacePublicIPv4AddressOptions,
1512
LinodeInterfacePublicIPv4Options,
1613
LinodeInterfacePublicIPv6Options,
@@ -23,79 +20,11 @@
2320
)
2421

2522

26-
@pytest.fixture(scope="function")
27-
def instance_with_interface_generation_linode(
28-
test_linode_client,
29-
e2e_test_firewall,
30-
# We won't be using this all the time, but it's
31-
# necessary for certain consumers of this fixture
32-
create_vpc_with_subnet,
33-
):
34-
client = test_linode_client
35-
36-
label = get_test_label()
37-
38-
instance = client.linode.instance_create(
39-
"g6-nanode-1",
40-
create_vpc_with_subnet[0].region,
41-
label=label,
42-
interface_generation=InterfaceGeneration.LINODE,
43-
)
44-
45-
yield instance
46-
47-
instance.delete()
48-
49-
50-
@pytest.fixture(scope="session")
51-
def instance_with_interfaces(
52-
test_linode_client, e2e_test_firewall, create_vpc_with_subnet
53-
):
54-
client = test_linode_client
55-
vpc, subnet = create_vpc_with_subnet
56-
57-
# Are there regions where VPCs are supported but Linode Interfaces aren't?
58-
region = vpc.region
59-
label = get_test_label()
60-
61-
instance, _ = client.linode.instance_create(
62-
"g6-nanode-1",
63-
region,
64-
image="linode/debian12",
65-
label=label,
66-
interface_generation=InterfaceGeneration.LINODE,
67-
interfaces=[
68-
LinodeInterfaceOptions(
69-
firewall_id=e2e_test_firewall.id,
70-
default_route=LinodeInterfaceDefaultRouteOptions(
71-
ipv4=True,
72-
ipv6=True,
73-
),
74-
public=LinodeInterfacePublicOptions(),
75-
),
76-
LinodeInterfaceOptions(
77-
vpc=LinodeInterfaceVPCOptions(
78-
subnet_id=subnet.id,
79-
),
80-
),
81-
LinodeInterfaceOptions(
82-
vlan=LinodeInterfaceVLANOptions(
83-
vlan_label="test-vlan", ipam_address="10.0.0.5/32"
84-
),
85-
),
86-
],
87-
)
88-
89-
yield instance
90-
91-
instance.delete()
92-
93-
9423
def test_linode_create_with_linode_interfaces(
9524
create_vpc_with_subnet,
96-
instance_with_interfaces,
25+
linode_with_linode_interfaces,
9726
):
98-
instance: Instance = instance_with_interfaces
27+
instance: Instance = linode_with_linode_interfaces
9928
vpc, subnet = create_vpc_with_subnet
10029

10130
def __assert_base(iface: LinodeInterface):
@@ -164,9 +93,9 @@ def __assert_vlan(iface: LinodeInterface):
16493
def linode_interface_public(
16594
test_linode_client,
16695
e2e_test_firewall,
167-
instance_with_interface_generation_linode,
96+
linode_with_interface_generation_linode,
16897
):
169-
instance: Instance = instance_with_interface_generation_linode
98+
instance: Instance = linode_with_interface_generation_linode
17099

171100
ipv6_range = test_linode_client.networking.ipv6_range_allocate(
172101
64, linode=instance.id
@@ -202,10 +131,10 @@ def linode_interface_public(
202131
def linode_interface_vpc(
203132
test_linode_client,
204133
e2e_test_firewall,
205-
instance_with_interface_generation_linode,
134+
linode_with_interface_generation_linode,
206135
create_vpc_with_subnet,
207136
):
208-
instance: Instance = instance_with_interface_generation_linode
137+
instance: Instance = linode_with_interface_generation_linode
209138
vpc, subnet = create_vpc_with_subnet
210139

211140
yield instance.interface_create(
@@ -238,10 +167,10 @@ def linode_interface_vpc(
238167
def linode_interface_vlan(
239168
test_linode_client,
240169
e2e_test_firewall,
241-
instance_with_interface_generation_linode,
170+
linode_with_interface_generation_linode,
242171
create_vpc_with_subnet,
243172
):
244-
instance: Instance = instance_with_interface_generation_linode
173+
instance: Instance = linode_with_interface_generation_linode
245174

246175
yield instance.interface_create(
247176
vlan=LinodeInterfaceVLANOptions(

test/integration/models/linode/test_linode.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
import pytest
1111

12-
from linode_api4 import InterfaceGeneration, LinodeInterface
12+
from linode_api4 import (
13+
InterfaceGeneration,
14+
LinodeInterface,
15+
)
1316
from linode_api4.errors import ApiError
1417
from linode_api4.objects import (
1518
Config,
@@ -68,7 +71,7 @@ def linode_with_volume_firewall(test_linode_client):
6871

6972

7073
@pytest.fixture(scope="function")
71-
def linode_for_network_interface_tests(test_linode_client, e2e_test_firewall):
74+
def linode_for_legacy_interface_tests(test_linode_client, e2e_test_firewall):
7275
client = test_linode_client
7376
region = get_region(client, {"Linodes", "Cloud Firewall"}, site_type="core")
7477
label = get_test_label(length=8)
@@ -88,7 +91,7 @@ def linode_for_network_interface_tests(test_linode_client, e2e_test_firewall):
8891

8992

9093
@pytest.fixture(scope="function")
91-
def linode_and_vpc_for_network_interface_tests_offline(
94+
def linode_and_vpc_for_legacy_interface_tests_offline(
9295
test_linode_client, create_vpc_with_subnet, e2e_test_firewall
9396
):
9497
vpc, subnet = create_vpc_with_subnet
@@ -614,10 +617,10 @@ def test_linode_initate_migration(test_linode_client, e2e_test_firewall):
614617

615618

616619
def test_linode_upgrade_interfaces(
617-
linode_for_network_interface_tests,
618-
linode_and_vpc_for_network_interface_tests_offline,
620+
linode_for_legacy_interface_tests,
621+
linode_and_vpc_for_legacy_interface_tests_offline,
619622
):
620-
vpc, subnet, linode, _ = linode_and_vpc_for_network_interface_tests_offline
623+
vpc, subnet, linode, _ = linode_and_vpc_for_legacy_interface_tests_offline
621624
config = linode.configs[0]
622625

623626
new_interfaces = [
@@ -709,6 +712,34 @@ def __assert_vlan(iface: LinodeInterface):
709712
__assert_vpc(linode.interfaces[2])
710713

711714

715+
def test_linode_interfaces_settings(linode_with_linode_interfaces):
716+
linode = linode_with_linode_interfaces
717+
settings = linode.interfaces_settings
718+
719+
assert settings.network_helper is not None
720+
assert settings.default_route.ipv4_interface_id == linode.interfaces[0].id
721+
assert settings.default_route.ipv4_eligible_interface_ids == [
722+
linode.interfaces[0].id,
723+
linode.interfaces[1].id,
724+
]
725+
726+
assert settings.default_route.ipv6_interface_id == linode.interfaces[0].id
727+
assert settings.default_route.ipv6_eligible_interface_ids == [
728+
linode.interfaces[0].id
729+
]
730+
731+
# Arbitrary updates
732+
settings.network_helper = True
733+
settings.default_route.ipv4_interface_id = linode.interfaces[1].id
734+
735+
settings.save()
736+
settings.invalidate()
737+
738+
# Assert updates
739+
assert settings.network_helper is not None
740+
assert settings.default_route.ipv4_interface_id == linode.interfaces[1].id
741+
742+
712743
def test_config_update_interfaces(create_linode):
713744
linode = create_linode
714745
config = linode.configs[0]
@@ -792,8 +823,8 @@ def test_save_linode_force(test_linode_client, create_linode):
792823

793824

794825
class TestNetworkInterface:
795-
def test_list(self, linode_for_network_interface_tests):
796-
linode = linode_for_network_interface_tests
826+
def test_list(self, linode_for_legacy_interface_tests):
827+
linode = linode_for_legacy_interface_tests
797828

798829
config: Config = linode.configs[0]
799830

@@ -813,8 +844,8 @@ def test_list(self, linode_for_network_interface_tests):
813844
assert interface[1].label == label
814845
assert interface[1].ipam_address == "10.0.0.3/32"
815846

816-
def test_create_public(self, linode_for_network_interface_tests):
817-
linode = linode_for_network_interface_tests
847+
def test_create_public(self, linode_for_legacy_interface_tests):
848+
linode = linode_for_legacy_interface_tests
818849

819850
config: Config = linode.configs[0]
820851

@@ -831,8 +862,8 @@ def test_create_public(self, linode_for_network_interface_tests):
831862
assert interface.purpose == "public"
832863
assert interface.primary
833864

834-
def test_create_vlan(self, linode_for_network_interface_tests):
835-
linode = linode_for_network_interface_tests
865+
def test_create_vlan(self, linode_for_legacy_interface_tests):
866+
linode = linode_for_legacy_interface_tests
836867

837868
config: Config = linode.configs[0]
838869

@@ -856,10 +887,10 @@ def test_create_vpu(self, test_linode_client, linode_for_vpu_tests):
856887
def test_create_vpc(
857888
self,
858889
test_linode_client,
859-
linode_and_vpc_for_network_interface_tests_offline,
890+
linode_and_vpc_for_legacy_interface_tests_offline,
860891
):
861892
vpc, subnet, linode, _ = (
862-
linode_and_vpc_for_network_interface_tests_offline
893+
linode_and_vpc_for_legacy_interface_tests_offline
863894
)
864895

865896
config: Config = linode.configs[0]
@@ -913,10 +944,10 @@ def test_create_vpc(
913944

914945
def test_update_vpc(
915946
self,
916-
linode_and_vpc_for_network_interface_tests_offline,
947+
linode_and_vpc_for_legacy_interface_tests_offline,
917948
):
918949
vpc, subnet, linode, _ = (
919-
linode_and_vpc_for_network_interface_tests_offline
950+
linode_and_vpc_for_legacy_interface_tests_offline
920951
)
921952

922953
config: Config = linode.configs[0]
@@ -946,8 +977,8 @@ def test_update_vpc(
946977
assert interface.ipv4.nat_1_1 == linode.ipv4[0]
947978
assert interface.ip_ranges == ["10.0.0.9/32"]
948979

949-
def test_reorder(self, linode_for_network_interface_tests):
950-
linode = linode_for_network_interface_tests
980+
def test_reorder(self, linode_for_legacy_interface_tests):
981+
linode = linode_for_legacy_interface_tests
951982

952983
config: Config = linode.configs[0]
953984

0 commit comments

Comments
 (0)