Skip to content

Commit 972fbcc

Browse files
Basic integration test
1 parent 30c5de0 commit 972fbcc

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

linode_api4/objects/linode_interfaces.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ class LinodeInterfaceOptions(JSONObject):
163163
Options accepted when creating or updating a Linode Interface.
164164
"""
165165

166+
always_include = {
167+
# If a default firewall_id isn't configured, the API requires that
168+
# firewall_id is defined in the LinodeInterface POST body.
169+
"firewall_id"
170+
}
171+
166172
firewall_id: Optional[Union[Firewall, int]] = None
167173
default_route: Optional[LinodeInterfaceDefaultRouteOptions] = None
168174
vpc: Optional[LinodeInterfaceVPCOptions] = None

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

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from test.integration.conftest import get_region
1+
import ipaddress
22
from test.integration.helpers import get_test_label
33

44
import pytest
@@ -10,6 +10,7 @@
1010
LinodeInterfaceDefaultRouteOptions,
1111
LinodeInterfaceOptions,
1212
LinodeInterfacePublicOptions,
13+
LinodeInterfaceVLANOptions,
1314
LinodeInterfaceVPCOptions,
1415
)
1516

@@ -21,11 +22,8 @@ def linode_create_with_interfaces(
2122
client = test_linode_client
2223
vpc, subnet = create_vpc_with_subnet
2324

24-
region = get_region(
25-
client,
26-
{"Linodes", "Cloud Firewall", "Linode Interfaces"},
27-
site_type="core",
28-
)
25+
# Are there regions where VPCs are supported but Linode Interfaces aren't
26+
region = vpc.region
2927
label = get_test_label()
3028

3129
instance, _ = client.linode.instance_create(
@@ -44,14 +42,15 @@ def linode_create_with_interfaces(
4442
public=LinodeInterfacePublicOptions(),
4543
),
4644
LinodeInterfaceOptions(
47-
firewall_id=e2e_test_firewall.id,
48-
default_route=LinodeInterfaceDefaultRouteOptions(
49-
ipv4=True,
50-
),
5145
vpc=LinodeInterfaceVPCOptions(
5246
subnet_id=subnet.id,
5347
),
5448
),
49+
LinodeInterfaceOptions(
50+
vlan=LinodeInterfaceVLANOptions(
51+
vlan_label="test-vlan", ipam_address="10.0.0.5/32"
52+
),
53+
),
5554
],
5655
)
5756

@@ -60,8 +59,12 @@ def linode_create_with_interfaces(
6059
instance.delete()
6160

6261

63-
def test_linode_create_with_linode_interfaces(linode_create_with_interfaces):
62+
def test_linode_create_with_linode_interfaces(
63+
create_vpc_with_subnet,
64+
linode_create_with_interfaces,
65+
):
6466
instance: Instance = linode_create_with_interfaces
67+
vpc, subnet = create_vpc_with_subnet
6568

6669
def __assert_base(iface: LinodeInterface):
6770
assert iface.id is not None
@@ -88,8 +91,38 @@ def __assert_public(iface: LinodeInterface):
8891
assert len(iface.public.ipv6.shared) == 0
8992
assert len(iface.public.ipv6.ranges) == 0
9093

94+
def __assert_vpc(iface: LinodeInterface):
95+
__assert_base(iface)
96+
97+
assert not iface.default_route.ipv4
98+
assert not iface.default_route.ipv6
99+
100+
assert iface.vpc.vpc_id == vpc.id
101+
assert iface.vpc.subnet_id == subnet.id
102+
103+
assert ipaddress.ip_address(
104+
iface.vpc.ipv4.addresses[0].address
105+
) in ipaddress.ip_network(subnet.ipv4)
106+
assert iface.vpc.ipv4.addresses[0].primary
107+
assert iface.vpc.ipv4.addresses[0].nat_1_1_address is None
108+
109+
assert len(iface.vpc.ipv4.ranges) == 0
110+
111+
def __assert_vlan(iface: LinodeInterface):
112+
__assert_base(iface)
113+
114+
assert not iface.default_route.ipv4
115+
assert not iface.default_route.ipv6
116+
117+
assert iface.vlan.vlan_label == "test-vlan"
118+
assert iface.vlan.ipam_address == "10.0.0.5/32"
119+
91120
__assert_public(instance.interfaces[0])
121+
__assert_vpc(instance.interfaces[1])
122+
__assert_vlan(instance.interfaces[2])
92123

93124
instance.invalidate()
94125

95126
__assert_public(instance.interfaces[0])
127+
__assert_vpc(instance.interfaces[1])
128+
__assert_vlan(instance.interfaces[2])

0 commit comments

Comments
 (0)