Skip to content

Commit 6e7f7ad

Browse files
Add VPC update test
1 parent c52b181 commit 6e7f7ad

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

linode_api4/objects/linode_interfaces.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class LinodeInterfacesSettings(Base):
4040

4141
@dataclass
4242
class LinodeInterfaceDefaultRouteOptions(JSONObject):
43-
ipv4: bool = False
44-
ipv6: bool = False
43+
ipv4: Optional[bool] = None
44+
ipv6: Optional[bool] = None
4545

4646

4747
@dataclass
@@ -102,12 +102,14 @@ class LinodeInterfaceVLANOptions(JSONObject):
102102

103103

104104
# Interface PUT Options
105+
# NOTE: These classes currently match their POST equivalents
106+
# but are implemented separately for future-proofing.
105107

106108

107109
@dataclass
108110
class LinodeInterfaceDefaultRouteUpdateOptions(JSONObject):
109-
ipv4: bool = False
110-
ipv6: bool = False
111+
ipv4: Optional[bool] = None
112+
ipv6: Optional[bool] = None
111113

112114

113115
@dataclass
@@ -206,7 +208,7 @@ class LinodeInterfaceVPCIPv4(JSONObject):
206208

207209
@dataclass
208210
class LinodeInterfaceVPC(JSONObject):
209-
put_class = LinodeInterfaceVPCIPv4Options
211+
put_class = LinodeInterfaceVPCOptions
210212

211213
vpc_id: int = 0
212214
subnet_id: int = 0

test/fixtures/linode_instances_124_interfaces_456.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
"subnet_id": 789,
1313
"ipv4" : {
1414
"addresses": [
15-
{ "address": "192.168.22.3",
16-
"primary": true }
15+
{
16+
"address": "192.168.22.3",
17+
"primary": true
18+
}
1719
],
1820
"ranges": [
1921
{ "range": "192.168.22.16/28"},

test/unit/objects/linode_interface_test.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from datetime import datetime
22
from test.unit.base import ClientBaseCase
33

4+
45
from linode_api4 import (
56
LinodeInterface,
67
LinodeInterfacePublicIPv4AddressUpdateOptions,
78
LinodeInterfacePublicIPv6RangeUpdateOptions,
9+
LinodeInterfaceVPCIPv4AddressUpdateOptions,
10+
LinodeInterfaceVPCIPv4RangeUpdateOptions,
811
)
912

1013

@@ -172,4 +175,48 @@ def test_update_public(self):
172175
},
173176
}
174177

175-
# TODO (Enhanced Interfaces): iface update tests
178+
def test_update_vpc(self):
179+
iface = LinodeInterface(self.client, 456, 124)
180+
181+
self.assert_linode_124_interface_456(iface)
182+
183+
iface.default_route.ipv4 = False
184+
185+
iface.vpc.subnet_id = 456
186+
187+
iface.vpc.ipv4.addresses = [
188+
LinodeInterfaceVPCIPv4AddressUpdateOptions(
189+
address="192.168.22.4", primary=False, nat_1_1_address="auto"
190+
)
191+
]
192+
193+
iface.vpc.ipv4.ranges = [
194+
LinodeInterfaceVPCIPv4RangeUpdateOptions(
195+
range="192.168.22.17/28",
196+
)
197+
]
198+
199+
with self.mock_put("/linode/instances/124/interfaces/456") as m:
200+
iface.save()
201+
202+
assert m.called
203+
204+
print(m.call_data)
205+
assert m.call_data == {
206+
"default_route": {
207+
"ipv4": False,
208+
},
209+
"vpc": {
210+
"subnet_id": 456,
211+
"ipv4": {
212+
"addresses": [
213+
{
214+
"address": "192.168.22.4",
215+
"primary": False,
216+
"nat_1_1_address": "auto",
217+
},
218+
],
219+
"ranges": [{"range": "192.168.22.17/28"}],
220+
},
221+
},
222+
}

0 commit comments

Comments
 (0)